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

86 lines
4.0 KiB

6 years ago
  1. import unittest
  2. class TestCase(unittest.TestCase):
  3. @classmethod
  4. def setUpClass(self):
  5. from stanford_parser.parser import Parser
  6. self.parser = Parser()
  7. def testParse(self):
  8. dependencies = self.parser.parseToStanfordDependencies("Pick up the tire pallet.")
  9. tupleResult = [(rel, gov.text, dep.text) for rel, gov, dep in dependencies.dependencies]
  10. self.assertEqual(tupleResult, [('prt', 'Pick', 'up'),
  11. ('det', 'pallet', 'the'),
  12. ('nn', 'pallet', 'tire'),
  13. ('dobj', 'Pick', 'pallet')])
  14. self.assertEqual(dependencies.tagForTokenStandoff(gov), "VB")
  15. self.assertEqual(dependencies.tagForTokenStandoff(dep), "NN")
  16. def testParseRefexpNextTo(self):
  17. dependencies = self.parser.parseToStanfordDependencies("Pick up the tire pallet next to the truck.")
  18. tupleResult = [(rel, gov.text, dep.text) for rel, gov, dep in dependencies.dependencies]
  19. self.assertEqual(tupleResult,
  20. [('prt', 'Pick', 'up'),
  21. ('det', 'pallet', 'the'),
  22. ('nn', 'pallet', 'tire'),
  23. ('dobj', 'Pick', 'pallet'),
  24. ('det', 'truck', 'the'),
  25. ('prep_next_to', 'pallet', 'truck')])
  26. def testParseRefexpNear(self):
  27. dependencies =self.parser.parseToStanfordDependencies("Pick up the tire pallet near the truck.")
  28. tupleResult = [(rel, gov.text, dep.text) for rel, gov, dep in dependencies.dependencies]
  29. self.assertEqual(tupleResult,
  30. [('prt', 'Pick', 'up'),
  31. ('det', 'pallet', 'the'),
  32. ('nn', 'pallet', 'tire'),
  33. ('dobj', 'Pick', 'pallet'),
  34. ('det', 'truck', 'the'),
  35. ('prep_near', 'pallet', 'truck')])
  36. def testParseLong(self):
  37. # this sentence has a self dependency that the python code filters out.
  38. # between drop and drop.
  39. dependencies = self.parser.parseToStanfordDependencies("Grab the skid of tires right in front of you " +
  40. "and drop it off just in front and to the " +
  41. "right of the far skid of tires.")
  42. tupleResult = [(rel, gov.text, dep.text) for rel, gov, dep in dependencies.dependencies]
  43. self.assertEqual(tupleResult,
  44. [('det', 'skid', 'the'), ('dobj', 'Grab', 'skid'),
  45. ('prep_of', 'skid', 'tires'), ('dep', 'Grab', 'right'),
  46. ('prep_in', 'Grab', 'front'), ('prep_of', 'front', 'you'),
  47. ('conj_and', 'Grab', 'drop'), ('dobj', 'drop', 'it'), ('prt', 'drop', 'off'),
  48. ('advmod', 'drop', 'just'), ('prep_in', 'drop', 'front'), ('det', 'right', 'the'),
  49. ('prep_to', 'drop', 'right'), ('det', 'skid', 'the'), ('amod', 'skid', 'far'),
  50. ('prep_of', 'right', 'skid'), ('prep_of', 'skid', 'tires')])
  51. def testAllCaps(self):
  52. dependencies = self.parser.parseToStanfordDependencies("GO TO THE TIRE PALLET NEXT TO THE TRUCK.")
  53. tupleResult = [(rel, gov.text, dep.text) for rel, gov, dep in dependencies.dependencies]
  54. self.assertEqual(tupleResult,
  55. [('nn', 'PALLET', 'GO'),
  56. ('nn', 'PALLET', 'TO'),
  57. ('nn', 'PALLET', 'THE'),
  58. ('nn', 'PALLET', 'TIRE'),
  59. ('nsubj', 'NEXT', 'PALLET'),
  60. ('dep', 'NEXT', 'TO'),
  61. ('det', 'TRUCK', 'THE'),
  62. ('dobj', 'TO', 'TRUCK')])