greek-nlp-toolkit-demo / test_run.py
eloukas's picture
Set TOKENIZERS_PARALLELISM to false in test_run.py
74d3a34
import os
from gr_nlp_toolkit import Pipeline
os.environ["TOKENIZERS_PARALLELISM"] = "false"
# Use this file only for testing purposes
nlp_pos_ner_dp = Pipeline(
"pos,ner,dp"
) # Instantiate the Pipeline with the DP, POS and NER processors
doc_pos_ner_dp = nlp_pos_ner_dp(
"Η Αργεντινή κέρδισε το Παγκόσμιο Κύπελλο το 2022"
) # Apply the pipeline to a sentence in Greek
# Iterate over the generated tokens
for token in doc_pos_ner_dp.tokens:
print(
f"Text: {token.text},"
f" NER: {token.ner}," # Print the NER value of the token
f" UPOS: {token.upos}, " # UPOS
f" Morphological Features: {token.feats}, Head: {token.head},"
f" Deprel: {token.deprel}"
"\n---"
)
nlp_g2g = Pipeline("g2g") # Instantiate the Pipeline with the G2G processor
doc_g2g = nlp_g2g(
"h thessaloniki einai mia poli sti boreia ellada"
) # Apply the pipeline to a sentence in Greek
for token in doc_g2g.tokens:
# Gather all the token.text values and join them with a space
transliterated_text = " ".join([token.text for token in doc_g2g.tokens])
print(transliterated_text) # Print the transliterated text