forked from yadavhimanshu059/Hindi_DS_to_PS_Conversion_v2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPS_word_order.py
69 lines (54 loc) · 2.13 KB
/
PS_word_order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#-*- coding: UTF-8 -*-
import os
import sys
import glob
from ssf_api import *
from os import listdir
from os.path import isfile, join
import string
class PS_word_order(object):
def __init__(self, ps_tree):
self.ps_tree=ps_tree
def ps_word_order(self):
index=0
word_posn={}
for word in self.ps_tree.split():
index=index+1
word_posn[word]=index
return word_posn
def ps_node_order(self):
token=0
node_address={}
for word in self.ps_tree.split():
if not word==']':
token=token+1
flag=0
for char in word:
if char=='[':
flag=flag+1
else:
flag=flag
if not flag==0:
node=string.replace(word, '[.', '')
else:
node=string.replace(word, '\\texthindi{', '')
node=string.replace(node, '}', '')
node_address[node]=token
return node_address
def ps_terminal(self):
token=0
node_address={}
for word in self.ps_tree.split():
if not word==']':
flag=0
for char in word:
if char=='[':
flag=flag+1
else:
flag=flag
if flag==0:
token=token+1
node=string.replace(word, '\\texthindi{', '')
node=string.replace(node, '}', '')
node_address[token]=node
return node_address