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.py 1.2 kB

123456789101112131415161718192021222324252627282930313233
  1. from reproduction.seqence_labelling.ner.data.Conll2003Loader import Conll2003DataLoader
  2. from reproduction.seqence_labelling.ner.data.Conll2003Loader import iob2, iob2bioes
  3. import unittest
  4. class TestTagSchemaConverter(unittest.TestCase):
  5. def test_iob2(self):
  6. tags = ['B-ORG', 'O', 'B-MISC', 'O', 'O', 'O', 'B-MISC', 'O', 'O']
  7. golden = ['B-ORG', 'O', 'B-MISC', 'O', 'O', 'O', 'B-MISC', 'O', 'O']
  8. self.assertListEqual(golden, iob2(tags))
  9. tags = ['I-ORG', 'O']
  10. golden = ['B-ORG', 'O']
  11. self.assertListEqual(golden, iob2(tags))
  12. tags = ['I-MISC', 'I-MISC', 'O', 'I-PER', 'I-PER', 'O']
  13. golden = ['B-MISC', 'I-MISC', 'O', 'B-PER', 'I-PER', 'O']
  14. self.assertListEqual(golden, iob2(tags))
  15. def test_iob2bemso(self):
  16. tags = ['B-MISC', 'I-MISC', 'O', 'B-PER', 'I-PER', 'O']
  17. golden = ['B-MISC', 'E-MISC', 'O', 'B-PER', 'E-PER', 'O']
  18. self.assertListEqual(golden, iob2bioes(tags))
  19. def test_conll2003_loader():
  20. path = '/hdd/fudanNLP/fastNLP/others/data/conll2003/train.txt'
  21. loader = Conll2003DataLoader().load(path)
  22. print(loader[:3])
  23. if __name__ == '__main__':
  24. test_conll2003_loader()