grafeno.linearizers.cypher_query module

class grafeno.linearizers.cypher_query.Linearizer(**kwds)

Bases: grafeno.linearizers.cypher_base.Linearizer

This linearizer converts the graph into a Cypher query, suitable for running against a Neo4J database.

The created query matches against subgraphs in the database with at least the same nodes and relations. If there are more nodes in the graph database, it also matches. If some node or relation in the grafeno graph is not present in the database subgraph, the whole subgraph doesn’t match.

If there are any question nodes (concept = '?') in the graph, the query finds the equivalent node in the database, and returns it and its full directed subcomponent. To reconstruct it, see reconstruct_graphs().

If there are no question nodes in the query, the number of matches is returned.

Methods

cypher_format_edge(head, child, edge, labels, gram)
cypher_format_node(node, labels, gram)
filter_node(node)
grafeno.linearizers.cypher_query.reconstruct_graphs(results)

This function can be used to reconstruct a grafeno concept graph from the results returned by a query from Neo4J created with the cypher_query linearizer.

from grafeno.linearizers.cypher_query import Linearizer as graph_to_cypher_query, reconstruct_graphs
query = query_graph.linearize(linearizer=graph_to_cypher_query)

from neo4j.v1 import GraphDatabase
driver = GraphDatabase.driver(**connection_params)
results = driver.session().run(query)

for graph in reconstruct_graphs(results):
    do_something_with(graph)