-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import sys | ||
import argparse | ||
|
||
ID,FORM,LEMMA,UCPOS,UPOS,UFEAT,UHEAD,UDEPREL,UDEPS,UMISC=range(10) | ||
ID,FORM,LEMMA,PLEMMA,POS,PPOS,FEAT,PFEAT,HEAD,PHEAD,DEPREL,PDEPREL=range(12) | ||
|
||
if __name__=="__main__": | ||
parser = argparse.ArgumentParser(description='Convert conllu to conll09 and back. Infers the direction on its own if no arguments given.') | ||
parser.add_argument('--output-format', default=None, help='Output format can be "u" or "09". If the input is in this format already, the conversion is a no-op and simply passes data through.') | ||
args = parser.parse_args() | ||
|
||
for line in sys.stdin: | ||
line=line.strip() | ||
if not line: | ||
elif line.startswith('#'): | ||
print line | ||
else: | ||
cols=line.split('\t') | ||
if len(cols)==10: | ||
#UD in | ||
if args.output_format=="u": | ||
#UD out, no-op | ||
print '\t'.join(cols) | ||
else: | ||
#UD -> 09 | ||
print '\t'.join((cols[ID],cols[FORM],cols[LEMMA],cols[LEMMA],cols[UCPOS],cols[UCPOS],cols[UFEAT],cols[UFEAT],cols[UHEAD],cols[UHEAD],cols[UDEPREL],cols[UDEPREL],'_','_')) | ||
else: | ||
#09 in | ||
assert len(cols) in (12,13,14), cols | ||
if args.output_format=="09": | ||
#09 out, no-op | ||
print '\t'.join(cols) | ||
else: | ||
#09 -> UD | ||
print '\t'.join((cols[ID],cols[FORM],cols[PLEMMA],cols[PPOS],'_',cols[PFEAT],cols[PHEAD],cols[PDEPREL],'_','_')) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters