Storage Operations

Cypher

Export your knowledge graph to Cypher to import it into openCypher-compatible databases.

The Perseus SDK allows you to export a KnowledgeGraph object to a Cypher Query Language (CQL) string or file. Cypher is a powerful, graph-optimized query language, and the openCypher project ensures its compatibility across various databases. This means you can use the generated CQL to import your graph into any openCypher-compatible database, such as Neo4j, FalkorDB, or AWS Neptune.

Saving the Graph to a Cypher File

You can use the save_cql() method on a KnowledgeGraph object to save it to a local CQL file.

For more details on the save_cql method, refer to the Python API.

import perseus_client

knowledge_graphs = perseus_client.build_graph(
    file_paths=["assets/sample.txt"],
)

for i, kg in enumerate(knowledge_graphs):
    file_path = f"./output/graph_{i}.cql"
    kg.save_cql(file_path)

Getting Cypher as a String Variable

For more details on the to_cql method, refer to the Python API.

import perseus_client

knowledge_graphs = perseus_client.build_graph(
    file_paths=["assets/sample.txt"],
)

for kg in knowledge_graphs:
    cql_content = kg.to_cql()

Getting Cypher Statements as a List

After building a KnowledgeGraph, you can use the to_cypher_statements() method to get a list of individual Cypher queries, which can be useful for executing them one by one or integrating with various database clients.

For more details on the to_cypher_statements method, refer to the Python API.

import perseus_client

knowledge_graphs = perseus_client.build_graph(
    file_paths=["assets/sample.txt"],
)

for kg in knowledge_graphs:
    statements = kg.to_cypher_statements()
    for statement in statements:
        print(statement)