Skip to content

Commit

Permalink
Merge pull request #1002 from ge-high-assurance/vr/migration-v13
Browse files Browse the repository at this point in the history
migration: v13 changes
  • Loading branch information
Ptival authored Sep 5, 2023
2 parents 988bc06 + 771bf70 commit 1f32e14
Show file tree
Hide file tree
Showing 13 changed files with 1,335 additions and 5 deletions.
41 changes: 41 additions & 0 deletions migration/migration_helpers/create_class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

# Copyright (c) 2023, Galois, Inc.
#
# All Rights Reserved
#
# This material is based upon work supported by the Defense Advanced Research
# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203.
#
# Any opinions, findings and conclusions or recommendations expressed in this
# material are those of the author(s) and do not necessarily reflect the views
# of the Defense Advanced Research Projects Agency (DARPA).

from typing import List

from migration_helpers.name_space import NameSpace
from ontology_changes import (
AddClassIsATypeOf,
CreateClass,
)
from ontology_changes.cardinality import Cardinality
from ontology_changes.ontology_change import OntologyChange
from ontology_changes.range_restriction import RangeRestriction

def create_class_with_type_of(
namespace: NameSpace,
class_id: str,
type_of_namespace: NameSpace,
type_of_class: str,
) -> List[OntologyChange]:
return [
CreateClass(
name_space=namespace,
class_id=class_id,
),
AddClassIsATypeOf(
name_space=namespace,
class_id=class_id,
range_name_space=type_of_namespace,
range_id=type_of_class,
),
]
51 changes: 51 additions & 0 deletions migration/migration_helpers/create_property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2023, Galois, Inc.
#
# All Rights Reserved
#
# This material is based upon work supported by the Defense Advanced Research
# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203.
#
# Any opinions, findings and conclusions or recommendations expressed in this
# material are those of the author(s) and do not necessarily reflect the views
# of the Defense Advanced Research Projects Agency (DARPA).

from typing import List, List

from migration_helpers.name_space import NameSpace
from ontology_changes import (
AddRangeRestriction,
ChangeCardinality,
CreateProperty,
)
from ontology_changes.cardinality import Cardinality
from ontology_changes.ontology_change import OntologyChange
from ontology_changes.range_restriction import RangeRestriction

def create_property_with_cardinality_and_range(
namespace: NameSpace,
class_id: str,
property_id: str,
range: RangeRestriction,
cardinality: Cardinality,
) -> List[OntologyChange]:
return [
CreateProperty(
name_space=namespace,
class_id=class_id,
property_id=property_id,
),
AddRangeRestriction(
domain_name_space=namespace,
domain_class=class_id,
prop_name_space=namespace,
prop_name=property_id,
restriction=range,
),
ChangeCardinality(
name_space=namespace,
class_id=class_id,
property_id=property_id,
to_cardinality=cardinality,
),

]
49 changes: 49 additions & 0 deletions migration/migration_helpers/relocate_class_and_properties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (c) 2023, Galois, Inc.
#
# All Rights Reserved
#
# This material is based upon work supported by the Defense Advanced Research
# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203.
#
# Any opinions, findings and conclusions or recommendations expressed in this
# material are those of the author(s) and do not necessarily reflect the views
# of the Defense Advanced Research Projects Agency (DARPA).

from typing import List

from migration_helpers.name_space import NameSpace
from ontology_changes import (
RenameClass,
RenameProperty,
)
from ontology_changes.ontology_change import OntologyChange


def relocate_class_and_properties(
from_namespace: NameSpace,
to_namespace: NameSpace,
class_id: str,
properties: List[str],
) -> List[OntologyChange]:
# Explicit type ascriptions to circumvent the fact that List is not
# covariant
rename_class: List[OntologyChange] = [
RenameClass(
from_name_space=from_namespace,
from_name=class_id,
to_name_space=to_namespace,
to_name=class_id,
)
]
rename_properties: List[OntologyChange] = [
RenameProperty(
from_name_space=from_namespace,
from_class=class_id,
from_name=property_id,
to_name_space=to_namespace,
to_class=class_id,
to_name=property_id,
)
for property_id in properties
]
return rename_class + rename_properties
4 changes: 2 additions & 2 deletions migration/ontology_changes/ontology_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dataclasses import dataclass
import logging
from abc import ABC, abstractmethod
from typing import List, Optional
from typing import Optional, Sequence

from colorama import Fore, Style
from semtk import SemTKJSON
Expand Down Expand Up @@ -124,6 +124,6 @@ def migrate_json(self, json: SemTKJSON) -> None:

@dataclass
class Commit:
changes: List[OntologyChange]
changes: Sequence[OntologyChange]
number: str
tag: Optional[str] = None
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def delete_property_from_node_list(
for sparqlID in node.SnodeSparqlIDs:
if json.importSpec is None:
continue
field = stylize_json("sparqlID")
for index, importSpecNode in enumerate(json.importSpec.nodes):
if importSpecNode.sparqlID == sparqlID:
field = stylize_json("sparqlID")
log_additional_deletion(
f"importSpec.nodes[{index}]",
f"it has {field} = {sparqlID}",
Expand Down
15 changes: 14 additions & 1 deletion migration/rack/commits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ontology_changes.ontology_change import Commit
from rack.commits import (
# <CHANGE_CRAWLER_IMPORTS> DO NOT EDIT OR MOVE THIS LINE
commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6,
commit05a03cd687e3bdce425794763e0957d3ccaf8ff0,
commit096749fb6a984d801d9ace5ccf5ec269de390a66,
commit09962dd9ab9d252639d9e4324288fd6b47cbd91f,
Expand Down Expand Up @@ -81,9 +82,13 @@
commitc6692fed3e150e7df53d4a2a8f8c84f760087420,
commitcafce30763b5332106340cc8cbeb8fdac3b8132d,
commitd48e208669c589d070c7c5fb7e3129ababbb9193,
commitd497287426ac99acffbd51858ebf4722af06dae2,
commitd8271d216704351cf0007a04abac47f4abc993ad,
commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8,
commitdf67562c4e5305fc9082fc369570de0a49089ccf,
commite18de6ebaa298881aab7e8e69580905ffb97e0c4,
commite454889c706f02818f4badc3360a3c068fa014a0,
commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b,
commite5e8a35322fab104a42cc0f46d16c27ffc10adbb,
commite696969a9d85ca8f894eea12305412bdc05521b3,
commiteb2f51ed862f33d2a56bbd6d43af27d9524912c9,
Expand All @@ -107,7 +112,6 @@

commits_in_chronological_order: List[Commit] = [
# <CHANGE_CRAWLER_COMMITS> DO NOT EDIT OR MOVE THIS LINE

# oldest (in history)

commita9210534a2ceb9ea5595df9eb5cd02df3abe3cb3.commit, # v4.0
Expand Down Expand Up @@ -212,6 +216,15 @@
commit8a01ff1b53e0b4979f0120a362b8fd3776a6586c.commit, # 2023 Jan 10
commit96c4d5d8672bbb8e8b5ff44ea928638092f91b82.commit, # 2023 Feb 21

commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b.commit, # v12.0

commitd497287426ac99acffbd51858ebf4722af06dae2.commit, # 2023 Apr 11
commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6.commit, # 2023 May 01
commite454889c706f02818f4badc3360a3c068fa014a0.commit, # 2023 May 02
commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.commit, # 2023 May 12

# commit???.commit, # v13

# most recent (in history)
]

Expand Down
Loading

0 comments on commit 1f32e14

Please sign in to comment.