API Reference
A list of the full API reference of all public classes and functions is below.
Public members can (and should) be imported from graphtransliterator:
from graphtransliterator import GraphTransliterator
Bundled transliterators require that graphtransliterator.transliterators:
be imported:
import graphtransliterator.transliterators
transliterators.iter_names()
Core Classes
- class graphtransliterator.GraphTransliterator(*args: Any, **kwargs: Any)[source]
- static from_dict_file(dict_filename: str, **kwargs: Any) GraphTransliterator[source]
Alias or file loader for dictionary/json files.
- static from_json(json_str: str, **kwargs: Any) GraphTransliterator[source]
Load a GraphTransliterator from a JSON string.
- static from_json_file(json_filename: str, **kwargs: Any) GraphTransliterator[source]
Load a GraphTransliterator from a JSON file.
- inject_subgraph(other: GraphTransliterator, prefix_tokens: list[str] | None = None) GraphTransliterator[source]
Injects another GraphTransliterator’s ruleset as a subgraph extension.
- merge(other: GraphTransliterator) GraphTransliterator[source]
Merges another GraphTransliterator context cleanly into this one.
Bundled Transliterators
graphtransliterator.transliterators
- class graphtransliterator.transliterators.Any(*args, **kwargs)[source]
Special type indicating an unconstrained type.
Any is compatible with every type.
Any assumed to have all methods.
All values assumed to be instances of Any.
Note that all the above statements are true from the point of view of static type checkers. At runtime, Any should not be used with instance checks.
- class graphtransliterator.transliterators.Bundled(*args: Any, **kwargs: Any)[source]
Subclass of GraphTransliterator used for bundled Graph Transliterators.
- from_bundled_JSON(check_ambiguity: bool = False, coverage: bool = False, **kwargs: Any) Bundled[source]
Initialize from bundled JSON file (best for speed).
- from_bundled_YAML(check_ambiguity: bool = True, coverage: bool = True, **kwargs: Any) Bundled[source]
Initialize from bundled YAML file (best for development).
- generate_yaml_tests(file: Any | None = None) str[source]
Generates YAML tests with complete coverage.
- class graphtransliterator.transliterators.Example(*args: Any, **kwargs: Any)[source]
Example Bundled Graph Transliterator.
- class graphtransliterator.transliterators.ITRANSDevanagariToUnicode(*args: Any, **kwargs: Any)[source]
ITRANS Devanagari to Unicode Transliterator.
- class graphtransliterator.transliterators.MetadataSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Schema for Bundled metadata.
Graph Classes
- class graphtransliterator.DirectedGraph(nodes: list[Node[T, N]] | None = None, edges: list[Edge[E]] | None = None)[source]
A directed graph representation storing nodes and edges in a flat structure.
- add_edge(source: int, target: int, data: E | None = None) None[source]
Add a directed edge connecting a source NodeId to a target NodeId.
- add_node(data: N | None = None, token: Any = None, type: Any = None, label: str | None = None, **kwargs: Any) int[source]
Append a node to the graph and return its generated integer NodeId.
- property edge_list: list[tuple[int, int]]
Return a list of all edge connection coordinates as (source, target) tuples.
- get_edge(source: int, target: int) dict[str, Any] | None[source]
Return the edge payload or full edge structure connecting source and target.
- Parameters:
source – The source node identifier.
target – The target node identifier.
- Returns:
The edge’s
datadictionary if it is a dict, or the full edge structure dict ifdatais not a dictionary. ReturnsNoneif no matching edge exists.
Note
For backward compatibility, if an edge’s
dataproperty contains a non-dict value (e.g., a primitive string), the method returns the full edge dictionary (includingsource,target, anddatakeys) rather than just the payload.
Rule Classes
- class graphtransliterator.TransliterationRule[source]
A transliteration rule containing match conditions and cost.
Exceptions
- exception graphtransliterator.GraphTransliteratorException[source]
Base exception class. All Graph Transliterator-specific exceptions should subclass this class.
- exception graphtransliterator.AmbiguousTransliterationRulesException[source]
Raised when multiple transliteration rules can match the same pattern. Details of ambiguities are given in a
logging.warning().
- exception graphtransliterator.NoMatchingTransliterationRuleException[source]
Raised when no transliteration rule can be matched at a particular location in the input string’s tokens. Details of the location are given in a
logging.warning().
- exception graphtransliterator.UnrecognizableInputTokenException[source]
Raised when a character in the input string does not correspond to any tokens in the GraphTransliterator’s token settings. Details of the location are given in a
logging.warning().
Schemas
- class graphtransliterator.DirectedGraphSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Canonical schema for DirectedGraph matching TypeScript LoadedGraphDict.
- class graphtransliterator.EasyReadingSettingsSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Schema for easy reading settings format.
- class graphtransliterator.GraphTransliteratorSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Canonical Unified Schema for GraphTransliterator config & execution state.
- class graphtransliterator.OnMatchRuleSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Schema for OnMatchRule.
- class graphtransliterator.SettingsSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Schema for full transliterator settings.
- class graphtransliterator.TransliterationRuleSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
- class graphtransliterator.WhitespaceDictSettingsSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Schema for Whitespace definition as a dict.
- class graphtransliterator.WhitespaceSettingsSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]
Schema for Whitespace definition that loads as a WhitespaceRule.