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_end_edge(node)[source]

Add an edge from node to end

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

add_roots(roots)[source]
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

draw(*args, **kwargs)[source]
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

score_graph()[source]
start = '__start__'
write_dot(path)[source]
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_avyayas(bases)[source]

Add Avyaya Links

add_bhavalakshana(krts, laks)[source]

Add bhavalakshana edges from saptami krts to lakaras

add_conjunctions(bases)[source]

Add samuccita links for conjunctions/disjunctions

add_edges()[source]
add_karakas(bases)[source]

Add karaka edges from base node (dhatu) base

add_kriya_kriya(lakaras, krts)[source]

Add kriya-kriya edges from lakaras to krts

add_kriyavisheshana(bases)[source]

Add kriyaviSezaRa edges from base node (dhatu) base

add_node(node)[source]

Extend dag with node inserted at root

Params:

Node (VakyaGraphNode) : Node to add

add_non_karaka_vibhaktis()[source]

Add Non-Karaka Vibhaktis

add_samastas()[source]

Add samasta links from next samasta/tiN

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

add_shashthi()[source]

Add zazWI-sambanDa links to next tiN

add_vipsa()[source]
add_visheshana()[source]
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

draw(*args, **kwargs)[source]
find_krtverbs()[source]

Find non ti~Nanta verbs

find_lakaras()[source]

Find the ti~Nanta

get_dot_dict()[source]
get_parses_dc()[source]

Returns all parses

Uses modified Kruskal Algorithm to compute (generalized) spanning tree of k-partite VakyaGraph

lock()[source]
write_dot(path)[source]
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

can_merge(other, length)[source]

Can we merge two VakyaParses

copy()[source]

Return a one level deep copy - in between a shallow and a fully deep copy

extend(pred, node)[source]

Extend current parse with edge from pred to node

is_extinguished(node)[source]

Is a node extinguished

is_safe(pred, node)[source]

Checks if a partial parse is compatible with a given node and predecessor pair

merge_f(other)[source]

Merge two VakyaParses: Fast method

merge_s(other, length)[source]

Merge two VakyaParses: Slow method

sanskrit_parser.parser.datastructures.getSLP1Tagset(n)[source]

Given a (base, tagset) pair, extract the tagset

Submodules

Indices and tables