tsproisl / textcomplexity

Linguistic and stylistic complexity measures for (literary) texts
GNU General Public License v3.0
76 stars 12 forks source link

run_stanza.py - AttributeError: type object 'CoNLL' has no attribute 'convert_dict' #6

Closed iiegn closed 9 months ago

iiegn commented 9 months ago

stanza deprecated convert_dict() and (at least in 1.7.0) it's not supported anymore. Hence, run_stanza.py fails with:

Traceback (most recent call last):
  File "/tmp/stanza/./run_stanza.py", line 41, in <module>
    main()
  File "/tmp/stanza/./run_stanza.py", line 33, in main
    conll = CoNLL.convert_dict(dicts)
AttributeError: type object 'CoNLL' has no attribute 'convert_dict'

which seemingly can be fixed with:

diff --git a/utils/run_stanza.py b/utils/run_stanza.py
index 02318ff..1508ac5 100755
--- a/utils/run_stanza.py
+++ b/utils/run_stanza.py
@@ -29,12 +29,7 @@ def main():
         filename = os.path.basename(fh.name)
         text = fh.read()
         doc = nlp(text)
-        dicts = doc.to_dict()
-        conll = CoNLL.convert_dict(dicts)
-        with open(os.path.join(args.output_dir, filename + ".conllu"), mode="w", encoding="utf-8") as out:
-            for sentence in conll:
-                out.write("\n".join(("\t".join(token) for token in sentence)))
-                out.write("\n\n")
+        CoNLL.write_doc2conll(doc, os.path.join(args.output_dir, filename + ".conllu"))
tsproisl commented 9 months ago

Thanks for noticing and providing a patch!