From 68d2bfe309e1fac8da575125ca5e28cf7e4646cf Mon Sep 17 00:00:00 2001 From: mouffok Date: Tue, 24 Oct 2023 15:22:39 +0200 Subject: [PATCH] rm shapes and ontology path separation --- kgforge/core/archetypes/model.py | 16 ++------------ kgforge/specializations/models/demo_model.py | 7 ++----- .../models/rdf/pyshacl_shape_wrapper.py | 21 +------------------ .../models/rdf/rdf_model_directory_service.py | 16 ++------------ kgforge/specializations/models/rdf_model.py | 13 ++---------- 5 files changed, 9 insertions(+), 64 deletions(-) diff --git a/kgforge/core/archetypes/model.py b/kgforge/core/archetypes/model.py index 484b09ef..b9b4e084 100644 --- a/kgforge/core/archetypes/model.py +++ b/kgforge/core/archetypes/model.py @@ -177,16 +177,7 @@ def _initialize_service(self, source: str, **source_config) -> Any: if origin == "directory": - ontology_path = Path(source_config["ontology_path"]) \ - if "ontology_path" in source_config else None - shapes_path = Path(source_config["shapes_path"]) \ - if "shapes_path" in source_config else None - source_path = Path(source) - - return self._service_from_directory( - source_path=source_path, ontologies_path=ontology_path, shapes_path=shapes_path, - context_iri=context_iri - ) + return self._service_from_directory(dir_path=Path(source), context_iri=context_iri) elif origin == "url": return self._service_from_url(source, context_iri) elif origin == "store": @@ -197,10 +188,7 @@ def _initialize_service(self, source: str, **source_config) -> Any: @staticmethod @abstractmethod - def _service_from_directory( - source_path: Optional[Path], ontologies_path: Optional[Path], - shapes_path: Optional[Path], context_iri: Optional[str] - ) -> Any: + def _service_from_directory(dir_path: Path, context_iri: Optional[str]) -> Any: pass @staticmethod diff --git a/kgforge/specializations/models/demo_model.py b/kgforge/specializations/models/demo_model.py index 2cdb89ee..7f834c01 100644 --- a/kgforge/specializations/models/demo_model.py +++ b/kgforge/specializations/models/demo_model.py @@ -96,11 +96,8 @@ def _validate_one(self, resource: Resource, type_: str) -> None: # Utils. @staticmethod - def _service_from_directory( - source_path: Optional[Path], ontologies_path: Optional[Path], - shapes_path: Optional[Path], context_iri: Optional[str] - ): - return ModelLibrary(source_path) + def _service_from_directory(dir_path: Path, context_iri: Optional[str]): + return ModelLibrary(dir_path) class ModelLibrary: diff --git a/kgforge/specializations/models/rdf/pyshacl_shape_wrapper.py b/kgforge/specializations/models/rdf/pyshacl_shape_wrapper.py index da63a8ff..d1a64b10 100644 --- a/kgforge/specializations/models/rdf/pyshacl_shape_wrapper.py +++ b/kgforge/specializations/models/rdf/pyshacl_shape_wrapper.py @@ -1,30 +1,11 @@ -import pyshacl from pyshacl import Shape, ShapesGraph from rdflib import Graph, URIRef from pyshacl.constraints import ALL_CONSTRAINT_PARAMETERS +from typing import List, Optional, Set, Tuple, Dict from kgforge.specializations.models.rdf.collectors import ALL_COLLECTORS -from time import perf_counter -from typing import TYPE_CHECKING, List, Optional, Set, Tuple, Type, Union, Dict - -from rdflib import BNode, Literal, URIRef - -from pyshacl.consts import ( - SH_Info, - SH_resultSeverity, - SH_Warning, -) -from pyshacl.errors import ConstraintLoadError, ConstraintLoadWarning, ReportableRuntimeError, \ - ShapeLoadError - -from pyshacl.pytypes import GraphLike - -if TYPE_CHECKING: - from pyshacl.constraints import ConstraintComponent - from pyshacl.shapes_graph import ShapesGraph - ALL_COLLECTORS_MAP = {c.constraint(): c for c in ALL_COLLECTORS} diff --git a/kgforge/specializations/models/rdf/rdf_model_directory_service.py b/kgforge/specializations/models/rdf/rdf_model_directory_service.py index a5c8badc..456e8573 100644 --- a/kgforge/specializations/models/rdf/rdf_model_directory_service.py +++ b/kgforge/specializations/models/rdf/rdf_model_directory_service.py @@ -27,20 +27,8 @@ class DirectoryService(RdfService): - def __init__(self, source_path: Path, ontologies_path: Optional[Path], - shapes_path: Optional[Path], context_iri: str) -> None: - - g = Graph() - if ontologies_path is None and shapes_path is None: - if source_path is None: - raise Exception("Must specify source path") - else: - g = load_rdf_files(source_path, g) - else: - g = load_rdf_files(ontologies_path, g) - g = load_rdf_files(shapes_path, g) - - self._graph = g + def __init__(self, dir_path: Path, context_iri: str) -> None: + self._graph = load_rdf_files(dir_path, Graph()) self._shapes_graph = ShapesGraphWrapper(self._graph) super().__init__(self._graph, context_iri) diff --git a/kgforge/specializations/models/rdf_model.py b/kgforge/specializations/models/rdf_model.py index 99758691..5724cf69 100644 --- a/kgforge/specializations/models/rdf_model.py +++ b/kgforge/specializations/models/rdf_model.py @@ -132,17 +132,8 @@ def _validate_one(self, resource: Resource, type_: str) -> None: # Utils. @staticmethod - def _service_from_directory( - source_path: Optional[Path], - ontologies_path: Optional[Path], - shapes_path: Optional[Path], - context_iri: str, - **dir_config - ) -> RdfService: - return DirectoryService( - source_path=source_path, - ontologies_path=ontologies_path, shapes_path=shapes_path, context_iri=context_iri - ) + def _service_from_directory(dir_path: Path, context_iri: str, **dir_config) -> RdfService: + return DirectoryService(dir_path=dir_path, context_iri=context_iri) @staticmethod def _service_from_store(store: Callable, context_config: Optional[Dict],