Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ python:
- "2.7"
- "3.2"
- "3.4"
- "3.5"
install:
- python setup.py install
script: python -m py.test
script:
- python -m pytest
- cd udapi/core/tests && ./external_tests.sh
12 changes: 6 additions & 6 deletions bin/udapy
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/usr/bin/env python

import sys
import logging
import argparse

from udapi.core.run import Run


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

args = argparser.parse_args()

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

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


# Process and provide the scenario.
if __name__ == "__main__":
runner = Run(args)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

from distutils.core import setup
from setuptools import setup, find_packages

setup(
name='udapi-python',
Expand All @@ -9,7 +9,7 @@
author='Vincent Kriz',
author_email='kriz@ufal.mff.cuni.cz',
url='https://github.com/udapi/udapi-python',
packages=['udapi'],
packages=find_packages(),
scripts=['bin/udapy'],
tests_require=['pytest'],
)
20 changes: 12 additions & 8 deletions udapi/block/write/conllu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
from udapi.core.block import Block


node_attributes = ["ord", "form", "lemma", "upostag", "xpostag", "feats", "head", "deprel", "deps", "misc"]


class Conllu(Block):
"""
A writer of the Conll-u files.
Expand All @@ -19,6 +16,12 @@ def __init__(self, args=None):
if args is None:
args = {}

super(Block, self).__init__()

# A list of Conllu columns.
self.node_attributes = ["ord", "form", "lemma", "upostag", "xpostag",
"raw_feats", "head", "deprel", "raw_deps", "misc"]

# File handler
self.filename = None
self.file_handler = None
Expand All @@ -28,7 +31,7 @@ def __init__(self, args=None):
elif 'filename' in args:
self.filename = args['filename']
logging.debug('Opening file %s', self.filename)
self.file_handler = open(self.filename, 'r')
self.file_handler = open(self.filename, 'wb')
else:
logging.warning('No filename specified, using STDOUT.')
self.file_handler = sys.stdout
Expand Down Expand Up @@ -69,22 +72,23 @@ def process_document(self, document):

# Nodes.
for node in root.descendants():
values = [getattr(node, node_attribute) for node_attribute in node_attributes]
values = [getattr(node, node_attribute) for node_attribute in self.node_attributes]
values[0] = str(values[0])

try:
values[6] = str(node.parent.ord)
except:
values[6] = '0'

for index in range(0,len(values)):
if values[index] == None:
for index in range(0, len(values)):
if values[index] is None:
values[index] = ''

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

self.file_handler.write("\n")
if number_of_written_bundles != len(document.bundles) - 1:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to CoNLL-U specification, each tree (including the last one) must end with an empty line

self.file_handler.write('\n')

number_of_written_bundles += 1

Expand Down
Loading