def testQuotationMerge(self): handler = QuotationHandler('foo') sentence = 'Who wrote "Lucy in the Sky with Diamonds" and "Let It Be"?' nonAmbiguousSentence = handler.pull(sentence) result = data.give_LSD_LIB() tree = computeTree(result) handler.push(tree) 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) # Wrote wrote = root.child[0] self.assertEqual(wrote.wordList, [Word("wrote", 2, 'VBD')]) self.assertEqual(wrote.namedEntityTag, 'undef') self.assertEqual(wrote.dependency, 'ROOT') self.assertEqual(wrote.parent, root) self.assertEqual(len(wrote.child), 2) self.assertEqual(wrote.subtreeType, 'undef') self.assertEqual(wrote.dfsTag, 0) # Who who = wrote.child[0] self.assertEqual(who.wordList, [Word("Who", 1, 'WP')]) self.assertEqual(who.namedEntityTag, 'undef') self.assertEqual(who.dependency, 'nsubj') self.assertEqual(who.parent, wrote) self.assertEqual(len(who.child), 0) self.assertEqual(who.subtreeType, 'undef') self.assertEqual(who.dfsTag, 0) # Lucy in the Sky with Diamondss lucy = wrote.child[1] self.assertEqual(lucy.wordList, [Word("Lucy in the Sky with Diamonds", 3, 'QUOTE')]) self.assertEqual(lucy.namedEntityTag, 'QUOTATION') self.assertEqual(lucy.dependency, 'dobj') self.assertEqual(lucy.parent, wrote) self.assertEqual(len(lucy.child), 1) self.assertEqual(lucy.subtreeType, 'undef') self.assertEqual(lucy.dfsTag, 0) # Let it be let = lucy.child[0] self.assertEqual(let.wordList, [Word("Let It Be", 5, 'QUOTE')]) self.assertEqual(let.namedEntityTag, 'QUOTATION') self.assertEqual(let.dependency, 'conj_and') self.assertEqual(let.parent, lucy) self.assertEqual(len(let.child), 0) self.assertEqual(let.subtreeType, 'undef') self.assertEqual(let.dfsTag, 0)
def testQuotationMerge(self): handler = QuotationHandler('foo') sentence = 'Who wrote "Lucy in the Sky with Diamonds" and "Let It Be"?' nonAmbiguousSentence = handler.pull(sentence) result=data.give_LSD_LIB() tree=computeTree(result['sentences'][0]) handler.push(tree) 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) # Wrote wrote=root.child[0] self.assertEqual(wrote.wordList, [Word("wrote", 2, 'VBD')]) self.assertEqual(wrote.namedEntityTag, 'undef') self.assertEqual(wrote.dependency, 'root') self.assertEqual(wrote.parent, root) self.assertEqual(len(wrote.child), 2) self.assertEqual(wrote.subtreeType, 'undef') self.assertEqual(wrote.dfsTag, 0) # Who who=wrote.child[0] self.assertEqual(who.wordList, [Word("Who", 1, 'WP')]) self.assertEqual(who.namedEntityTag, 'undef') self.assertEqual(who.dependency, 'nsubj') self.assertEqual(who.parent, wrote) self.assertEqual(len(who.child), 0) self.assertEqual(who.subtreeType, 'undef') self.assertEqual(who.dfsTag, 0) # Lucy in the Sky with Diamondss lucy=wrote.child[1] self.assertEqual(lucy.wordList, [Word("Lucy in the Sky with Diamonds", 3, 'QUOTE')]) self.assertEqual(lucy.namedEntityTag, 'QUOTATION') self.assertEqual(lucy.dependency, 'dobj') self.assertEqual(lucy.parent, wrote) self.assertEqual(len(lucy.child), 1) self.assertEqual(lucy.subtreeType, 'undef') self.assertEqual(lucy.dfsTag, 0) # Let it be let=lucy.child[0] self.assertEqual(let.wordList, [Word("Let It Be", 5, 'QUOTE')]) self.assertEqual(let.namedEntityTag, 'QUOTATION') self.assertEqual(let.dependency, 'conj_and') self.assertEqual(let.parent, lucy) self.assertEqual(len(let.child), 0) self.assertEqual(let.subtreeType, 'undef') self.assertEqual(let.dfsTag, 0)
def testnormalFormProduction2(self): handler = QuotationHandler('foo') sentence = 'Who wrote "Lucy in the Sky with Diamonds" and "Let It Be"?' nonAmbiguousSentence = handler.pull(sentence) result=data.give_LSD_LIB() tree=computeTree(result) handler.push(tree) NamedEntityMerging(tree).merge() PrepositionMerging(tree).merge() qw = simplify(tree) result = normalFormProduction(tree, qw) self.assertEqual(result, { "list": [ { "inverse-predicate": { "list": [ { "value": "author", "type": "resource" }, { "value": "writer", "type": "resource" } ], "type": "list" }, "subject": { "type": "missing" }, "object": { "value": "Lucy in the Sky with Diamonds", "type": "resource" }, "type": "triple", "predicate": { "list": [ { "value": "written", "type": "resource" }, { "value": "literary works", "type": "resource" }, { "value": "bibliography", "type": "resource" }, { "value": "notable work", "type": "resource" } ], "type": "list" } }, { "inverse-predicate": { "list": [ { "value": "author", "type": "resource" }, { "value": "writer", "type": "resource" } ], "type": "list" }, "subject": { "type": "missing" }, "object": { "value": "Let It Be", "type": "resource" }, "type": "triple", "predicate": { "list": [ { "value": "written", "type": "resource" }, { "value": "literary works", "type": "resource" }, { "value": "bibliography", "type": "resource" }, { "value": "notable work", "type": "resource" } ], "type": "list" } } ], "type": "intersection" })
def testnormalFormProduction2(self): handler = QuotationHandler('foo') sentence = 'Who wrote "Lucy in the Sky with Diamonds" and "Let It Be"?' nonAmbiguousSentence = handler.pull(sentence) result = data.give_LSD_LIB() tree = computeTree(result) handler.push(tree) NamedEntityMerging(tree).merge() PrepositionMerging(tree).merge() qw = simplify(tree) result = normalFormProduction(tree, qw) self.assertEqual( result, { "list": [{ "inverse-predicate": { "list": [{ "value": "author", "type": "resource" }, { "value": "writer", "type": "resource" }], "type": "list" }, "subject": { "type": "missing" }, "object": { "value": "Lucy in the Sky with Diamonds", "type": "resource" }, "type": "triple", "predicate": { "list": [{ "value": "written", "type": "resource" }, { "value": "literary works", "type": "resource" }, { "value": "bibliography", "type": "resource" }, { "value": "notable work", "type": "resource" }], "type": "list" } }, { "inverse-predicate": { "list": [{ "value": "author", "type": "resource" }, { "value": "writer", "type": "resource" }], "type": "list" }, "subject": { "type": "missing" }, "object": { "value": "Let It Be", "type": "resource" }, "type": "triple", "predicate": { "list": [{ "value": "written", "type": "resource" }, { "value": "literary works", "type": "resource" }, { "value": "bibliography", "type": "resource" }, { "value": "notable work", "type": "resource" }], "type": "list" } }], "type": "intersection" })