cognee 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognee/api/v1/cloud/routers/get_checks_router.py +1 -1
- cognee/api/v1/cognify/cognify.py +44 -7
- cognee/api/v1/cognify/routers/get_cognify_router.py +2 -1
- cognee/api/v1/notebooks/routers/get_notebooks_router.py +2 -1
- cognee/api/v1/prune/prune.py +2 -2
- cognee/api/v1/search/search.py +1 -1
- cognee/api/v1/sync/sync.py +16 -5
- cognee/base_config.py +19 -1
- cognee/eval_framework/corpus_builder/task_getters/get_default_tasks_by_indices.py +2 -2
- cognee/infrastructure/databases/graph/kuzu/remote_kuzu_adapter.py +4 -1
- cognee/infrastructure/databases/relational/ModelBase.py +2 -1
- cognee/infrastructure/databases/relational/sqlalchemy/SqlAlchemyAdapter.py +2 -2
- cognee/infrastructure/databases/vector/chromadb/ChromaDBAdapter.py +2 -6
- cognee/infrastructure/databases/vector/config.py +1 -1
- cognee/infrastructure/databases/vector/embeddings/OllamaEmbeddingEngine.py +6 -5
- cognee/infrastructure/files/storage/LocalFileStorage.py +50 -0
- cognee/infrastructure/files/storage/S3FileStorage.py +56 -9
- cognee/infrastructure/files/storage/StorageManager.py +18 -0
- cognee/infrastructure/files/utils/get_file_metadata.py +6 -1
- cognee/infrastructure/llm/structured_output_framework/litellm_instructor/llm/anthropic/adapter.py +4 -2
- cognee/infrastructure/utils/run_async.py +9 -4
- cognee/infrastructure/utils/run_sync.py +4 -3
- cognee/modules/cloud/operations/check_api_key.py +4 -1
- cognee/modules/data/deletion/prune_system.py +5 -1
- cognee/modules/data/methods/create_authorized_dataset.py +9 -0
- cognee/modules/data/methods/get_authorized_dataset.py +1 -1
- cognee/modules/data/methods/get_authorized_dataset_by_name.py +11 -0
- cognee/modules/graph/utils/expand_with_nodes_and_edges.py +22 -8
- cognee/modules/graph/utils/retrieve_existing_edges.py +0 -2
- cognee/modules/notebooks/methods/create_notebook.py +34 -0
- cognee/modules/notebooks/methods/get_notebook.py +2 -2
- cognee/modules/notebooks/methods/get_notebooks.py +27 -1
- cognee/modules/notebooks/methods/update_notebook.py +0 -1
- cognee/modules/notebooks/models/Notebook.py +206 -1
- cognee/modules/notebooks/operations/run_in_local_sandbox.py +8 -5
- cognee/modules/observability/get_observe.py +14 -0
- cognee/modules/observability/observers.py +1 -0
- cognee/modules/ontology/base_ontology_resolver.py +42 -0
- cognee/modules/ontology/get_default_ontology_resolver.py +41 -0
- cognee/modules/ontology/matching_strategies.py +53 -0
- cognee/modules/ontology/models.py +20 -0
- cognee/modules/ontology/ontology_config.py +24 -0
- cognee/modules/ontology/ontology_env_config.py +45 -0
- cognee/modules/ontology/rdf_xml/{OntologyResolver.py → RDFLibOntologyResolver.py} +20 -28
- cognee/modules/pipelines/layers/resolve_authorized_user_dataset.py +13 -0
- cognee/modules/pipelines/layers/resolve_authorized_user_datasets.py +1 -1
- cognee/modules/pipelines/models/PipelineRunInfo.py +7 -2
- cognee/modules/retrieval/graph_completion_context_extension_retriever.py +1 -1
- cognee/modules/retrieval/graph_completion_cot_retriever.py +1 -1
- cognee/modules/retrieval/graph_completion_retriever.py +1 -1
- cognee/modules/retrieval/temporal_retriever.py +3 -3
- cognee/modules/retrieval/user_qa_feedback.py +1 -1
- cognee/modules/search/methods/get_search_type_tools.py +7 -0
- cognee/modules/search/methods/search.py +12 -13
- cognee/modules/search/utils/prepare_search_result.py +31 -9
- cognee/modules/search/utils/transform_context_to_graph.py +1 -1
- cognee/modules/search/utils/transform_insights_to_graph.py +28 -0
- cognee/modules/users/methods/create_user.py +4 -24
- cognee/modules/users/permissions/methods/authorized_give_permission_on_datasets.py +12 -0
- cognee/modules/users/permissions/methods/check_permission_on_dataset.py +11 -0
- cognee/modules/users/permissions/methods/get_all_user_permission_datasets.py +19 -2
- cognee/modules/users/permissions/methods/get_document_ids_for_user.py +10 -0
- cognee/modules/users/permissions/methods/get_principal.py +9 -0
- cognee/modules/users/permissions/methods/get_principal_datasets.py +11 -0
- cognee/modules/users/permissions/methods/get_role.py +10 -0
- cognee/modules/users/permissions/methods/get_specific_user_permission_datasets.py +3 -3
- cognee/modules/users/permissions/methods/get_tenant.py +9 -0
- cognee/modules/users/permissions/methods/give_default_permission_to_role.py +9 -0
- cognee/modules/users/permissions/methods/give_default_permission_to_tenant.py +9 -0
- cognee/modules/users/permissions/methods/give_default_permission_to_user.py +9 -0
- cognee/modules/users/permissions/methods/give_permission_on_dataset.py +10 -0
- cognee/modules/users/roles/methods/add_user_to_role.py +11 -0
- cognee/modules/users/roles/methods/create_role.py +10 -0
- cognee/modules/users/tenants/methods/add_user_to_tenant.py +12 -0
- cognee/modules/users/tenants/methods/create_tenant.py +10 -0
- cognee/root_dir.py +5 -0
- cognee/shared/cache.py +346 -0
- cognee/shared/utils.py +12 -0
- cognee/tasks/graph/extract_graph_from_data.py +53 -10
- cognee/tasks/graph/extract_graph_from_data_v2.py +16 -4
- cognee/tasks/ingestion/save_data_item_to_storage.py +1 -0
- cognee/tasks/temporal_graph/models.py +11 -6
- cognee/tests/cli_tests/cli_unit_tests/test_cli_main.py +5 -5
- cognee/tests/test_cognee_server_start.py +4 -4
- cognee/tests/test_temporal_graph.py +6 -34
- cognee/tests/unit/modules/ontology/test_ontology_adapter.py +330 -13
- cognee/tests/unit/modules/users/test_tutorial_notebook_creation.py +399 -0
- {cognee-0.3.2.dist-info → cognee-0.3.4.dist-info}/METADATA +11 -8
- {cognee-0.3.2.dist-info → cognee-0.3.4.dist-info}/RECORD +93 -86
- cognee-0.3.4.dist-info/entry_points.txt +2 -0
- cognee/api/v1/save/save.py +0 -335
- cognee/tests/test_save_export_path.py +0 -116
- cognee-0.3.2.dist-info/entry_points.txt +0 -2
- {cognee-0.3.2.dist-info → cognee-0.3.4.dist-info}/WHEEL +0 -0
- {cognee-0.3.2.dist-info → cognee-0.3.4.dist-info}/licenses/LICENSE +0 -0
- {cognee-0.3.2.dist-info → cognee-0.3.4.dist-info}/licenses/NOTICE.md +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
from rdflib import Graph, Namespace, RDF, OWL, RDFS
|
|
3
|
-
from cognee.modules.ontology.rdf_xml.
|
|
3
|
+
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
4
|
+
from cognee.modules.ontology.models import AttachedOntologyNode
|
|
5
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_default_ontology_resolver
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
def test_ontology_adapter_initialization_success():
|
|
7
|
-
"""Test successful initialization of
|
|
9
|
+
"""Test successful initialization of RDFLibOntologyResolver from get_default_ontology_resolver."""
|
|
8
10
|
|
|
9
|
-
adapter =
|
|
11
|
+
adapter = get_default_ontology_resolver()
|
|
10
12
|
adapter.build_lookup()
|
|
11
13
|
|
|
12
14
|
assert isinstance(adapter.lookup, dict)
|
|
@@ -14,7 +16,7 @@ def test_ontology_adapter_initialization_success():
|
|
|
14
16
|
|
|
15
17
|
def test_ontology_adapter_initialization_file_not_found():
|
|
16
18
|
"""Test OntologyAdapter initialization with nonexistent file."""
|
|
17
|
-
adapter =
|
|
19
|
+
adapter = RDFLibOntologyResolver(ontology_file="nonexistent.owl")
|
|
18
20
|
assert adapter.graph is None
|
|
19
21
|
|
|
20
22
|
|
|
@@ -27,7 +29,7 @@ def test_build_lookup():
|
|
|
27
29
|
|
|
28
30
|
g.add((ns.Audi, RDF.type, ns.Car))
|
|
29
31
|
|
|
30
|
-
resolver =
|
|
32
|
+
resolver = RDFLibOntologyResolver()
|
|
31
33
|
resolver.graph = g
|
|
32
34
|
resolver.build_lookup()
|
|
33
35
|
|
|
@@ -50,7 +52,7 @@ def test_find_closest_match_exact():
|
|
|
50
52
|
g.add((ns.Car, RDF.type, OWL.Class))
|
|
51
53
|
g.add((ns.Audi, RDF.type, ns.Car))
|
|
52
54
|
|
|
53
|
-
resolver =
|
|
55
|
+
resolver = RDFLibOntologyResolver()
|
|
54
56
|
resolver.graph = g
|
|
55
57
|
resolver.build_lookup()
|
|
56
58
|
|
|
@@ -71,7 +73,7 @@ def test_find_closest_match_fuzzy():
|
|
|
71
73
|
g.add((ns.Audi, RDF.type, ns.Car))
|
|
72
74
|
g.add((ns.BMW, RDF.type, ns.Car))
|
|
73
75
|
|
|
74
|
-
resolver =
|
|
76
|
+
resolver = RDFLibOntologyResolver()
|
|
75
77
|
resolver.graph = g
|
|
76
78
|
resolver.build_lookup()
|
|
77
79
|
|
|
@@ -92,7 +94,7 @@ def test_find_closest_match_no_match():
|
|
|
92
94
|
g.add((ns.Audi, RDF.type, ns.Car))
|
|
93
95
|
g.add((ns.BMW, RDF.type, ns.Car))
|
|
94
96
|
|
|
95
|
-
resolver =
|
|
97
|
+
resolver = RDFLibOntologyResolver()
|
|
96
98
|
resolver.graph = g
|
|
97
99
|
resolver.build_lookup()
|
|
98
100
|
|
|
@@ -102,10 +104,10 @@ def test_find_closest_match_no_match():
|
|
|
102
104
|
|
|
103
105
|
|
|
104
106
|
def test_get_subgraph_no_match_rdflib():
|
|
105
|
-
"""Test get_subgraph returns empty results for a non-existent node."""
|
|
107
|
+
"""Test get_subgraph returns empty results for a non-existent node using RDFLibOntologyResolver."""
|
|
106
108
|
g = Graph()
|
|
107
109
|
|
|
108
|
-
resolver =
|
|
110
|
+
resolver = get_default_ontology_resolver()
|
|
109
111
|
resolver.graph = g
|
|
110
112
|
resolver.build_lookup()
|
|
111
113
|
|
|
@@ -138,7 +140,7 @@ def test_get_subgraph_success_rdflib():
|
|
|
138
140
|
g.add((ns.VW, owns, ns.Audi))
|
|
139
141
|
g.add((ns.VW, owns, ns.Porsche))
|
|
140
142
|
|
|
141
|
-
resolver =
|
|
143
|
+
resolver = RDFLibOntologyResolver()
|
|
142
144
|
resolver.graph = g
|
|
143
145
|
resolver.build_lookup()
|
|
144
146
|
|
|
@@ -160,10 +162,10 @@ def test_get_subgraph_success_rdflib():
|
|
|
160
162
|
|
|
161
163
|
|
|
162
164
|
def test_refresh_lookup_rdflib():
|
|
163
|
-
"""Test that refresh_lookup rebuilds the lookup dict into a new object."""
|
|
165
|
+
"""Test that refresh_lookup rebuilds the lookup dict into a new object using RDFLibOntologyResolver."""
|
|
164
166
|
g = Graph()
|
|
165
167
|
|
|
166
|
-
resolver =
|
|
168
|
+
resolver = get_default_ontology_resolver()
|
|
167
169
|
resolver.graph = g
|
|
168
170
|
resolver.build_lookup()
|
|
169
171
|
|
|
@@ -172,3 +174,318 @@ def test_refresh_lookup_rdflib():
|
|
|
172
174
|
resolver.refresh_lookup()
|
|
173
175
|
|
|
174
176
|
assert resolver.lookup is not original_lookup
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def test_fuzzy_matching_strategy_exact_match():
|
|
180
|
+
"""Test FuzzyMatchingStrategy finds exact matches."""
|
|
181
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
182
|
+
|
|
183
|
+
strategy = FuzzyMatchingStrategy()
|
|
184
|
+
candidates = ["audi", "bmw", "mercedes"]
|
|
185
|
+
|
|
186
|
+
result = strategy.find_match("audi", candidates)
|
|
187
|
+
assert result == "audi"
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def test_fuzzy_matching_strategy_fuzzy_match():
|
|
191
|
+
"""Test FuzzyMatchingStrategy finds fuzzy matches."""
|
|
192
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
193
|
+
|
|
194
|
+
strategy = FuzzyMatchingStrategy(cutoff=0.6)
|
|
195
|
+
candidates = ["audi", "bmw", "mercedes"]
|
|
196
|
+
|
|
197
|
+
result = strategy.find_match("audii", candidates)
|
|
198
|
+
assert result == "audi"
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def test_fuzzy_matching_strategy_no_match():
|
|
202
|
+
"""Test FuzzyMatchingStrategy returns None when no match meets cutoff."""
|
|
203
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
204
|
+
|
|
205
|
+
strategy = FuzzyMatchingStrategy(cutoff=0.9)
|
|
206
|
+
candidates = ["audi", "bmw", "mercedes"]
|
|
207
|
+
|
|
208
|
+
result = strategy.find_match("completely_different", candidates)
|
|
209
|
+
assert result is None
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def test_fuzzy_matching_strategy_empty_candidates():
|
|
213
|
+
"""Test FuzzyMatchingStrategy handles empty candidates list."""
|
|
214
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
215
|
+
|
|
216
|
+
strategy = FuzzyMatchingStrategy()
|
|
217
|
+
|
|
218
|
+
result = strategy.find_match("audi", [])
|
|
219
|
+
assert result is None
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def test_base_ontology_resolver_initialization():
|
|
223
|
+
"""Test BaseOntologyResolver initialization with default matching strategy."""
|
|
224
|
+
from cognee.modules.ontology.base_ontology_resolver import BaseOntologyResolver
|
|
225
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
226
|
+
|
|
227
|
+
class TestOntologyResolver(BaseOntologyResolver):
|
|
228
|
+
def build_lookup(self):
|
|
229
|
+
pass
|
|
230
|
+
|
|
231
|
+
def refresh_lookup(self):
|
|
232
|
+
pass
|
|
233
|
+
|
|
234
|
+
def find_closest_match(self, name, category):
|
|
235
|
+
return None
|
|
236
|
+
|
|
237
|
+
def get_subgraph(self, node_name, node_type="individuals", directed=True):
|
|
238
|
+
return [], [], None
|
|
239
|
+
|
|
240
|
+
resolver = TestOntologyResolver()
|
|
241
|
+
assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def test_base_ontology_resolver_custom_matching_strategy():
|
|
245
|
+
"""Test BaseOntologyResolver initialization with custom matching strategy."""
|
|
246
|
+
from cognee.modules.ontology.base_ontology_resolver import BaseOntologyResolver
|
|
247
|
+
from cognee.modules.ontology.matching_strategies import MatchingStrategy
|
|
248
|
+
|
|
249
|
+
class CustomMatchingStrategy(MatchingStrategy):
|
|
250
|
+
def find_match(self, name, candidates):
|
|
251
|
+
return "custom_match"
|
|
252
|
+
|
|
253
|
+
class TestOntologyResolver(BaseOntologyResolver):
|
|
254
|
+
def build_lookup(self):
|
|
255
|
+
pass
|
|
256
|
+
|
|
257
|
+
def refresh_lookup(self):
|
|
258
|
+
pass
|
|
259
|
+
|
|
260
|
+
def find_closest_match(self, name, category):
|
|
261
|
+
return None
|
|
262
|
+
|
|
263
|
+
def get_subgraph(self, node_name, node_type="individuals", directed=True):
|
|
264
|
+
return [], [], None
|
|
265
|
+
|
|
266
|
+
custom_strategy = CustomMatchingStrategy()
|
|
267
|
+
resolver = TestOntologyResolver(matching_strategy=custom_strategy)
|
|
268
|
+
assert resolver.matching_strategy == custom_strategy
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def test_ontology_config_structure():
|
|
272
|
+
"""Test TypedDict structure for ontology configuration."""
|
|
273
|
+
from cognee.modules.ontology.ontology_config import Config
|
|
274
|
+
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
275
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
276
|
+
|
|
277
|
+
matching_strategy = FuzzyMatchingStrategy()
|
|
278
|
+
resolver = RDFLibOntologyResolver(matching_strategy=matching_strategy)
|
|
279
|
+
|
|
280
|
+
config: Config = {"ontology_config": {"ontology_resolver": resolver}}
|
|
281
|
+
|
|
282
|
+
assert config["ontology_config"]["ontology_resolver"] == resolver
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def test_get_ontology_resolver_default():
|
|
286
|
+
"""Test get_default_ontology_resolver returns a properly configured RDFLibOntologyResolver with FuzzyMatchingStrategy."""
|
|
287
|
+
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
288
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
289
|
+
|
|
290
|
+
resolver = get_default_ontology_resolver()
|
|
291
|
+
|
|
292
|
+
assert isinstance(resolver, RDFLibOntologyResolver)
|
|
293
|
+
assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def test_get_default_ontology_resolver():
|
|
297
|
+
"""Test get_default_ontology_resolver returns a properly configured RDFLibOntologyResolver with FuzzyMatchingStrategy."""
|
|
298
|
+
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
299
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
300
|
+
|
|
301
|
+
resolver = get_default_ontology_resolver()
|
|
302
|
+
|
|
303
|
+
assert isinstance(resolver, RDFLibOntologyResolver)
|
|
304
|
+
assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def test_rdflib_ontology_resolver_uses_matching_strategy():
|
|
308
|
+
"""Test that RDFLibOntologyResolver uses the provided matching strategy."""
|
|
309
|
+
from cognee.modules.ontology.matching_strategies import MatchingStrategy
|
|
310
|
+
|
|
311
|
+
class TestMatchingStrategy(MatchingStrategy):
|
|
312
|
+
def find_match(self, name, candidates):
|
|
313
|
+
return "test_match" if candidates else None
|
|
314
|
+
|
|
315
|
+
ns = Namespace("http://example.org/test#")
|
|
316
|
+
g = Graph()
|
|
317
|
+
g.add((ns.Car, RDF.type, OWL.Class))
|
|
318
|
+
g.add((ns.Audi, RDF.type, ns.Car))
|
|
319
|
+
|
|
320
|
+
resolver = RDFLibOntologyResolver(matching_strategy=TestMatchingStrategy())
|
|
321
|
+
resolver.graph = g
|
|
322
|
+
resolver.build_lookup()
|
|
323
|
+
|
|
324
|
+
result = resolver.find_closest_match("Audi", "individuals")
|
|
325
|
+
assert result == "test_match"
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def test_rdflib_ontology_resolver_default_matching_strategy():
|
|
329
|
+
"""Test that RDFLibOntologyResolver uses FuzzyMatchingStrategy by default."""
|
|
330
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
331
|
+
|
|
332
|
+
resolver = RDFLibOntologyResolver()
|
|
333
|
+
assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def test_get_ontology_resolver_from_env_success():
|
|
337
|
+
"""Test get_ontology_resolver_from_env returns correct resolver with valid parameters."""
|
|
338
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
339
|
+
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
340
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
341
|
+
|
|
342
|
+
resolver = get_ontology_resolver_from_env(
|
|
343
|
+
ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path="/test/path.owl"
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
assert isinstance(resolver, RDFLibOntologyResolver)
|
|
347
|
+
assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
|
|
348
|
+
assert resolver.ontology_file == "/test/path.owl"
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
def test_get_ontology_resolver_from_env_unsupported_resolver():
|
|
352
|
+
"""Test get_ontology_resolver_from_env raises EnvironmentError for unsupported resolver."""
|
|
353
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
354
|
+
|
|
355
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
356
|
+
get_ontology_resolver_from_env(
|
|
357
|
+
ontology_resolver="unsupported",
|
|
358
|
+
matching_strategy="fuzzy",
|
|
359
|
+
ontology_file_path="/test/path.owl",
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
assert "Unsupported ontology resolver: unsupported" in str(exc_info.value)
|
|
363
|
+
assert "Supported resolvers are: RdfLib with FuzzyMatchingStrategy" in str(exc_info.value)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def test_get_ontology_resolver_from_env_unsupported_strategy():
|
|
367
|
+
"""Test get_ontology_resolver_from_env raises EnvironmentError for unsupported strategy."""
|
|
368
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
369
|
+
|
|
370
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
371
|
+
get_ontology_resolver_from_env(
|
|
372
|
+
ontology_resolver="rdflib",
|
|
373
|
+
matching_strategy="unsupported",
|
|
374
|
+
ontology_file_path="/test/path.owl",
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
def test_get_ontology_resolver_from_env_empty_file_path():
|
|
381
|
+
"""Test get_ontology_resolver_from_env raises EnvironmentError for empty file path."""
|
|
382
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
383
|
+
|
|
384
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
385
|
+
get_ontology_resolver_from_env(
|
|
386
|
+
ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path=""
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def test_get_ontology_resolver_from_env_none_file_path():
|
|
393
|
+
"""Test get_ontology_resolver_from_env raises EnvironmentError for None file path."""
|
|
394
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
395
|
+
|
|
396
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
397
|
+
get_ontology_resolver_from_env(
|
|
398
|
+
ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path=None
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def test_get_ontology_resolver_from_env_empty_resolver():
|
|
405
|
+
"""Test get_ontology_resolver_from_env raises EnvironmentError for empty resolver."""
|
|
406
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
407
|
+
|
|
408
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
409
|
+
get_ontology_resolver_from_env(
|
|
410
|
+
ontology_resolver="", matching_strategy="fuzzy", ontology_file_path="/test/path.owl"
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
assert "Unsupported ontology resolver:" in str(exc_info.value)
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def test_get_ontology_resolver_from_env_empty_strategy():
|
|
417
|
+
"""Test get_ontology_resolver_from_env raises EnvironmentError for empty strategy."""
|
|
418
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
419
|
+
|
|
420
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
421
|
+
get_ontology_resolver_from_env(
|
|
422
|
+
ontology_resolver="rdflib", matching_strategy="", ontology_file_path="/test/path.owl"
|
|
423
|
+
)
|
|
424
|
+
|
|
425
|
+
assert "Unsupported ontology resolver: rdflib" in str(exc_info.value)
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
def test_get_ontology_resolver_from_env_default_parameters():
|
|
429
|
+
"""Test get_ontology_resolver_from_env with default empty parameters raises EnvironmentError."""
|
|
430
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
431
|
+
|
|
432
|
+
with pytest.raises(EnvironmentError) as exc_info:
|
|
433
|
+
get_ontology_resolver_from_env()
|
|
434
|
+
|
|
435
|
+
assert "Unsupported ontology resolver:" in str(exc_info.value)
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
def test_get_ontology_resolver_from_env_case_sensitivity():
|
|
439
|
+
"""Test get_ontology_resolver_from_env is case sensitive."""
|
|
440
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
441
|
+
|
|
442
|
+
with pytest.raises(EnvironmentError):
|
|
443
|
+
get_ontology_resolver_from_env(
|
|
444
|
+
ontology_resolver="RDFLIB",
|
|
445
|
+
matching_strategy="fuzzy",
|
|
446
|
+
ontology_file_path="/test/path.owl",
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
with pytest.raises(EnvironmentError):
|
|
450
|
+
get_ontology_resolver_from_env(
|
|
451
|
+
ontology_resolver="RdfLib",
|
|
452
|
+
matching_strategy="fuzzy",
|
|
453
|
+
ontology_file_path="/test/path.owl",
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def test_get_ontology_resolver_from_env_with_actual_file():
|
|
458
|
+
"""Test get_ontology_resolver_from_env works with actual file path."""
|
|
459
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
460
|
+
from cognee.modules.ontology.rdf_xml.RDFLibOntologyResolver import RDFLibOntologyResolver
|
|
461
|
+
from cognee.modules.ontology.matching_strategies import FuzzyMatchingStrategy
|
|
462
|
+
|
|
463
|
+
resolver = get_ontology_resolver_from_env(
|
|
464
|
+
ontology_resolver="rdflib",
|
|
465
|
+
matching_strategy="fuzzy",
|
|
466
|
+
ontology_file_path="/path/to/ontology.owl",
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
assert isinstance(resolver, RDFLibOntologyResolver)
|
|
470
|
+
assert isinstance(resolver.matching_strategy, FuzzyMatchingStrategy)
|
|
471
|
+
assert resolver.ontology_file == "/path/to/ontology.owl"
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def test_get_ontology_resolver_from_env_resolver_functionality():
|
|
475
|
+
"""Test that resolver created from env function works correctly."""
|
|
476
|
+
from cognee.modules.ontology.get_default_ontology_resolver import get_ontology_resolver_from_env
|
|
477
|
+
|
|
478
|
+
resolver = get_ontology_resolver_from_env(
|
|
479
|
+
ontology_resolver="rdflib", matching_strategy="fuzzy", ontology_file_path="/test/path.owl"
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
resolver.build_lookup()
|
|
483
|
+
assert isinstance(resolver.lookup, dict)
|
|
484
|
+
|
|
485
|
+
result = resolver.find_closest_match("test", "individuals")
|
|
486
|
+
assert result is None # Should return None for non-existent entity
|
|
487
|
+
|
|
488
|
+
nodes, relationships, start_node = resolver.get_subgraph("test", "individuals")
|
|
489
|
+
assert nodes == []
|
|
490
|
+
assert relationships == []
|
|
491
|
+
assert start_node is None
|