Skip to content

Commit

Permalink
Neat 279 add write endpoint (#491)
Browse files Browse the repository at this point in the history
Improved
Single NeatGraphStore instantiated via three options:
from_memory_store
from_oxi_store
from_sparql_store
Removed
Removed various superclassing of NeatGraphStore
Remove Prometheus reminisce in code base
Remove logging
Added
RdfFileExtractor graph extractor added.
  • Loading branch information
nikokaoja authored Jun 10, 2024
1 parent 4db0eb9 commit 251e585
Show file tree
Hide file tree
Showing 23 changed files with 224 additions and 587 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: run-explorer run-tests run-linters build-ui build-python build-docker run-docker compose-up
version="0.79.0"
version="0.80.0"
run-explorer:
@echo "Running explorer API server..."
# open "http://localhost:8000/static/index.html" || true
Expand Down
2 changes: 1 addition & 1 deletion cognite/neat/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.79.0"
__version__ = "0.80.0"
4 changes: 2 additions & 2 deletions cognite/neat/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .stores import NeatGraphStoreBase
from .stores import NeatGraphStore

__all__ = ["NeatGraphStoreBase"]
__all__ = ["NeatGraphStore"]
5 changes: 5 additions & 0 deletions cognite/neat/graph/_shared.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing import Literal, TypeAlias

MIMETypes: TypeAlias = Literal[
"application/rdf+xml", "text/turtle", "application/n-triple", "application/n-quads", "application/trig"
]
15 changes: 15 additions & 0 deletions cognite/neat/graph/extractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ._classic_cdf._sequences import SequencesExtractor
from ._classic_cdf._timeseries import TimeSeriesExtractor
from ._mock_graph_generator import MockGraphGenerator
from ._rdf_file import RdfFileExtractor

__all__ = [
"AssetsExtractor",
Expand All @@ -16,4 +17,18 @@
"EventsExtractor",
"FilesExtractor",
"LabelsExtractor",
"RdfFileExtractor",
]


TripleExtractors = (
AssetsExtractor
| MockGraphGenerator
| RelationshipsExtractor
| TimeSeriesExtractor
| SequencesExtractor
| EventsExtractor
| FilesExtractor
| LabelsExtractor
| RdfFileExtractor
)
18 changes: 18 additions & 0 deletions cognite/neat/graph/extractors/_rdf_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from pathlib import Path

from rdflib import URIRef

from cognite.neat.graph._shared import MIMETypes
from cognite.neat.graph.extractors._base import BaseExtractor


class RdfFileExtractor(BaseExtractor):
def __init__(
self,
filepath: Path,
mime_type: MIMETypes = "application/rdf+xml",
base_uri: URIRef | None = None,
):
self.filepath = filepath
self.mime_type = mime_type
self.base_uri = base_uri
4 changes: 2 additions & 2 deletions cognite/neat/graph/loaders/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cognite.client import CogniteClient
from cognite.client.data_classes.capabilities import Capability

from cognite.neat.graph import NeatGraphStoreBase
from cognite.neat.graph import NeatGraphStore
from cognite.neat.graph.issues.loader import FailedAuthorizationError
from cognite.neat.issues import NeatIssue, NeatIssueList
from cognite.neat.utils.upload import UploadDiffsID, UploadResultIDs
Expand All @@ -18,7 +18,7 @@ class BaseLoader(ABC, Generic[T_Output]):
_new_line = "\n"
_encoding = "utf-8"

def __init__(self, graph_store: NeatGraphStoreBase):
def __init__(self, graph_store: NeatGraphStore):
self.graph_store = graph_store

@abstractmethod
Expand Down
8 changes: 4 additions & 4 deletions cognite/neat/graph/loaders/_rdf2dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from cognite.neat.graph._tracking import LogTracker, Tracker
from cognite.neat.graph.issues import loader as loader_issues
from cognite.neat.graph.stores import NeatGraphStoreBase
from cognite.neat.graph.stores import NeatGraphStore
from cognite.neat.issues import NeatIssue, NeatIssueList
from cognite.neat.rules.models import DMSRules
from cognite.neat.rules.models.data_types import _DATA_TYPE_BY_DMS_TYPE
Expand All @@ -29,7 +29,7 @@
class DMSLoader(CDFLoader[dm.InstanceApply]):
def __init__(
self,
graph_store: NeatGraphStoreBase,
graph_store: NeatGraphStore,
data_model: dm.DataModel[dm.View] | None,
instance_space: str,
class_by_view_id: dict[ViewId, str] | None = None,
Expand All @@ -48,7 +48,7 @@ def from_data_model_id(
cls,
client: CogniteClient,
data_model_id: dm.DataModelId,
graph_store: NeatGraphStoreBase,
graph_store: NeatGraphStore,
instance_space: str,
) -> "DMSLoader":
issues: list[NeatIssue] = []
Expand All @@ -61,7 +61,7 @@ def from_data_model_id(
return cls(graph_store, data_model, instance_space, {}, issues)

@classmethod
def from_rules(cls, rules: DMSRules, graph_store: NeatGraphStoreBase, instance_space: str) -> "DMSLoader":
def from_rules(cls, rules: DMSRules, graph_store: NeatGraphStore, instance_space: str) -> "DMSLoader":
issues: list[NeatIssue] = []
data_model: dm.DataModel[dm.View] | None = None
try:
Expand Down
14 changes: 2 additions & 12 deletions cognite/neat/graph/stores/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
from ._base import NeatGraphStoreBase
from ._graphdb_store import GraphDBStore
from ._memory_store import MemoryStore
from ._oxigraph_store import OxiGraphStore
from ._base import NeatGraphStore

STORE_BY_TYPE: dict[str, type[NeatGraphStoreBase]] = {}
for store in NeatGraphStoreBase.__subclasses__():
STORE_BY_TYPE[store.rdf_store_type] = store # type: ignore[type-abstract]

del store # Cleanup namespace
AVAILABLE_STORES = set(STORE_BY_TYPE.keys())

__all__ = ["NeatGraphStoreBase", "MemoryStore", "OxiGraphStore", "GraphDBStore", "STORE_BY_TYPE", "AVAILABLE_STORES"]
__all__ = ["NeatGraphStore"]
Loading

0 comments on commit 251e585

Please sign in to comment.