Skip to content

Commit 60a5c64

Browse files
committed
template for tutorial.Adpositions
1 parent 22a1acd commit 60a5c64

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

udapi/block/tutorial/__init__.py

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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))

0 commit comments

Comments
 (0)