Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stanfordnlp/stanza.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorPeng Qi <qipeng@users.noreply.github.com>2019-01-23 11:51:00 +0300
committerPeng Qi <qipeng@users.noreply.github.com>2019-01-23 11:51:06 +0300
commit9b632ec9e2e37b795adaffb8d02f1d8e3288b02e (patch)
tree18b787e875658d85948c13216e2bdba836ddd3e0 /demo
parenteedb20ad6ee1102e4695c73d6aade173c01048e2 (diff)
Demo script goes multi-lingual; don't confirm overwrite by default (by do it in the demo script)
Diffstat (limited to 'demo')
-rw-r--r--demo/pipeline_demo.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/demo/pipeline_demo.py b/demo/pipeline_demo.py
index f713d477..5ea5ec60 100644
--- a/demo/pipeline_demo.py
+++ b/demo/pipeline_demo.py
@@ -14,16 +14,26 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--models_dir', help='location of models files | default: ~/stanfordnlp_data',
default=DEFAULT_MODEL_DIR)
+ parser.add_argument('-l', '--lang', help='Demo language',
+ default="en")
args = parser.parse_args()
+
+ example_sentences = {"en": "Barack Obama was born in Hawaii. He was elected president in 2008.",
+ "zh": "達沃斯世界經濟論壇是每年全球政商界領袖聚在一起的年度盛事。",
+ "fr": "Vainqueur de Raonic à l'Open d'Australie, le Français Lucas Pouille atteint pour la première fois de sa carrière une demi-finale en Grand Chelem."}
+
+ if args.lang not in example_sentences:
+ print(f'Sorry, but we don\'t have a demo sentence for "{args.lang}" for the moment. Try one of these languages: {list(example_sentences.keys())}')
+ exit()
+
# download the models
- demo_language = "en"
- stanfordnlp.download(demo_language, args.models_dir)
+ stanfordnlp.download(args.lang, args.models_dir, confirm_if_exists=True)
# set up a pipeline
print('---')
print('Building pipeline...')
- pipeline = stanfordnlp.Pipeline(models_dir=args.models_dir, lang=demo_language)
+ pipeline = stanfordnlp.Pipeline(models_dir=args.models_dir, lang=args.lang)
# process the document
- doc = pipeline('Barack Obama was born in Hawaii. He was elected president in 2008.')
+ doc = pipeline(example_sentences[args.lang])
# access nlp annotations
print('')
print('---')