Skip to content

Commit

Permalink
Introducing Legacy (#407)
Browse files Browse the repository at this point in the history
## [0.75.0] - 23-05-24
### Added
- Added and moved all v1 rules related code base under `legacy` module
  • Loading branch information
nikokaoja committed Apr 23, 2024
1 parent b7f3c9b commit 6fa0489
Show file tree
Hide file tree
Showing 209 changed files with 47,030 additions and 855 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: run-explorer run-tests run-linters build-ui build-python build-docker run-docker compose-up

version="0.74.0"
version="0.75.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.74.0"
__version__ = "0.75.0"
3 changes: 1 addition & 2 deletions cognite/neat/app/api/routers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from cognite.neat.app.api.configuration import NEAT_APP
from cognite.neat.rules import exporters, importers
from cognite.neat.rules.models._rules import DMSRules
from cognite.neat.rules.models._rules.base import RoleTypes
from cognite.neat.rules.models.rules import DMSRules, RoleTypes

router = APIRouter()

Expand Down
2 changes: 1 addition & 1 deletion cognite/neat/app/api/routers/data_exploration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
from cognite.neat.app.api.utils.data_mapping import rdf_result_to_api_response
from cognite.neat.app.api.utils.query_templates import query_templates
from cognite.neat.graph.transformation import query_generator
from cognite.neat.legacy.graph.transformations import query_generator
from cognite.neat.utils.utils import remove_namespace
from cognite.neat.workflows.steps.data_contracts import RulesData, SolutionGraph, SourceGraph

Expand Down
20 changes: 13 additions & 7 deletions cognite/neat/app/api/routers/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

from cognite.neat.app.api.configuration import NEAT_APP
from cognite.neat.app.api.data_classes.rest import TransformationRulesUpdateRequest
from cognite.neat.rules import exporter, importer, importers
from cognite.neat.rules.models._base import EntityTypes
from cognite.neat.rules.models._rules.base import RoleTypes
from cognite.neat.rules.models.rules import Class, Classes, Metadata, Properties, Property, Rules
from cognite.neat.legacy.rules import exporters as legacy_exporters
from cognite.neat.legacy.rules import importers as legacy_importers
from cognite.neat.legacy.rules.models._base import EntityTypes
from cognite.neat.legacy.rules.models.rules import Class, Classes, Metadata, Properties, Property, Rules
from cognite.neat.rules import importers
from cognite.neat.rules.models.rules import RoleTypes
from cognite.neat.workflows.steps.data_contracts import RulesData
from cognite.neat.workflows.steps.lib.rules_exporter import RulesToExcel
from cognite.neat.workflows.steps.lib.rules_importer import ExcelToRules
Expand Down Expand Up @@ -90,7 +92,9 @@ def get_rules(
try:
# Trying to load rules V1
if rules_schema_version == "" or rules_schema_version == "v1":
rules = cast(Rules, importer.ExcelImporter(path).to_rules(return_report=False, skip_validation=False))
rules = cast(
Rules, legacy_importers.ExcelImporter(path).to_rules(return_report=False, skip_validation=False)
)
properties = [
{
"class": value.class_id,
Expand Down Expand Up @@ -148,7 +152,9 @@ def get_rules(
def get_original_rules_from_file(file_name: str):
# """Endpoint for retrieving raw transformation from file"""
path = Path(NEAT_APP.config.rules_store_path) / file_name
rules = cast(Rules, importer.ExcelImporter(filepath=path).to_rules(return_report=False, skip_validation=False))
rules = cast(
Rules, legacy_importers.ExcelImporter(filepath=path).to_rules(return_report=False, skip_validation=False)
)
return Response(content=rules.model_dump_json(), media_type="application/json")


Expand Down Expand Up @@ -193,5 +199,5 @@ def upsert_rules(request: TransformationRulesUpdateRequest):
else:
path = Path(NEAT_APP.config.data_store_path) / rules_file

exporter.ExcelExporter(rules=rules).export_to_file(path)
legacy_exporters.ExcelExporter(rules=rules).export_to_file(path)
return {"status": "ok"}
4 changes: 2 additions & 2 deletions cognite/neat/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
PACKAGE_DIRECTORY = Path(neat.__file__).parent


EXAMPLE_RULES = PACKAGE_DIRECTORY / "rules" / "examples"
EXAMPLE_GRAPHS = PACKAGE_DIRECTORY / "graph" / "examples"
EXAMPLE_RULES = PACKAGE_DIRECTORY / "legacy" / "rules" / "examples"
EXAMPLE_GRAPHS = PACKAGE_DIRECTORY / "legacy" / "graph" / "examples"
EXAMPLE_WORKFLOWS = PACKAGE_DIRECTORY / "workflows" / "examples"

DEFAULT_NAMESPACE = Namespace("http://purl.org/cognite/neat#")
Expand Down
8 changes: 4 additions & 4 deletions cognite/neat/graph/extractors/_mock_graph_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from rdflib import RDF, Literal, Namespace, URIRef

from cognite.neat.graph.models import Triple
from cognite.neat.rules._analysis._information_rules import InformationArchitectRulesAnalysis
from cognite.neat.rules.models._rules import DMSRules, InformationRules
from cognite.neat.rules.models._rules._types import ClassEntity, EntityTypes, XSDValueType
from cognite.neat.rules.models._rules.information_rules import InformationProperty
from cognite.neat.rules.analysis import InformationArchitectRulesAnalysis
from cognite.neat.rules.models.rules import DMSRules, InformationRules
from cognite.neat.rules.models.rules._information_rules import InformationProperty
from cognite.neat.rules.models.rules._types import ClassEntity, EntityTypes, XSDValueType
from cognite.neat.utils.utils import remove_namespace

from ._base import BaseExtractor
Expand Down
25 changes: 2 additions & 23 deletions cognite/neat/graph/stores/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
from cognite.neat.constants import DEFAULT_NAMESPACE, PREFIXES
from cognite.neat.graph.models import Triple
from cognite.neat.graph.stores._rdf_to_graph import rdf_file_to_graph
from cognite.neat.rules.models.rules import Rules

if sys.version_info >= (3, 11):
from typing import Self
pass
else:
from typing_extensions import Self
pass

prom_qsm = Summary("store_query_time_summary", "Time spent processing queries", ["query"])
prom_sq = Gauge("store_single_query_time", "Time spent processing a single query", ["query"])
Expand Down Expand Up @@ -64,26 +63,6 @@ def __init__(
self.storage_dirs_to_delete: list[Path] = []
self.queries = _Queries(self)

@classmethod
def from_rules(cls, rules: Rules) -> Self:
"""
Creates a new instance of NeatGraphStore from TransformationRules and runs the .init_graph() method on it.
Args:
rules: TransformationRules object containing information about the graph store.
Returns:
An instantiated instance of NeatGraphStore
"""
if rules.metadata.namespace is None:
namespace = DEFAULT_NAMESPACE
else:
namespace = rules.metadata.namespace
store = cls(prefixes=rules.prefixes, namespace=namespace)
store.init_graph(base_prefix=rules.metadata.prefix)
return store

@abstractmethod
def _set_graph(self) -> None:
raise NotImplementedError()
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions cognite/neat/legacy/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .stores import NeatGraphStoreBase

__all__ = ["NeatGraphStoreBase"]
Loading

0 comments on commit 6fa0489

Please sign in to comment.