def test_equals(self): p1 = core.Passage("1") p2 = core.Passage("2") p1l0 = layer0.Layer0(p1) p2l0 = layer0.Layer0(p2) p1l1 = layer1.Layer1(p1) p2l1 = layer1.Layer1(p2) self.assertTrue(p1.equals(p2) and p2.equals(p1)) # Checks basic passage equality and Attrib/tag/len differences p1l0.add_terminal("0", False) p1l0.add_terminal("1", False) p1l0.add_terminal("2", False) p2l0.add_terminal("0", False) p2l0.add_terminal("1", False) p2l0.add_terminal("2", False) self.assertTrue(p1.equals(p2) and p2.equals(p1)) pnct2 = p2l0.add_terminal("3", True) self.assertFalse(p1.equals(p2) or p2.equals(p1)) temp = p1l0.add_terminal("3", False) self.assertFalse(p1.equals(p2) or p2.equals(p1)) temp.destroy() pnct1 = p1l0.add_terminal("3", True) self.assertTrue(p1.equals(p2) and p2.equals(p1)) # Check Edge and node equality ps1 = p1l1.add_fnode(None, layer1.EdgeTags.ParallelScene) self.assertFalse(p1.equals(p2) or p2.equals(p1)) ps2 = p2l1.add_fnode(None, layer1.EdgeTags.ParallelScene) self.assertTrue(p1.equals(p2) and p2.equals(p1)) p1l1.add_fnode(ps1, layer1.EdgeTags.Participant) self.assertFalse(p1.equals(p2) or p2.equals(p1)) self.assertTrue(ps1.equals(ps2, recursive=False)) p2l1.add_fnode(ps2, layer1.EdgeTags.Process) self.assertFalse(p1.equals(p2) or p2.equals(p1)) p2l1.add_fnode(ps2, layer1.EdgeTags.Participant) self.assertFalse(p1.equals(p2) or p2.equals(p1)) p1l1.add_fnode(ps1, layer1.EdgeTags.Process) self.assertTrue(p1.equals(p2) and p2.equals(p1)) self.assertFalse( p1.equals(p2, ordered=True) or p2.equals(p1, ordered=True)) p1l1.add_fnode(ps1, layer1.EdgeTags.Adverbial, implicit=True) ps2d3 = p2l1.add_fnode(ps2, layer1.EdgeTags.Adverbial) self.assertFalse(p1.equals(p2) or p2.equals(p1)) ps2d3.attrib["implicit"] = True self.assertTrue(p1.equals(p2) and p2.equals(p1)) ps2[2].attrib["remote"] = True self.assertFalse(p1.equals(p2) or p2.equals(p1)) ps1[2].attrib["remote"] = True self.assertTrue(p1.equals(p2) and p2.equals(p1)) p1l1.add_punct(None, pnct1) self.assertFalse(p1.equals(p2) or p2.equals(p1)) p2l1.add_punct(None, pnct2) self.assertTrue(p1.equals(p2) and p2.equals(p1)) core.Layer("2", p1) self.assertFalse(p1.equals(p2) or p2.equals(p1))
def basic(): """Creates a basic :class:Passage to tinker with. Passage structure is as follows: Layer1: order by ID, heads = [1.2], all = [1.1, 1.2, 1.3] Layer2: order by node unique ID descending, heads = all = [2.2, 2.1], attrib={"test": True} Nodes (tag): 1.1 (1) 1.3 (3), attrib={"node": True} 1.2 (x), order by edge tag children: 1.3 Edge: tag=test1, attrib={"Edge": True} 1.1 Edge: tag=test2 2.1 (2), children [1.1, 1.2] with edge tags [test, test2] 2.2 (2), children [1.1, 1.2, 1.3] with tags [test, test1, test] """ p = core.Passage(ID="1") core.Layer(ID="1", root=p) core.Layer(ID="2", root=p, attrib={"test": True}, orderkey=lambda x: -1 * int(x.ID.split(".")[1])) # Order is explicitly different in order to break the alignment between # the ID/Edge ordering and the order of creation/addition node11 = core.Node(ID="1.1", root=p, tag="1") node13 = core.Node(ID="1.3", root=p, tag="3", attrib={"node": True}) node12 = core.Node(ID="1.2", root=p, tag="x", orderkey=operator.attrgetter("tag")) node21 = core.Node(ID="2.1", root=p, tag="2") node22 = core.Node(ID="2.2", root=p, tag="2") node12.add("test2", node11) node12.add("test1", node13, edge_attrib={"edge": True}) node21.add("test2", node12) node21.add("test", node11) node22.add("test1", node12) node22.add("test", node13) node22.add("test", node11) return p
def create_basic_passage(): """Creates a basic :class:Passage to tinker with. Passage structure is as follows: Layer1: order by ID, heads = [1.2], all = [1.1, 1.2, 1.3] Layer2: order by node unique ID descending, heads = all = [2.2, 2.1], attrib={'test': True} Nodes (tag): 1.1 (1) 1.3 (3), attrib={'node': True} 1.2 (x), order by edge tag children: 1.3 Edge: tag=test1, attrib={'Edge': True} 1.1 Edge: tag=test2 2.1 (2), children [1.1, 1.2] with edge tags [test, test2] 2.2 (2), children [1.1, 1.2, 1.3] with tags [test, test1, test] """ p = core.Passage(ID='1') core.Layer(ID='1', root=p) core.Layer(ID='2', root=p, attrib={'test': True}, orderkey=lambda x: -1 * int(x.ID.split('.')[1])) # Order is explicitly different in order to break the alignment between # the ID/Edge ordering and the order of creation/addition node11 = core.Node(ID='1.1', root=p, tag='1') node13 = core.Node(ID='1.3', root=p, tag='3', attrib={'node': True}) node12 = core.Node(ID='1.2', root=p, tag='x', orderkey=operator.attrgetter('tag')) node21 = core.Node(ID='2.1', root=p, tag='2') node22 = core.Node(ID='2.2', root=p, tag='2') node12.add('test2', node11) node12.add('test1', node13, edge_attrib={'edge': True}) node21.add('test2', node12) node21.add('test', node11) node22.add('test1', node12) node22.add('test', node13) node22.add('test', node11) return p