Skip to content

Commit

Permalink
feat: add stanza python script
Browse files Browse the repository at this point in the history
  • Loading branch information
BrewingWeasel committed Jul 27, 2024
1 parent f98c9ad commit 2e19caa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions stanza/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import stanza

language = input()
try:
nlp = stanza.Pipeline(language)
except ValueError:
exit(1)
print("done")

while True:
contents = ""
while True:
line = input()
if line == "":
break;
contents += line + "\n"

doc = nlp(contents)

print("[")
for sent_index, sent in enumerate(doc.sentences):
for word_index, word in enumerate(sent.words):
# If it's not the first word, print a comma to conform to json syntax
if not (word_index == 0 and sent_index == 0):
print(",")
print(word, end="")
print("\n]")

0 comments on commit 2e19caa

Please sign in to comment.