Name Indexing
Functions for indexing named objects in JSON to be imported.
-
class
authorityspoke.io.name_index.
Mentioned
An index of cross-referenced objects to be used in
loading AuthoritySpoke objects, keyed to the phrases
used to reference them.
-
authorityspoke.io.name_index.
assign_name_from_content
(obj)
Use the content to assign a name to any Fact
that lacks one.
- Parameters
obj (Dict
) – object loaded from JSON to make a Factor
or Holding
- Return type
str
- Returns
a new name
-
authorityspoke.io.name_index.
assign_name_for_enactment
(obj)
Return an appropriate name for an Enactment
- Parameters
obj (Dict
) – an unloaded Enactment
- Return type
str
- Returns
a name for the Enactment
-
authorityspoke.io.name_index.
assign_name_for_evidence
(obj)
Return an appropriate name for an Enactment
- Parameters
obj (Dict
) – an unloaded Enactment
- Return type
str
- Returns
a name for the Enactment
-
authorityspoke.io.name_index.
assign_name_for_pleading
(obj)
Return an appropriate name for an Enactment
- Parameters
obj (Dict
) – an unloaded Enactment
- Return type
str
- Returns
a name for the Enactment
-
authorityspoke.io.name_index.
create_name_for_factor
(obj)
Determine what kind of RawFactor the input is and return an appropriate name.
- Parameters
obj (Dict
) – an unloaded Factor
- Return type
str
- Returns
a name for the Factor
-
authorityspoke.io.name_index.
ensure_factor_has_name
(obj)
Add a name to a RawFactor if it doesn’t already have one.
- Parameters
obj (Dict
) – an unloaded Factor
- Return type
Dict
- Returns
the same Factor
with a name field added
-
authorityspoke.io.name_index.
update_name_index_from_context_factors
(context_factors, mentioned)
Update name index from a list of RawFactor
s or strings referencing them.
- Parameters
context_factors (List
[Dict
[str
, Union
[Dict
[str
, Union
[str
, bool
]], Sequence
[Any
], str
, bool
]]]) – a list of RawFactor
s or strings referencing them. Both
RawFactor
s and strings may exist in the list.
mentioned (Mentioned
) – RawFactor
s indexed by name for retrieval when loading objects
using a Marshmallow schema.
- Returns
an updated “mentioned” name index
-
authorityspoke.io.name_index.
update_name_index_from_fact_content
(obj, mentioned)
Update index of mentioned Factors from Factors mentioned in Fact’s content, and vice versa.
- Parameters
-
- Return type
Tuple
[Dict
[str
, Union
[Dict
[str
, Union
[str
, bool
]], Sequence
[Any
], str
, bool
]], Mentioned
]
- Returns
both ‘obj’ and ‘mentioned’, updated with values from each other
-
authorityspoke.io.name_index.
update_name_index_with_factor
(obj, mentioned)
Update index of mentioned Factors with ‘obj’, if obj is named.
If there is already an entry in the mentioned index with the same name
as obj, the old entry won’t be replaced. But if any additional text
anchors are present in the new obj, the anchors will be added.
If obj has a name, it will be collapsed to a name reference.
- Parameters
-
- Return type
Tuple
[Union
[str
, Dict
[str
, Union
[Dict
[str
, Union
[str
, bool
]], Sequence
[Any
], str
, bool
]]], Mentioned
]
- Returns
both ‘obj’ and ‘mentioned’, as updated
-
authorityspoke.io.name_index.
collect_mentioned
(obj, mentioned=None, keys_to_ignore=('predicate', 'anchors'))
Make a dict of all nested objects labeled by name, creating names if needed.
To be used during loading to expand name references to full objects.
- Return type
Tuple
[Dict
[str
, Union
[Dict
[str
, Union
[str
, bool
]], Sequence
[Any
], str
, bool
]], Mentioned
]
-
authorityspoke.io.name_index.
index_names
(record)
Call all functions to prepare “mentioned” index.
The names are sorted by length so that if one mentioned Factor’s name
is a substring of another, the longest available name is expanded.
- Return type
Mentioned
- Returns
a modified version of the dict to load, plus a dict of names
and the objects to expand them with.
Nesting fields to prepare to load a dict with a Marshmallow schema.
-
authorityspoke.io.nesting.
nest_fields
(data, nest, eggs)
Make sure specified fields are nested under “nest” key.
-
authorityspoke.io.nesting.
walk_tree_and_modify
(obj, func, ignore=())
Traverse tree of dicts and lists, and modify each node.
- Parameters
obj (Union
[Dict
, List
]) – the object to traverse
func (Callable
) – the function to call on each dict node, returning a dict
ignore (Sequence
[str
]) – the names of keys that should not be explored
- Return type
Union
[Dict
, List
]
- Returns
a version of the tree with every node modified by func