2. Nodes: argonodes.nodes

Nodes are the building block of the whole pipeline to augment data with semantics.

With Nodes, data can be passed in JSON, which can be explored, described, and tagged, and the nodes can then be used to build data models.

Basic usage: tree = Tree(json_data)

class argonodes.nodes.Node(data, fieldName, filename=None, parent=None, process_traversal=False)

Bases: object

A Node is a specific part of the JSON Tree.

Parameters
  • data (Any) – Whichever raw data the Node should contains.

  • fieldName (String) – The field name for that Node in the raw JSON data.

  • filename (String, default None.) – Facultative, what file is the data from.

  • parent (Node, default None.) – Facultative, parent for that Node.

  • process_traversal (bool, default False.) – Facultative, whether a traversal should be processed already or not.

apply(fun, rec=True, *args, **kwargs) Union[Node, Any]

Takes a function that will be applied to the node and/or children, and potential arguments.

Parameters
  • fun (A function taking into parameters at least the node and the rec parameters.) – A Node function

  • rec (bool, default True.) – Should the function be applied recursively (all children) or not.

Returns

Self if the function does not return anything, else whatever the function returns.

Return type

Node or None.

delete(rec=False, remove=False)

Delete a node in the Tree.

Parameters
  • rec (bool, default False.) – Should the removal be recursive or not.

  • remove (bool, default False.) – Should a “blank” node be put in lieu, or plain delete.

export_traversal() dict

Export the created traversal.

If the traversal does not exist, it is created.

Returns

The returned traversal.

Return type

dict

get_attributes() list

List of all attributes available.

Returns

List of all attributes available.

Return type

list

get_children_from_path(paths) list

Get all children for a given path.

The path can either be a specific path, or use wildcards.

Parameters

paths – A single JSONPath or a list of JSONPaths.

Rtype paths

list[str] or [str]

Returns

The list of all children for the paths.

Return type

list[Node]

get_paths() set

All paths linked to that Node.

Returns

Set of avalaible paths.

Return type

set[str]

get_paths_fancy() str

A printable and formatted list of Paths.

Returns

Fancy paths list.

Return type

str

set_attributes(path, **kwargs)

Given a specific path, add more context to that path.

Parameters
  • path (str) – A valid path.

  • kwargs (Keyworded, variable-length argument list.) – The different information to add to that path.

Returns

True if the path was found and info added; False otherwise.

Return type

bool

class argonodes.nodes.NodeDict(contains, fieldName, parent, process_traversal, filename=None)

Bases: Node

A NodeDict is a special Node that contains data in a dict.

class argonodes.nodes.NodeList(contains, parent, process_traversal, i=None, filename=None)

Bases: Node

A NodeList is a special Node that contains data in a list.

class argonodes.nodes.Tree(data, filename=None)

Bases: Node

A Tree is a special Node with $ as field name.

delete(rec=False, remove=False)

Delete a node in the Tree.

Parameters
  • rec (bool, default False.) – Should the removal be recursive or not.

  • remove (bool, default False.) – Should a “blank” node be put in lieu, or plain delete.