segram.nlp.grammar.components module

class segram.nlp.grammar.components.ComponentNLP(*args: Any, **kwds: Any)[source]

Bases: GrammarNLP, Component

Abstract base class for grammar components with NLP backend methods.

All grammar classes must be defined as slots classes. This is necessary for ensuring low-memory footprint and better computational efficiency. Even classes with no new slots need to declare __slots__ = (). This requirement is checked during class construction. Other class-specific requirements of this sort as well as their related validation checks may be implemented on specialized grammar classes using the standard __init_subclass__ interface. This allows abstract base classes further down the inheritance chain to check for more complex requirements as well as apply dynamic class customizations.

abstract classmethod is_head(tok: Token) bool[source]

Test for head token.

abstract get_dep(parent: Component) Dep | None[source]

Get dependency between self and parent.

is_child_of(comp: Component) bool[source]

Is self a child of comp.

find_parents(comps: Sequence[Component])[source]

Find parents of self contained in comps.

get_sconj(parent: Component) Token | None[source]

Get conjunction subordinating self to parent.

get_cconj(other: Component) Token | None[source]

Get conjunction token coordinating self and other.

classmethod from_tok(tok: Token, pos: POS | None = None, role: Role | None = None, **kwds: Any) Component[source]

Construct from a token.

Parameters:
  • tok – NLP token object.

  • pos – POS tag to assign to the tok token. Determined automatically if None.

  • role – Syntactic role assigned to the tok token and the entire component. Determined autoamtically if None.

  • **kwds – Passed to __init__().