triplemodel.io.compare

Graph and model comparison helpers for tests and migrations.

class triplemodel.io.compare.GraphDiff(only_in_first, only_in_second)[source]

Bases: object

Structural difference between two RDF graphs.

Parameters:
only_in_first: frozenset[tuple[str, str, str]]
only_in_second: frozenset[tuple[str, str, str]]
property equal: bool
__init__(only_in_first, only_in_second)
Parameters:
Return type:

None

triplemodel.io.compare.graph_diff(graph_a, graph_b, *, normalize_bnodes=True)[source]

Compare two graphs by normalized triple sets (after optional skolemization).

Return type:

GraphDiff

Parameters:
  • graph_a (RdfGraph)

  • graph_b (RdfGraph)

  • normalize_bnodes (bool)

triplemodel.io.compare.graphs_equal(graph_a, graph_b, *, normalize_bnodes=True)[source]

Return whether graph_a and graph_b are isomorphic RDF graphs.

Return type:

bool

Parameters:
  • graph_a (RdfGraph)

  • graph_b (RdfGraph)

  • normalize_bnodes (bool)

triplemodel.io.compare.model_diff(model_a, model_b, graph=None, *, normalize_bnodes=True)[source]

Return field-level differences between two model instances.

When graph is provided, also includes graph_diff between model_a.to_graph() and model_b.to_graph() merged into the source graph.

Return type:

dict[str, Any]

Parameters:
  • model_a (T)

  • model_b (T)

  • graph (RdfGraph | None)

  • normalize_bnodes (bool)