Skip to content

Commit e0fad04

Browse files
author
Vincent Kriz
committed
Merge branch 'master' into zellig-harris-transformations
2 parents 216245d + ba3fcbf commit e0fad04

8 files changed

Lines changed: 375 additions & 1017 deletions

File tree

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ python:
44
- "2.7"
55
- "3.2"
66
- "3.4"
7+
- "3.5"
78
install:
89
- python setup.py install
9-
script: python -m py.test
10+
script:
11+
- python -m pytest
12+
- cd udapi/core/tests && ./external_tests.sh

bin/udapy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#!/usr/bin/env python
22

3-
import sys
43
import logging
54
import argparse
65

76
from udapi.core.run import Run
87

9-
8+
# Parse command line arguments.
109
argparser = argparse.ArgumentParser(description='udapy - Python interface to Udapi - API for Universal Dependencies')
11-
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.")
10+
argparser.add_argument("-q", "--quiet", action="store_true",
11+
help="Warning, info and debug messages are suppressed. Only fatal errors are reported.")
12+
argparser.add_argument("-v", "--verbose", action="store_true",
13+
help="Warning, info and debug messages are printed to the STDERR.")
1314
argparser.add_argument('scenario', nargs=argparse.REMAINDER, help="A sequence of blocks and their parameters.")
14-
args = argparser.parse_args()
1515

16+
args = argparser.parse_args()
1617

1718
# Set the level of logs according to parameters.
1819
if args.verbose:
@@ -24,7 +25,6 @@ else:
2425

2526
logging.basicConfig(format='%(asctime)-15s [%(levelname)7s] %(funcName)s - %(message)s', level=level)
2627

27-
2828
# Process and provide the scenario.
2929
if __name__ == "__main__":
3030
runner = Run(args)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22

3-
from distutils.core import setup
3+
from setuptools import setup, find_packages
44

55
setup(
66
name='udapi-python',
@@ -9,7 +9,7 @@
99
author='Vincent Kriz',
1010
author_email='kriz@ufal.mff.cuni.cz',
1111
url='https://github.com/udapi/udapi-python',
12-
packages=['udapi'],
12+
packages=find_packages(),
1313
scripts=['bin/udapy'],
1414
tests_require=['pytest'],
1515
)

udapi/block/write/conllu.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from udapi.core.block import Block
88

99

10-
node_attributes = ["ord", "form", "lemma", "upostag", "xpostag", "feats", "head", "deprel", "deps", "misc"]
11-
12-
1310
class Conllu(Block):
1411
"""
1512
A writer of the Conll-u files.
@@ -19,6 +16,12 @@ def __init__(self, args=None):
1916
if args is None:
2017
args = {}
2118

19+
super(Block, self).__init__()
20+
21+
# A list of Conllu columns.
22+
self.node_attributes = ["ord", "form", "lemma", "upostag", "xpostag",
23+
"raw_feats", "head", "deprel", "raw_deps", "misc"]
24+
2225
# File handler
2326
self.filename = None
2427
self.file_handler = None
@@ -28,7 +31,7 @@ def __init__(self, args=None):
2831
elif 'filename' in args:
2932
self.filename = args['filename']
3033
logging.debug('Opening file %s', self.filename)
31-
self.file_handler = open(self.filename, 'r')
34+
self.file_handler = open(self.filename, 'wb')
3235
else:
3336
logging.warning('No filename specified, using STDOUT.')
3437
self.file_handler = sys.stdout
@@ -69,22 +72,23 @@ def process_document(self, document):
6972

7073
# Nodes.
7174
for node in root.descendants():
72-
values = [getattr(node, node_attribute) for node_attribute in node_attributes]
75+
values = [getattr(node, node_attribute) for node_attribute in self.node_attributes]
7376
values[0] = str(values[0])
7477

7578
try:
7679
values[6] = str(node.parent.ord)
7780
except:
7881
values[6] = '0'
7982

80-
for index in range(0,len(values)):
81-
if values[index] == None:
83+
for index in range(0, len(values)):
84+
if values[index] is None:
8285
values[index] = ''
8386

8487
self.file_handler.write('\t'.join([value for value in values]))
8588
self.file_handler.write('\n')
8689

87-
self.file_handler.write("\n")
90+
if number_of_written_bundles != len(document.bundles) - 1:
91+
self.file_handler.write('\n')
8892

8993
number_of_written_bundles += 1
9094

udapi/core/node.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ def parent(self):
210210
@parent.setter
211211
def parent(self, new_parent):
212212
"""
213-
Check if the parent assignment is correct and assign a new parent for the current Node.
213+
Check if the parent assignment is valid (no cycles) and assign
214+
a new parent (dependency head) for the current node.
215+
If the node had a parent, it is detached first
216+
(from the list of original parent's children).
214217
215218
:param new_parent: A parent Node object.
216219

0 commit comments

Comments
 (0)