4. Models: argonodes.models

Models are an abstraction of data sources.

They aim to describe, complete, and enhance the information of unknown data, so that the information related to the data can be re-applied to new data.

Basic usage = model = Model(tree)

class argonodes.models.Model(trees=None, name=None, context=None)

Bases: object

Model for a specific type of data.

If multiple files are used, the model will internally use the file names as key for traversals. Else, a default None key is used.

Parameters
  • trees (Tree or list[Tree], default None.) – Trees to be processed by the Model.

  • name (str, default None.) – Name of the Model.

  • context (dict, default None.) – Context for the JSON-LD export.

add_traversal(traversal, filename=None, apply=True) None

Add a traversal to the Model.

Parameters
  • traversal (dict) – The traversal, from a Tree.

  • filename (str, default None.) – The filename, from a Tree.

  • apply (bool, default True.) – If True, will effectively be applied to the Model.

add_tree(tree, apply=True) None

Add a Tree’s traversal to the Model.

Parameters
  • tree (Tree) – A Tree.

  • apply (bool) – If True, will effectively be applied to the Model.

apply(filtr) Model

Apply a Filter to the Model.

Parameters

filtr (Filter) – The Filter.

Returns

Self, for chaining.

Return type

Model

export(exporter)

Sugar for argonodes.exporters.

Parameters

exporter (argonodes.exporters.Exporter) – Exporter to be used.

export_to_csv(filename)

Sugar for argonodes.exporters.CSVExporter.

Parameters

filename (str) – Filename where to export.

export_to_markdown(filename=None)

Sugar for argonodes.exporters.MarkdownExporter.

Parameters

filename (str, default None.) – Filename where to export. If None, it will print the Markdown instead.

export_to_pickle(filename)

Sugar for argonodes.exporters.PickleExporter.

Parameters

filename (str) – Filename where to export.

find_info(target, filename=None) Optional[dict]

Returns the given path, or the latest found element within the path.

Parameters
  • target – A JSON path.

  • filename – Filename.

Rtype target

str

Rtype filename

str, default None.

Returns

The corresponding linked information in the traversal.

Return type

dict

flatten() dict

Returns a flattened version of the model.

Returns

A dict of the model.

Return type

dict

get_paths() dict

Returns the set of avalaible paths.

Returns

Set of avalaible paths.

Return type

set[str]

import_from_csv(filename)

Import a Model from CSV.

Parameters

filename (str) – Filename where to import.

import_from_pickle(filename)

Import a Model from a Pickle.

Parameters

filename (str) – Filename where to import.

set_attributes(path, filename=None, create=False, **kwargs) bool

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

Parameters
  • path (str) – A valid path.

  • filename (str, default None.) – A filename.

  • create (bool, default None.) – If the path does not exist, should it be created or not.

  • 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

to_list(headers=True) tuple[list, dict] | dict

Returns the model in the form of a list.

Parameters

headers (bool, default True.) – If the first line should be the headers.

Returns

A nice little list representing the Model.

Return type

list[list]