EmilStenstrom / conllu

A CoNLL-U parser that takes a CoNLL-U formatted string and turns it into a nested python dictionary.
MIT License
311 stars 50 forks source link

Cannot parse CoNNL-U Plus fields after reading file content #61

Closed harisont closed 2 years ago

harisont commented 2 years ago

It seems that if I write:

with open("my.conllup") as file:
        content = file.read()
        plus_fields = conllu.parse_conllu_plus_fields(file)

plus_fields is equal to None, while if run parse_conllu_plus_fields first and then read the file everything works as expected.

EmilStenstrom commented 2 years ago

@harisont I think that this just is how Python works. When you call read() on a file pointer, that pointer moves to the end of what you just read. So to conllu this file looks like it's empty. What happens if you add file.seek(0) after you read the file, but before you parse the plus fields?

Also, why do you need to parse the fields separate? Is there some feature that's missing from conllu that you need to build yourself?

harisont commented 2 years ago

Sorry, you're completely right! I got too used to stateless reasoning :laughing: