Exemplo n.º 1
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])
Exemplo n.º 2
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])
Exemplo n.º 3
0
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
annotation = Annotation('label', feature_strct)
annotation.features['another_feature'] = 'value_another'
annotation.features['feature3'] = 'value_3'

# Adding the annotations to the node
node_one.annotations.add(annotation)

# Rendering the Graph
graf_render = GrafRenderer(sys.stdout)
graf_render.render(graph)