nanom commited on
Commit
0fe32b8
·
1 Parent(s): 2310bfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -7,21 +7,27 @@ nlp = spacy.load("en_core_web_md")
7
 
8
  # -- Main functions --
9
 
 
 
 
 
 
 
10
  def genFlatDepthTree(expr):
11
  doc = nlp(expr)
12
  root = next(doc.sents).root
13
- node = Node(root.text+" : depth="+str(0), parent=None)
14
 
15
  def tree(tk, last_node, depth):
16
  if tk.n_lefts + tk.n_rights > 0:
17
  for ch in tk.children:
18
- tree(ch, Node(ch.text+" : depth="+str(depth+1), parent=last_node), depth+1)
19
 
20
  tree(root, node, 0)
21
  flat_tree = ""
22
 
23
  for pre, fill, node in RenderTree(node):
24
- flat_tree += "{}{}\n".format(pre, node.name)
25
 
26
  img_tree = displacy.render(doc, style='dep', options={'distance': 100})
27
 
 
7
 
8
  # -- Main functions --
9
 
10
+ def markTk(tk):
11
+ noun_tags = ['NN', 'NNS', 'WP']
12
+ if tk.tag_ in noun_tags:
13
+ return " (Plural)"
14
+ return ""
15
+
16
  def genFlatDepthTree(expr):
17
  doc = nlp(expr)
18
  root = next(doc.sents).root
19
+ node = Node(root.text+": 0 (Root)"+markTk(root), parent=None)
20
 
21
  def tree(tk, last_node, depth):
22
  if tk.n_lefts + tk.n_rights > 0:
23
  for ch in tk.children:
24
+ tree(ch, Node(ch.text+" :"+str(depth+1)+markTk(ch), parent=last_node), depth+1)
25
 
26
  tree(root, node, 0)
27
  flat_tree = ""
28
 
29
  for pre, fill, node in RenderTree(node):
30
+ flat_tree += """{}{}\n""".format(pre, node.name)
31
 
32
  img_tree = displacy.render(doc, style='dep', options={'distance': 100})
33