parser.datastructures¶
Sanskrit Parser Data Structures
@author: Karthik Madathil (github: @kmadathil)
-
class
sanskrit_parser.parser.datastructures.
SandhiGraph
[source]¶ Bases:
object
DAG class to hold Sandhi Lexical Analysis Results
Represents the results of lexical sandhi analysis as a DAG Nodes are SanskritObjects
-
add_node
(node)[source]¶ Extend dag with node inserted at root
- Params:
Node (SanskritObject) : Node to add root (Boolean) : Make a root node end (Boolean) : Add an edge to end
-
append_to_node
(t, nodes)[source]¶ Create edges from t to nodes
- Params:
t (SanskritObject) : Node to append to nodes (iterator(nodes)) : Nodes to append to t
-
end
= '__end__'¶
-
find_all_paths
(max_paths=10, sort=True, score=True)[source]¶ Find all paths through DAG to End
- Params:
- max_paths (int :default:=10): Number of paths to find
If this is > 1000, all paths will be found
- sort (bool)If True (default), sort paths
in ascending order of length
-
has_node
(t)[source]¶ Does a given node exist in the graph?
- Params:
t (SanskritObject): Node
- Returns:
boolean
-
lock_start
()[source]¶ Make the graph ready for search by adding a start node
Add a start node, add arcs to all current root nodes, and clear self.roots
-
start
= '__start__'¶
-
-
class
sanskrit_parser.parser.datastructures.
VakyaGraph
(path, max_parse_dc=4, fast_merge=True)[source]¶ Bases:
object
DAG class for Sanskrit Vakya Analysis
Represents Sanskrit Vakya Analysis as a DAG Nodes are SanskritObjects with morphological tags Edges are potential relationships between them
-
add_node
(node)[source]¶ Extend dag with node inserted at root
- Params:
Node (VakyaGraphNode) : Node to add
-
add_sentence_conjunctions
(laks, krts)[source]¶ Add sentence conjunction links
For all nodes which match sentence_conjuction keys add vAkyasambanDaH link between y-t pair
if vibhakti matches where relevant
Reverse all edges to node, add sambadDa- to link label (eg sambadDa-karma, if node is not vIpsa if node is saMyojakaH, and not vIpsA add saMbadDakriyA links to verbs if associated t* doesn’t exist vAkyasambanDaH links from verbs
-
check_parse_validity
()[source]¶ Validity Check for parses
Remove parses with double kArakas Remove parses with multiple to edges into a node Remove parses with cycles
-
-
class
sanskrit_parser.parser.datastructures.
VakyaParse
(nodepair)[source]¶ Bases:
object
-
activate_and_extinguish_alternatives
(node)[source]¶ Make node active, extinguish other nodes in its partition
-
-
sanskrit_parser.parser.datastructures.
getSLP1Tagset
(n)[source]¶ Given a (base, tagset) pair, extract the tagset