Skip to content

Commit 9e07957

Browse files
author
Vincent Kriz
committed
New verbose option in bin/udapy.
Removed unnecessary getters and setters for Node attributes. Several modifications to pass tests in Python 3+.
1 parent 252aa7f commit 9e07957

12 files changed

Lines changed: 58 additions & 115 deletions

File tree

bin/udapy

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,24 @@ import argparse
66

77
from udapi.core.run import Run
88

9+
910
argparser = argparse.ArgumentParser(description='udapy - Python interface to Udapi - API for Universal Dependencies')
1011
argparser.add_argument("-q", "--quiet", action="store_true", help="Warning, info and debug messages are suppressed. Only fatal errors are reported.")
12+
argparser.add_argument("-v", "--verbose", action="store_true", help="Warning, info and debug messages are printed to the STDERR.")
1113
argparser.add_argument('scenario', nargs=argparse.REMAINDER, help="A sequence of blocks and their parameters.")
1214
args = argparser.parse_args()
1315

14-
# Initialize logging.
15-
if args.quiet:
16-
logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', level=logging.CRITICAL)
16+
17+
# Set the level of logs according to parameters.
18+
if args.verbose:
19+
level = logging.DEBUG
20+
elif args.quiet:
21+
level = logging.CRITICAL
1722
else:
18-
logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', level=logging.INFO)
23+
level = logging.INFO
24+
25+
logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', level=level)
26+
1927

2028
# Process and provide the scenario.
2129
if __name__ == "__main__":

udapi/block/read/conllu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(self, args=None):
5858
self.file_handler = bz2.BZ2File(self.filename)
5959
else:
6060
logging.info('Opening regular file %s', self.filename)
61-
self.file_handler = open(self.filename, 'r')
61+
self.file_handler = open(self.filename, 'rb')
6262
else:
6363
raise ValueError('No file to process')
6464

udapi/block/read/reducedconllu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import codecs
55
import re
66

7-
from conllu import Conllu
7+
from udapi.block.read.conllu import Conllu
88

99

1010
class ReducedConllu(Conllu):

udapi/block/zellig_harris/baseline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def print_triple(self, target_node, context_node, relation_name):
113113
context_word = self.get_word(context_node)
114114

115115
triple = '%s %s_%s' % (target_word, context_word, relation_name)
116-
print triple.encode('utf-8')
116+
print(triple.encode('utf-8'))
117117

118118
def process_node(self, node):
119119
"""

udapi/block/zellig_harris/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ def print_triple(node_a, relation_name, node_b, print_lemma=False):
3030
node_a = get_node_representation(node_a, print_lemma=print_lemma)
3131
node_b = get_node_representation(node_b, print_lemma=print_lemma)
3232

33-
print "%s %s_%s" % (node_a, relation_name, node_b)
33+
print("%s %s_%s", node_a, relation_name, node_b)

udapi/block/zellig_harris/csnouns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from udapi.core.block import Block
66

7-
from common import *
8-
from queries import *
7+
from udapi.block.zellig_harris.common import *
8+
from udapi.block.zellig_harris.queries import *
99

1010

1111
class CsNouns(Block):

udapi/block/zellig_harris/csverbs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from udapi.core.block import Block
66

7-
from common import *
8-
from queries import *
7+
from udapi.block.zellig_harris.common import *
8+
from udapi.block.zellig_harris.queries import *
99

1010

1111
class CsVerbs(Block):

udapi/block/zellig_harris/ennouns.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from udapi.core.block import Block
66

7-
from common import *
8-
from queries import *
7+
from udapi.block.zellig_harris.common import *
8+
from udapi.block.zellig_harris.queries import *
99

1010

1111
class EnNouns(Block):

udapi/block/zellig_harris/enverbs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from udapi.core.block import Block
66

7-
from common import *
8-
from queries import *
7+
from udapi.block.zellig_harris.common import *
8+
from udapi.block.zellig_harris.queries import *
99

1010

1111
class EnVerbs(Block):

udapi/core/node.py

Lines changed: 30 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,45 @@ class Node(object):
2929
Class for representing non-root nodes in Universal Dependency trees.
3030
3131
"""
32-
33-
__slots__ = list()
34-
35-
# (A) Features following the CoNLL-U documentation:
36-
__slots__.append('_ord') # Word index, integer starting at 1 for each new sentence.
37-
__slots__.append('_form') # Word form or punctuation symbol.
38-
__slots__.append('_lemma') # Lemma or stem of word form.
39-
__slots__.append('_upostag') # Universal POS tag drawn from our revised version of the Google UPOS tags.
40-
__slots__.append('_xpostag') # Language-specific part-of-speech tag; underscore if not available.
41-
__slots__.append('_raw_feats') # Morphological features in their original CoNLLU format.
42-
__slots__.append('_head') # Head of the current token, which is either a value of ID or zero (0).
43-
__slots__.append('_deprel') # Universal Stanford dependency relation to the HEAD (root iff HEAD = 0).
44-
__slots__.append('_raw_deps') # Secondary dependencies (head-deprel pairs) in their original CoNLLU format.
45-
__slots__.append('_misc') # Any other annotation.
46-
47-
# (B) Udapi-specific extra features:
48-
__slots__.append('_feats') # Deserialized morphological features stored in a dict (feature -> value).
49-
__slots__.append('_deps') # Deserialized secondary dependencies in a list od {parent, deprel} dicts.
50-
__slots__.append('_parent') # Parent node.
51-
__slots__.append('_children') # Ord-ordered list of child nodes.
52-
__slots__.append('_aux') # Other technical attributes.
32+
__slots__ = [
33+
'ord', # Word index, integer starting at 1 for each new sentence.
34+
'form', # Word form or punctuation symbol.
35+
'lemma', # Lemma or stem of word form.
36+
'upostag', # Universal POS tag drawn from our revised version of the Google UPOS tags.
37+
'xpostag', # Language-specific part-of-speech tag; underscore if not available.
38+
'head', # Head of the current token, which is either a value of ID or zero (0).
39+
'deprel', # Universal Stanford dependency relation to the HEAD (root iff HEAD = 0).
40+
'misc', # Any other annotation.
41+
42+
'_raw_deps', # Secondary dependencies (head-deprel pairs) in their original CoNLLU format.
43+
'_deps', # Deserialized secondary dependencies in a list od {parent, deprel} dicts.
44+
'_raw_feats', # Morphological features in their original CoNLLU format.
45+
'_feats', # Deserialized morphological features stored in a dict (feature -> value).
46+
'_parent', # Parent node.
47+
'_children', # Ord-ordered list of child nodes.
48+
'_aux' # Other technical attributes.
49+
]
5350

5451
def __init__(self, data=None):
5552
if data is None:
5653
data = dict()
5754

5855
# Initialization of the (A) list.
59-
self._ord = 0
60-
self._form = '_'
61-
self._lemma = '_'
62-
self._upostag = '_'
63-
self._xpostag = '_'
64-
self._raw_feats = '_'
65-
self._head = '_'
66-
self._deprel = '_'
67-
self._raw_deps = '_'
68-
self._misc = '_'
56+
# setattr(self, 'ord', 0)
57+
# self.ord = 0
58+
# self.form = '_'
59+
# self.lemma = '_'
60+
# self.upostag = '_'
61+
# self.xpostag = '_'
62+
# self.head = '_'
63+
# self.deprel = '_'
64+
# self.misc = '_'
6965

7066
# Initialization of the (B) list.
71-
self._feats = None
67+
self._raw_deps = '_'
7268
self._deps = None
69+
self._raw_feats = '_'
70+
self._feats = None
7371
self._parent = None
7472
self._children = list()
7573
self._aux = dict()
@@ -90,46 +88,6 @@ def __str__(self):
9088
parent_ord = self.parent.ord
9189
return "<%d, %s, %s, %s>" % (self.ord, self.form, parent_ord, self.deprel)
9290

93-
@property
94-
def ord(self):
95-
return self._ord
96-
97-
@ord.setter
98-
def ord(self, value):
99-
self._ord = int(value)
100-
101-
@property
102-
def form(self):
103-
return self._form
104-
105-
@form.setter
106-
def form(self, value):
107-
self._form = value
108-
109-
@property
110-
def lemma(self):
111-
return self._lemma
112-
113-
@lemma.setter
114-
def lemma(self, value):
115-
self._lemma = value
116-
117-
@property
118-
def upostag(self):
119-
return self._upostag
120-
121-
@upostag.setter
122-
def upostag(self, value):
123-
self._upostag = value
124-
125-
@property
126-
def xpostag(self):
127-
return self._xpostag
128-
129-
@xpostag.setter
130-
def xpostag(self, value):
131-
self._xpostag = value
132-
13391
@property
13492
def raw_feats(self):
13593
"""
@@ -161,22 +119,6 @@ def raw_feats(self, value):
161119
self._raw_feats = str(value)
162120
self._feats = None
163121

164-
@property
165-
def head(self):
166-
return self._head
167-
168-
@head.setter
169-
def head(self, value):
170-
self._head = int(value)
171-
172-
@property
173-
def deprel(self):
174-
return self._deprel
175-
176-
@deprel.setter
177-
def deprel(self, value):
178-
self._deprel = value
179-
180122
@property
181123
def raw_deps(self):
182124
"""
@@ -208,14 +150,6 @@ def raw_deps(self, value):
208150
self._raw_deps = str(value)
209151
self._deps = None
210152

211-
@property
212-
def misc(self):
213-
return self._misc
214-
215-
@misc.setter
216-
def misc(self, value):
217-
self._misc = value
218-
219153
@property
220154
def feats(self):
221155
"""

0 commit comments

Comments
 (0)