Ejemplo n.º 1
0
 def test_pipeline_graph_vertex_chain_dict_to_list_internal(self):
     pipeline_test = pipeline.Pipeline(
         self.graph_test_2.get_vertices_iterator(), [
             pipes.GraphVertexPipe(),
             pipes.ElementPropertiesPipe(internal=True)
         ])
     expected_output = [{
         '_id': 1,
         '_label': 'test_label',
         'test_field': 8
     }, {
         '_id': 2,
         '_label': 'test_label',
         'test_field': 10
     }, {
         '_id': 3,
         '_label': 'test_label',
         'test_field': 12,
         'time': 'now'
     }]
     self.assertEqual(pipeline_test.to_list(), expected_output)
     self.assertEqual(
         str(pipeline_test),
         '[DictKeyValueIterator(3), GraphVertexPipe(), ElementPropertiesPipe(internal:True)]'
     )
Ejemplo n.º 2
0
    def test_pipeline_graph_vertex_while(self):
        pipeline_test = pipeline.Pipeline(
            self.graph_test_1.get_vertices_iterator(),
            [pipes.GraphVertexPipe()])

        list_out = self._iterate_pipeline(pipeline_test)
        self.assertEquals(str(list_out),
                          '[Vertex(test_label), Vertex(test_label)]')
Ejemplo n.º 3
0
    def test_pipeline_graph_vertex_chain_to_list(self):
        pipeline_test = pipeline.Pipeline(
            self.graph_test_1.get_vertices_iterator(),
            [pipes.GraphVertexPipe(),
             pipes.ElementIdPipe()])

        self.assertEqual(pipeline_test.to_list(), [1, 2])
        self.assertEqual(
            str(pipeline_test),
            '[DictKeyValueIterator(2), GraphVertexPipe(), ElementIdPipe()]')
Ejemplo n.º 4
0
    def V(self, vertex_label=None, value=None):
        """
        Vertices
        """
        self.pipeline.add_pipe(pipes.GraphVertexPipe())

        if self.pipeline.starts is None:
            self.pipeline.set_starts(recommend_utils.DictKeyValueIterator(self.graph.vertices))

        return self
Ejemplo n.º 5
0
    def test_pipeline_graph_vertex_chain_to_list(self):
        graph = Graph()
        graph.add_vertex('test_label', {'test_field': 1})
        graph.add_vertex('test_label', {'test_field': 2})

        pipeline_test = pipeline.Pipeline(
            graph.get_vertices_iterator(),
            [pipes.GraphVertexPipe(),
             pipes.ElementIdPipe()])

        self.assertEqual(pipeline_test.to_list(), [1, 2])
Ejemplo n.º 6
0
    def test_pipeline_graph_vertex_while(self):
        graph = Graph()
        graph.add_vertex('test_label', {'test_field': 1})
        graph.add_vertex('test_label', {'test_field': 2})

        pipeline_test = pipeline.Pipeline(graph.get_vertices_iterator(),
                                          [pipes.GraphVertexPipe()])

        try:
            list_out = []
            while pipeline_test.has_next():
                current_object = pipeline_test.next()
                list_out.append(current_object.id)
        except recommend_utils.FastNoSuchElementException:
            # Ignore FastNoSuchElementException
            pass
        self.assertEqual(list_out, [1, 2])
Ejemplo n.º 7
0
    def test_pipeline_graph_vertex_chain_dict_to_list(self):
        graph = Graph()
        graph.add_vertex('test_label', {'test_field': 8})
        graph.add_vertex('test_label', {'test_field': 10})
        graph.add_vertex('test_label', {'test_field': 12, 'time': 'now'})

        pipeline_test = pipeline.Pipeline(
            graph.get_vertices_iterator(),
            [pipes.GraphVertexPipe(),
             pipes.ElementPropertiesPipe()])
        output = [{
            'test_field': 8
        }, {
            'test_field': 10
        }, {
            'test_field': 12,
            'time': 'now'
        }]
        self.assertEqual(pipeline_test.to_list(), output)
Ejemplo n.º 8
0
    def v(self, vertex_id, *vertex_ids):
        """
        Get Vertex by internal id
        """
        self.pipeline.add_pipe(pipes.GraphVertexPipe())

        if not self.pipeline.starts:
            out_list = []

            if self.graph.vertices.get(vertex_id):
                out_list.append(self.graph.vertices.get(vertex_id))

            for current_vertex_id in vertex_ids:
                if self.graph.vertices.get(current_vertex_id):
                    out_list.append(self.graph.vertices.get(current_vertex_id))

            self.pipeline.set_starts(recommend_utils.ListIterator(out_list))

        return self