segram.utils.diff module

segram.utils.diff.equal(obj, other, *, strict: bool = True) bool[source]
segram.utils.diff.equal(obj: Token, other: Token, *, strict: bool = True) bool
segram.utils.diff.equal(obj: Span, other: Span, *, strict: bool = True) bool
segram.utils.diff.equal(obj: Doc, other: Doc, *, strict: bool = True) bool

Compare two arbitrary objects.

Objects are compared using standard equality operator, unless they are SegramABC instance, in which case the equal() method is used.

Parameters:
  • obj – Arbitrary objects.

  • other – Arbitrary objects.

  • strict – Passed to .equal() method.

segram.utils.diff.iter_diffs(obj, other, *, strict: bool = True) Iterable[tuple[str, Any, Any]][source]
segram.utils.diff.iter_diffs(obj: tuple, other: tuple, *, strict: bool = True) Iterable[tuple[str, Any, Any]]
segram.utils.diff.iter_diffs(obj: list, other: list, *, strict: bool = True) Iterable[tuple[str, Any, Any]]
segram.utils.diff.iter_diffs(obj: Mapping, other: Mapping, *, strict: bool = True) Iterable[tuple[str, Any, Any]]
segram.utils.diff.iter_diffs(obj: Token, other: Token, *, strict: bool = True) Iterable[tuple[str, Any, Any]]
segram.utils.diff.iter_diffs(obj: Span, other: Span, *, strict: bool = True) Iterable[tuple[str, Any, Any]]
segram.utils.diff.iter_diffs(obj: Doc, other: Doc, *, strict: bool = True) Iterable[tuple[str, Any, Any]]
segram.utils.diff.iter_diffs(obj: SegramABC, other: Any, *, strict: bool = True) Iterable[tuple[str, Any, Any]]

Single dispatch generic function for iterating over differences between two objects.

Parameters:
  • obj – Two arbitrary objects. The method dispatch is done on obj type.

  • other – Two arbitrary objects. The method dispatch is done on obj type.

  • strict – Used for comparing NLP token objects and grammar/semantic objects. When strict=True only exact matches on classes are accepted. This means, for instance, that only tokens from the same document can be equal, regardless of any text and index equivalences between two tokens and documents.

Yields:
  • qname – Qualified name of obj or its type.

  • name – Name of the attribute/property that differs between obj and other.

  • v1, v2 – Values that differ.