Parsers

The fosf.parsers package provides high-level functions for parsing textual representations of directed graphs, sort taxonomies, OSF terms, OSF clauses, and OSF theories.

Each function calls the corresponding parser class and returns an objcet from fosf.syntax.

fosf.parsers.parse_graph(string)[source]

Parse a textual representation of a (weighted) DAG.

Parameters:

string (str) – The string representation of the (weighted) DAG.

Returns:

The parsed weighted DAG.

Return type:

networkx.DiGraph

Note

The accepted syntax is defined in Graph Grammar.

fosf.parsers.parse_taxonomy(string)[source]

Parse a textual representation of a (fuzzy) sort taxonomy.

Parameters:

string (str) – The string representation of the (fuzzy) sort taxonomy.

Returns:

The parsed sort taxonomy

Return type:

SortTaxonomy

Note

The accepted syntax is defined in Taxonomy Grammar.

fosf.parsers.parse_term(string, default_tag='X', create_using=None)[source]

Parse a textual representation of an OSF term.

Parameters:
  • string (str) – The string representation of the OSF term.

  • default_tag (str, default="X") – The default base identifier for a tag, used when an explicit tag is missing. Defaults to "X".

  • create_using (type, optional) – Term class to construct the output. Should be one of Term or NormalTerm. If None, defaults to Term

Returns:

The parsed OSF term.

Return type:

Term

Note

The accepted OSF term syntax is defined in OSF Term Grammar.

fosf.parsers.parse_clause(string, create_using=None, root=None)[source]

Parse a textual representation of an OSF clause.

Parameters:
Returns:

The parsed OSF clause.

Return type:

Clause

Note

The accepted OSF clause syntax is defined in OSF Clause Grammar.

fosf.parsers.parse_theory(string, ensure_closed=False)[source]

Parse a textual representation of an OSF theory.

Parameters:
  • string (str) – The string representation of the OSF theory.

  • ensure_closed (bool, default=False) – If True, close the theory to ensure its order-consistency.

Returns:

The parsed OSF theory.

Return type:

OsfTheory

Note

The accepted OSF theory syntax is defined in OSF Theory Grammar.

Base OSF Parser

class fosf.parsers.base.BaseOSFParser[source]

Bases: object

parse(expression, **kwargs)[source]
Parameters:

expression (str)

Return type:

Sort

(Fuzzy) Taxonomy Parser

class fosf.parsers.taxonomy.TaxonomyParser[source]

Bases: BaseOSFParser

parse(expression)[source]
Parameters:

expression (str)

Return type:

SortTaxonomy

OSF Clause Parser

class fosf.parsers.clause.OsfConstraintParser[source]

Bases: BaseOSFParser

parse(expression, create_using=None, root=None)[source]
Parameters:

expression (str)

Return type:

Clause

class fosf.parsers.clause.NormalizationParser[source]

Bases: BaseOSFParser

OSF Term Parser

class fosf.parsers.term.OsfTermParser[source]

Bases: BaseOSFParser

parse(expression: str, default_tag='X', create_using=NormalTerm) NormalTerm[source]
parse(expression: str, default_tag='X', create_using=Term) Term
Parameters:

expression (str)

Return type:

Term

class fosf.parsers.term.UnificationParser[source]

Bases: OsfTermParser

parse(expression: str, default_tag='X', term_constructor=NormalTerm) tuple[SortTaxonomy, NormalTerm, NormalTerm][source]
parse(expression: str, default_tag='X', term_constructor=Term) tuple[SortTaxonomy, Term, Term]
Parameters:

expression (str)

Return type:

tuple[SortTaxonomy, Term, Term]

OSF Theory Parser

class fosf.parsers.theory.OsfTheoryParser[source]

Bases: TaxonomyParser

parse(expression, ensure_closed=False)[source]
Parameters:

expression (str)

Return type:

OsfTheory