fix: ruff format
This commit is contained in:
parent
3fd40df44a
commit
c8d695948f
2 changed files with 42 additions and 32 deletions
|
|
@ -163,6 +163,7 @@ class OntologyEngine:
|
|||
elif file_path.endswith(".owl") or file_path.endswith(".rdf"):
|
||||
from cognee.modules.ontology.rdf_xml.OntologyResolver import OntologyResolver
|
||||
from cognee.infrastructure.llm.LLMGateway import LLMGateway
|
||||
|
||||
resolver = OntologyResolver(ontology_file=file_path)
|
||||
nodes = []
|
||||
edges = []
|
||||
|
|
@ -176,14 +177,18 @@ class OntologyEngine:
|
|||
node_info["description"] = str(uri)
|
||||
# Generate embedding for node
|
||||
try:
|
||||
embedding = llm.generate_embedding(text=node_info["label"] + " " + node_info["description"])
|
||||
embedding = llm.generate_embedding(
|
||||
text=node_info["label"] + " " + node_info["description"]
|
||||
)
|
||||
except Exception:
|
||||
embedding = None
|
||||
node_info["embedding"] = embedding
|
||||
embeddings[key] = embedding
|
||||
nodes.append(node_info)
|
||||
for node in nodes:
|
||||
_, node_edges, _ = resolver.get_subgraph(node_name=node["id"], node_type=node["category"])
|
||||
_, node_edges, _ = resolver.get_subgraph(
|
||||
node_name=node["id"], node_type=node["category"]
|
||||
)
|
||||
for edge in node_edges:
|
||||
edge_info = {"source": edge[0], "relation": edge[1], "target": edge[2]}
|
||||
# Generate embedding for edge relation
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import asyncio
|
||||
from cognee.tasks.graph.infer_data_ontology import OntologyEngine
|
||||
|
||||
|
||||
def test_load_owl_rdf_file(tmp_path):
|
||||
# Create a minimal OWL file
|
||||
owl_content = '''<?xml version="1.0"?>
|
||||
# Create a minimal OWL file
|
||||
owl_content = """<?xml version="1.0"?>
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
|
||||
|
|
@ -11,20 +12,21 @@ def test_load_owl_rdf_file(tmp_path):
|
|||
<owl:NamedIndividual rdf:about="http://example.org/test#Audi">
|
||||
<rdf:type rdf:resource="http://example.org/test#Car"/>
|
||||
</owl:NamedIndividual>
|
||||
</rdf:RDF>'''
|
||||
owl_file = tmp_path / "test.owl"
|
||||
owl_file.write_text(owl_content)
|
||||
</rdf:RDF>"""
|
||||
owl_file = tmp_path / "test.owl"
|
||||
owl_file.write_text(owl_content)
|
||||
|
||||
engine = OntologyEngine()
|
||||
data = asyncio.run(engine.load_data(str(owl_file)))
|
||||
assert "nodes" in data
|
||||
assert "edges" in data
|
||||
assert "embeddings" in data
|
||||
assert any(n["id"] == "car" for n in data["nodes"])
|
||||
assert any(n["id"] == "audi" for n in data["nodes"])
|
||||
|
||||
engine = OntologyEngine()
|
||||
data = asyncio.run(engine.load_data(str(owl_file)))
|
||||
assert "nodes" in data
|
||||
assert "edges" in data
|
||||
assert "embeddings" in data
|
||||
assert any(n["id"] == "car" for n in data["nodes"])
|
||||
assert any(n["id"] == "audi" for n in data["nodes"])
|
||||
|
||||
def test_embeddings_are_generated(tmp_path):
|
||||
owl_content = '''<?xml version="1.0"?>
|
||||
owl_content = """<?xml version="1.0"?>
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
|
||||
|
|
@ -32,18 +34,19 @@ def test_embeddings_are_generated(tmp_path):
|
|||
<owl:NamedIndividual rdf:about="http://example.org/test#Audi">
|
||||
<rdf:type rdf:resource="http://example.org/test#Car"/>
|
||||
</owl:NamedIndividual>
|
||||
</rdf:RDF>'''
|
||||
owl_file = tmp_path / "test.owl"
|
||||
owl_file.write_text(owl_content)
|
||||
</rdf:RDF>"""
|
||||
owl_file = tmp_path / "test.owl"
|
||||
owl_file.write_text(owl_content)
|
||||
|
||||
engine = OntologyEngine()
|
||||
data = asyncio.run(engine.load_data(str(owl_file)))
|
||||
for node in data["nodes"]:
|
||||
assert "embedding" in node
|
||||
|
||||
engine = OntologyEngine()
|
||||
data = asyncio.run(engine.load_data(str(owl_file)))
|
||||
for node in data["nodes"]:
|
||||
assert "embedding" in node
|
||||
|
||||
def test_search_integration(tmp_path):
|
||||
# This test assumes search integration uses ontology_nodes
|
||||
owl_content = '''<?xml version="1.0"?>
|
||||
# This test assumes search integration uses ontology_nodes
|
||||
owl_content = """<?xml version="1.0"?>
|
||||
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
|
||||
|
|
@ -51,15 +54,17 @@ def test_search_integration(tmp_path):
|
|||
<owl:NamedIndividual rdf:about="http://example.org/test#Audi">
|
||||
<rdf:type rdf:resource="http://example.org/test#Car"/>
|
||||
</owl:NamedIndividual>
|
||||
</rdf:RDF>'''
|
||||
owl_file = tmp_path / "test.owl"
|
||||
owl_file.write_text(owl_content)
|
||||
</rdf:RDF>"""
|
||||
owl_file = tmp_path / "test.owl"
|
||||
owl_file.write_text(owl_content)
|
||||
|
||||
engine = OntologyEngine()
|
||||
data = asyncio.run(engine.load_data(str(owl_file)))
|
||||
assert hasattr(engine, "ontology_nodes")
|
||||
assert hasattr(engine, "ontology_edges")
|
||||
assert hasattr(engine, "ontology_embeddings")
|
||||
|
||||
|
||||
engine = OntologyEngine()
|
||||
data = asyncio.run(engine.load_data(str(owl_file)))
|
||||
assert hasattr(engine, "ontology_nodes")
|
||||
assert hasattr(engine, "ontology_edges")
|
||||
assert hasattr(engine, "ontology_embeddings")
|
||||
import pytest
|
||||
from rdflib import Graph, Namespace, RDF, OWL, RDFS
|
||||
from cognee.modules.ontology.rdf_xml.OntologyResolver import OntologyResolver, AttachedOntologyNode
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue