You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

examples.py 2.1 kB

6 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. api/example.py contains all API examples provided by fastNLP.
  3. It is used as a tutorial for API or a test script since it is difficult to test APIs in travis.
  4. """
  5. from . import CWS, POS, Parser
  6. text = ['编者按:7月12日,英国航空航天系统公司公布了该公司研制的第一款高科技隐形无人机雷电之神。',
  7. '这款飞行从外型上来看酷似电影中的太空飞行器,据英国方面介绍,可以实现洲际远程打击。',
  8. '那么这款无人机到底有多厉害?']
  9. def chinese_word_segmentation():
  10. cws = CWS(device='cpu')
  11. print(cws.predict(text))
  12. def chinese_word_segmentation_test():
  13. cws = CWS(device='cpu')
  14. print(cws.test("../../test/data_for_tests/zh_sample.conllx"))
  15. def pos_tagging():
  16. # 输入已分词序列
  17. text = [['编者', '按:', '7月', '12日', ',', '英国', '航空', '航天', '系统', '公司', '公布', '了', '该', '公司',
  18. '研制', '的', '第一款', '高科技', '隐形', '无人机', '雷电之神', '。'],
  19. ['那么', '这', '款', '无人机', '到底', '有', '多', '厉害', '?']]
  20. pos = POS(device='cpu')
  21. print(pos.predict(text))
  22. def pos_tagging_test():
  23. pos = POS(device='cpu')
  24. print(pos.test("../../test/data_for_tests/zh_sample.conllx"))
  25. def syntactic_parsing():
  26. text = [['编者', '按:', '7月', '12日', ',', '英国', '航空', '航天', '系统', '公司', '公布', '了', '该', '公司',
  27. '研制', '的', '第一款', '高科技', '隐形', '无人机', '雷电之神', '。'],
  28. ['那么', '这', '款', '无人机', '到底', '有', '多', '厉害', '?']]
  29. parser = Parser(device='cpu')
  30. print(parser.predict(text))
  31. def syntactic_parsing_test():
  32. parser = Parser(device='cpu')
  33. print(parser.test("../../test/data_for_tests/zh_sample.conllx"))
  34. if __name__ == "__main__":
  35. # chinese_word_segmentation()
  36. # chinese_word_segmentation_test()
  37. # pos_tagging()
  38. # pos_tagging_test()
  39. syntactic_parsing()
  40. # syntactic_parsing_test()