diff --git a/.github/workflows/qc.yml b/.github/workflows/qc.yml index 9d8114cb..78c7307d 100644 --- a/.github/workflows/qc.yml +++ b/.github/workflows/qc.yml @@ -33,7 +33,9 @@ jobs: # install your root project, if required #---------------------------------------------- - name: Install library - run: poetry install --no-interaction + run: | + pip install -U poetry + poetry install --no-interaction #---------------------------------------------- # run pytest diff --git a/src/kgcl_schema/grammar/parser.py b/src/kgcl_schema/grammar/parser.py index 9cd645dc..8e8066d2 100644 --- a/src/kgcl_schema/grammar/parser.py +++ b/src/kgcl_schema/grammar/parser.py @@ -11,8 +11,8 @@ EdgeDeletion, NewSynonym, NodeAnnotationChange, NodeCreation, NodeDeepening, NodeDeletion, NodeMove, - NodeObsoletion, NodeRename, - NodeShallowing, NodeUnobsoletion, + NodeObsoletion, NodeObsoletionWithDirectReplacement, + NodeRename, NodeShallowing, NodeUnobsoletion, PlaceUnder, PredicateChange, RemovedNodeFromSubset, RemoveUnder, Session) @@ -452,13 +452,19 @@ def parse_obsolete(tree, id): entity, representation = get_entity_representation(entity_token) replacement_token = extract(tree, "replacement") - - return NodeObsoletion( - id=id, - about_node=entity, - about_node_representation=representation, - has_direct_replacement=replacement_token, - ) + if replacement_token: + return NodeObsoletionWithDirectReplacement( + id=id, + about_node=entity, + about_node_representation=representation, + has_direct_replacement=replacement_token, + ) + else: + return NodeObsoletion( + id=id, + about_node=entity, + about_node_representation=representation + ) def parse_rename(tree, id): diff --git a/src/kgcl_schema/grammar/render_operations.py b/src/kgcl_schema/grammar/render_operations.py index b98032ef..17c795db 100644 --- a/src/kgcl_schema/grammar/render_operations.py +++ b/src/kgcl_schema/grammar/render_operations.py @@ -3,7 +3,7 @@ from kgcl_schema.datamodel.kgcl import (ClassCreation, EdgeCreation, EdgeDeletion, NewSynonym, NodeAnnotationChange, NodeCreation, NodeDeepening, - NodeDeletion, NodeMove, NodeObsoletion, + NodeDeletion, NodeMove, NodeObsoletion, NodeObsoletionWithDirectReplacement, NodeRename, NodeUnobsoletion, PlaceUnder, PredicateChange, RemoveUnder, Change) from lark.lexer import Token @@ -102,7 +102,7 @@ def render(kgcl_instance: Change) -> str: + new_object ) - if type(kgcl_instance) is NodeObsoletion: + if type(kgcl_instance) is NodeObsoletion or type(kgcl_instance) is NodeObsoletionWithDirectReplacement: subject = render_entity(kgcl_instance.about_node, "uri") # TODO: type this correctly replacement = render_entity(kgcl_instance.has_direct_replacement, "uri") diff --git a/tests/cases.py b/tests/cases.py index 5ab02fcb..0aec6460 100644 --- a/tests/cases.py +++ b/tests/cases.py @@ -1,6 +1,6 @@ from typing import Tuple, Optional, List, Union -from kgcl_schema.datamodel.kgcl import NodeRename, NodeObsoletion, NewSynonym, ClassCreation, PredicateChange, Change, \ +from kgcl_schema.datamodel.kgcl import NodeObsoletionWithDirectReplacement, NodeRename, NodeObsoletion, NewSynonym, ClassCreation, PredicateChange, Change, \ NodeCreation, EdgeCreation, PlaceUnder, RemoveUnder, EdgeDeletion, NodeDeepening from kgcl_schema.datamodel.ontology_model import Edge @@ -85,7 +85,7 @@ ( f"obsolete {NUCLEUS} with replacement {TERM2}", None, - NodeObsoletion(id=UID, + NodeObsoletionWithDirectReplacement(id=UID, about_node=NUCLEUS, about_node_representation='curie', has_direct_replacement=TERM2),