Пример #1
0
 def testnormalFormProduction3(self):
     tree = computeTree(data.give_obama_president_usa())
     NamedEntityMerging(tree).merge()
     PrepositionMerging(tree).merge()
     qw = simplify(tree)
     result = normalFormProduction(tree, qw)
     self.assertEqual(
         result, {
             "type":
             "intersection",
             "list": [{
                 "predicate": {
                     "type":
                     "list",
                     "list": [{
                         "type": "resource",
                         "value": "been"
                     }, {
                         "type": "resource",
                         "value": "identity"
                     }]
                 },
                 "type": "triple",
                 "subject": {
                     "type": "resource",
                     "value": "Obama"
                 },
                 "inverse-predicate": {
                     "type": "resource",
                     "value": "identity"
                 },
                 "object": {
                     "type": "missing"
                 }
             }, {
                 "predicate": {
                     "type":
                     "list",
                     "list": [{
                         "type": "resource",
                         "value": "been"
                     }, {
                         "type": "resource",
                         "value": "identity"
                     }]
                 },
                 "type": "triple",
                 "subject": {
                     "type": "resource",
                     "value": "United States president"
                 },
                 "inverse-predicate": {
                     "type": "resource",
                     "value": "identity"
                 },
                 "object": {
                     "type": "missing"
                 }
             }]
         })
Пример #2
0
 def testNamedEntity2(self):
     tree=computeTree(data.give_obama_president_usa())
     NamedEntityMerging(tree).merge()
     tree.sort()
     root=tree
     # Root
     self.assertEqual(root.wordList, [Word("ROOT", 0)])
     self.assertEqual(root.namedEntityTag, 'undef')
     self.assertEqual(root.dependency, 'undef')
     self.assertEqual(root.parent, None)
     self.assertEqual(len(root.child), 1)
     self.assertEqual(root.subtreeType, 'undef')
     self.assertEqual(root.dfsTag, 0)
     # Is
     is_=root.child[0]
     self.assertEqual(is_.wordList, [Word("is", 2, 'VBZ')])
     self.assertEqual(is_.namedEntityTag, 'undef')
     self.assertEqual(is_.dependency, 'ROOT')
     self.assertEqual(is_.parent, tree)
     self.assertEqual(len(is_.child), 2)
     self.assertEqual(is_.subtreeType, 'undef')
     self.assertEqual(is_.dfsTag, 0)
     # Obama
     obama=is_.child[0]
     self.assertEqual(obama.wordList, [Word("Obama", 1, 'NNP')])
     self.assertEqual(obama.namedEntityTag, 'PERSON')
     self.assertEqual(obama.dependency, 'nsubj')
     self.assertEqual(obama.parent, is_)
     self.assertEqual(len(obama.child), 0)
     self.assertEqual(obama.subtreeType, 'undef')
     self.assertEqual(obama.dfsTag, 0)
     # president
     president =is_.child[1]
     self.assertEqual(president.wordList, [Word("president", 6, 'NN')])
     self.assertEqual(president.namedEntityTag, 'undef')
     self.assertEqual(president.dependency, 'xcomp')
     self.assertEqual(president.parent, is_)
     self.assertEqual(len(president.child), 2)
     self.assertEqual(president.subtreeType, 'undef')
     self.assertEqual(president.dfsTag, 0)
     # The
     the=president.child[0]
     self.assertEqual(the.wordList, [Word("the", 3, 'DT')])
     self.assertEqual(the.namedEntityTag, 'undef')
     self.assertEqual(the.dependency, 'det')
     self.assertEqual(the.parent, president)
     self.assertEqual(len(the.child), 0)
     self.assertEqual(the.subtreeType, 'undef')
     self.assertEqual(the.dfsTag, 0)
     # United States
     united=president.child[1]
     self.assertEqual(united.wordList, [Word("United", 4, 'NNP'), Word("States", 5, 'NNPS')])
     self.assertEqual(united.namedEntityTag, 'LOCATION')
     self.assertEqual(united.dependency, 'compound')
     self.assertEqual(united.parent, president)
     self.assertEqual(len(united.child), 0)
     self.assertEqual(united.subtreeType, 'undef')
     self.assertEqual(united.dfsTag, 0)
    def testnormalFormProduction3(self):
        tree = computeTree(data.give_obama_president_usa())
        NamedEntityMerging(tree).merge()
        PrepositionMerging(tree).merge()
        qw = simplify(tree)
        result = normalFormProduction(tree, qw)
        self.assertEqual(result, {
    "type": "intersection",
    "list": [
        {
            "predicate": {
                "type": "list",
                "list": [
                    {
                        "type": "resource",
                        "value": "been"
                    },
                    {
                        "type": "resource",
                        "value": "identity"
                    }
                ]
            },
            "type": "triple",
            "subject": {
                "type": "resource",
                "value": "Obama"
            },
            "inverse-predicate": {
                "type": "resource",
                "value": "identity"
            },
            "object": {
                "type": "missing"
            }
        },
        {
            "predicate": {
                "type": "list",
                "list": [
                    {
                        "type": "resource",
                        "value": "been"
                    },
                    {
                        "type": "resource",
                        "value": "identity"
                    }
                ]
            },
            "type": "triple",
            "subject": {
                "type": "resource",
                "value": "United States president"
            },
            "inverse-predicate": {
                "type": "resource",
                "value": "identity"
            },
            "object": {
                "type": "missing"
            }
        }
    ]
})