Skip to content

Commit

Permalink
rm shapes and ontology path separation
Browse files Browse the repository at this point in the history
  • Loading branch information
ssssarah committed Oct 24, 2023
1 parent fe7747c commit 68d2bfe
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 64 deletions.
16 changes: 2 additions & 14 deletions kgforge/core/archetypes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions kgforge/specializations/models/demo_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 1 addition & 20 deletions kgforge/specializations/models/rdf/pyshacl_shape_wrapper.py
Original file line number Diff line number Diff line change
@@ -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}

Expand Down
16 changes: 2 additions & 14 deletions kgforge/specializations/models/rdf/rdf_model_directory_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 2 additions & 11 deletions kgforge/specializations/models/rdf_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 68d2bfe

Please sign in to comment.