Skip to content

Commit

Permalink
Added replacement to parse while node obsoletion. (#15)
Browse files Browse the repository at this point in the history
* Added replacement to parse while node obsoletion.

* corrected tests

* test install again due to Windows error on gh
  • Loading branch information
hrshdhgd authored Oct 27, 2022
1 parent ab3d997 commit 13cf4a5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/qc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions src/kgcl_schema/grammar/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions src/kgcl_schema/grammar/render_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/cases.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 13cf4a5

Please sign in to comment.