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.

test_conll.py 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import unittest
  2. import os
  3. from fastNLP.io import MsraNERPipe, PeopleDailyPipe, WeiboNERPipe, Conll2003Pipe, Conll2003NERPipe, \
  4. OntoNotesNERPipe
  5. @unittest.skipIf('TRAVIS' in os.environ, "Skip in travis")
  6. class TestConllPipe(unittest.TestCase):
  7. def test_process_from_file(self):
  8. for pipe in [MsraNERPipe, PeopleDailyPipe, WeiboNERPipe]:
  9. with self.subTest(pipe=pipe):
  10. print(pipe)
  11. data_bundle = pipe(bigrams=True, trigrams=True).process_from_file()
  12. print(data_bundle)
  13. data_bundle = pipe(encoding_type='bioes').process_from_file()
  14. print(data_bundle)
  15. class TestRunPipe(unittest.TestCase):
  16. def test_conll2003(self):
  17. for pipe in [Conll2003Pipe, Conll2003NERPipe]:
  18. with self.subTest(pipe=pipe):
  19. print(pipe)
  20. data_bundle = pipe().process_from_file('test/data_for_tests/conll_2003_example.txt')
  21. print(data_bundle)
  22. class TestNERPipe(unittest.TestCase):
  23. def test_process_from_file(self):
  24. data_dict = {
  25. 'weibo_NER': WeiboNERPipe,
  26. 'peopledaily': PeopleDailyPipe,
  27. 'MSRA_NER': MsraNERPipe,
  28. }
  29. for k, v in data_dict.items():
  30. pipe = v
  31. with self.subTest(pipe=pipe):
  32. data_bundle = pipe(bigrams=True, trigrams=True).process_from_file(f'test/data_for_tests/io/{k}')
  33. print(data_bundle)
  34. data_bundle = pipe(encoding_type='bioes').process_from_file(f'test/data_for_tests/io/{k}')
  35. print(data_bundle)
  36. class TestConll2003Pipe(unittest.TestCase):
  37. def test_conll(self):
  38. with self.assertWarns(Warning):
  39. data_bundle = Conll2003Pipe().process_from_file('test/data_for_tests/io/conll2003')
  40. print(data_bundle)
  41. def test_OntoNotes(self):
  42. data_bundle = OntoNotesNERPipe().process_from_file('test/data_for_tests/io/OntoNotes')
  43. print(data_bundle)