Name Indexing

Functions for indexing named objects in JSON to be imported.

class authorityspoke.io.name_index.Mentioned

Index of cross-referenced objects, keyed to phrases that reference them.

insert_by_name(obj)

Add record to dict, using value of record’s “name” field as the dict key.

Return type

None

get_by_name(name)

Convert retrieved record so name is a field rather than the key for the whole record.

Parameters

name (str) – the name of the key where the record can be found in the Mentioned dict.

Return type

Dict

Returns

the value stored at the key “name”, plus a name field.

get_if_present(name)

Retrieve a record from the index, if it exists.

Parameters

name (str) – the name of the key where the record can be found in the Mentioned dict.

Return type

Union[Dict, str]

Returns

the value stored at the key “name”, plus a name field.

sorted_by_length()

Sort dict items from longest to shortest.

Used to ensure that keys nearer the start can’t be substrings of later keys.

Return type

Mentioned

authorityspoke.io.name_index.assign_name_from_content(obj)

Use the content to assign a name to any Fact that lacks one.

This can fail if the parser replaces placeholder text with another placeholder

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_evidence(obj)

Return an appropriate name for Evidence.

Parameters

obj (Dict) – an unloaded Evidence object

Return type

str

Returns

a name for the Evidence

authorityspoke.io.name_index.assign_name_for_pleading(obj)

Return an appropriate name for a Pleading.

Parameters

obj (Dict) – an unloaded Pleading

Return type

str

Returns

a name for the Pleading

authorityspoke.io.name_index.create_name_for_enactment(obj)

Create unique name for unloaded Enactment data, for indexing.

Return type

str

authorityspoke.io.name_index.create_name_for_enactment_passage(obj)

Create unique name for unloaded Enactment data, for indexing.

Return type

str

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_terms(terms, mentioned)

Update name index from a list of RawFactors or strings referencing them.

Parameters
Returns

an updated “mentioned” name index

authorityspoke.io.name_index.update_name_index_from_bracketed_phrases(content, mentioned)

Find string template placeholders in content, and use them to create dicts to be loaded as Entities.

Return type

Mentioned

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, ignore=('predicate', 'anchors', 'factor_anchors', 'enactment_anchors', 'enactments'))

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.collect_enactments(obj, mentioned=None, ignore=('predicate', 'anchors', 'children', 'inputs', 'despite', 'outputs', 'selection'))

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