예제 #1
0
 def test_get_edge_by_id(self):
     fnode = Node('node_1')  # From Node
     tnode = Node('node_2')  # To Node
     edge = Edge('id_test', fnode, tnode)
     self.graph.nodes.add(fnode)
     self.graph.nodes.add(tnode)
     self.graph.edges.add(edge)
     self.assertEqual(self.graph.edges['id_test'], edge)
예제 #2
0
 def test_get_edge_by_nodes(self):
     fnode = Node('node_1')  # From Node
     tnode = Node('node_2')  # To Node
     edge = Edge('id_test', fnode, tnode)
     self.graph.nodes.add(fnode)
     self.graph.nodes.add(tnode)
     self.graph.edges.add(edge)
     self.assertEqual(self.graph.find_edge(fnode, tnode), edge)
     self.assertEqual(self.graph.find_edge(fnode.id, tnode.id), edge)
예제 #3
0
    def test_add_edge(self):
        # Test values
        fnode = Node('node_1')  # From Node
        tnode = Node('node_2')  # To Node

        edge = Edge('id_test', fnode, tnode)
        self.graph.nodes.add(fnode)
        self.graph.nodes.add(tnode)
        self.graph.edges.add(edge)
        self.assertListEqual(list(self.graph.edges), [edge])
예제 #4
0
    def test_renderer(self):
        filename = os.path.dirname(__file__) + '/sample_files/rend-file.xml'

        comparation_filename = os.path.dirname(__file__) + \
                               '/sample_files/expected-rend-file.xml'

        from_node = Node('node_zero')
        node = Node('node_one')

        anchors = ('1', '2')
        region = Region('region_one', *anchors)

        node.add_region(region)

        features = {'name': 'feature_name', 'value': 'feature_value'}

        annotation = Annotation('Annotation_label', features, 'annotation-1')

        node.annotations.add(annotation)

        edge = Edge('edge1', from_node, node)

        self.graph.edges.add(edge)
        self.graph.nodes.add(node)
        self.graph.regions.add(region)

        graf_render = GrafRenderer(filename)
        graf_render.render(self.graph)

        expected_tree = ElementTree.parse(comparation_filename)
        result_tree = ElementTree.parse(filename)

        expected_result = [
            ElementTree.tostring(i) for i in expected_tree.getroot()
        ]
        result = [ElementTree.tostring(i) for i in result_tree.getroot()]

        assert (result[0] == expected_result[0])
        assert (result[1] == expected_result[1])
        assert (result[2] == expected_result[2])
        assert (result[3] == expected_result[3])
예제 #5
0
# Create three nodes
node_one = Node('node_one')
node_two = Node('node_two')
node_three = Node('node_three')

# Create the Annotation Graph and set the values
graph = Graph()

#Adding the nodes
graph.nodes.add(node_one)
graph.nodes.add(node_two)
graph.nodes.add(node_three)

# Create the edge
edge = Edge(node_one, node_three)

# Add an the edge
#graph.add_edge(edge)

# Add Features
feature_strct = FeatureStructure() # Structure

# Adding two features
# There are two ways to it.
# Use the simple first
# Setting up all the features to the annotation
feature_strct['feature1'] = 'value_1'
feature_strct['feature2'] = 'value_2'

# Adding the features to annotations