File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ """tutorial.Adpositions block template.
2+
3+ Example usage:
4+ for a in */sample.conllu; do
5+ printf '%50s ' $a;
6+ udapy tutorial.Adpositions < $a;
7+ done | tee results.txt
8+
9+ # What are the English postpositions?
10+ cat UD_English/sample.conllu | udapy -TM util.Mark \
11+ node='node.upos == "ADP" and node.parent.precedes(node)' | less -R
12+ """
13+ from udapi .core .block import Block
14+
15+ class Adpositions (Block ):
16+ """Compute the number of prepositions and postpositions."""
17+
18+ def __init__ (self , ** kwargs ):
19+ """Create the Adpositions block object."""
20+ super ().__init__ (** kwargs )
21+ self .prepositions = 0
22+ self .postpositions = 0
23+
24+ def process_node (self , node ):
25+ # TODO: Your task: distinguish prepositions and postpositions
26+ if node .upos == "ADP" :
27+ self .prepositions += 1
28+
29+ def process_end (self ):
30+ total = self .prepositions + self .postpositions or 1
31+ prep = 100 * self .prepositions / total
32+ post = 100 * self .postpositions / total
33+ print ("prepositions %5.1f%%, postpositions %5.1f%%" % (prep , post ))
You can’t perform that action at this time.
0 commit comments