Skip to content

Commit

Permalink
Merge pull request #26 from INCATools/add-definition
Browse files Browse the repository at this point in the history
Add `NewTextDefinition`
  • Loading branch information
hrshdhgd authored Apr 4, 2023
2 parents 29eaa00 + 5d46744 commit 2b07913
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/data/examples/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ Test_15:
new_object_type: curie
command_with_curie: deepen GO:0005739 from GO:0043231 to GO:0005634
command_with_uri: TODO
Test_16:
id: CHANGE:001
type: NewTextDefinition
new_value: '''this is dummy description'''
about_node: GO:0005635
about_node_representation: curie
command_with_curie: add definition 'this is dummy description' to GO:0005635
command_with_uri: add definition 'this is dummy description' to http://purl.obolibrary.org/obo/GO_0005635
9 changes: 9 additions & 0 deletions src/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ old_object_type: curie
new_object_type: curie
```
## Example: New definition of a node.
Class: [`NewTextDefinition`](https://w3id.org/kgcl/NewTextDefinition) </br></br>Command: `add definition 'this is dummy description' to GO:0005635`</br></br>YAML:
```
id: CHANGE:001
new_value: this is dummy description
about_node: GO:0005635
about_node_representation: curie
```
3 changes: 3 additions & 0 deletions src/kgcl_schema/grammar/kgcl.lark
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
| remove_synonym
| remove_from_subset
| add_to_subset
| add_definition

rename : "rename" _WS [id _WS "from" _WS] old_label ["@" old_language] _WS ("to"|"as"|"->") _WS new_label ["@" new_language]

Expand Down Expand Up @@ -45,6 +46,7 @@ change_relationship: "change relationship between" _WS entity_subject _WS "and"

change_annotation: "change annotation of" _WS entity_subject _WS "with" _WS entity_predicate _WS "from" _WS old_entity_object _WS "to" _WS new_entity_object

add_definition: "add definition" _WS definition _WS "to" _WS entity

remove_from_subset : "remove" _WS id _WS "from subset" _WS subset
add_to_subset : "add" _WS id _WS "to subset" _WS subset
Expand All @@ -64,6 +66,7 @@ filler: _entity
label : SINGLE_QUOTE_LITERAL
old_label : SINGLE_QUOTE_LITERAL
new_label : SINGLE_QUOTE_LITERAL
definition : SINGLE_QUOTE_LITERAL

language: LANGUAGE_TAG
old_language : LANGUAGE_TAG
Expand Down
16 changes: 16 additions & 0 deletions src/kgcl_schema/grammar/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
EdgeCreation,
EdgeDeletion,
NewSynonym,
NewTextDefinition,
NodeAnnotationChange,
NodeCreation,
NodeDeepening,
Expand Down Expand Up @@ -119,6 +120,8 @@ def parse_statement(input: str) -> Change:
return parse_remove_from_subset(tree, id)
elif command == "remove_synonym":
return parse_remove_synonym(tree, id)
elif command == "add_definition":
return parse_add_definition(tree, id)
else:
raise NotImplementedError("No implementation for KGCL command: " + command)

Expand Down Expand Up @@ -208,6 +211,19 @@ def parse_create_class(tree, id):
)


def parse_add_definition(tree, id):
"""Add definition to class."""
entity_token = extract(tree, "entity")
new_value = extract(tree, "definition")
entity, representation = get_entity_representation(entity_token)
return NewTextDefinition(
id=id,
about_node=entity,
about_node_representation=representation,
new_value=new_value,
)


# the KGCL model suggests the command
# 'create node {id} {label} with {annotation set}'
# TODO: handling of {annotation set}
Expand Down
6 changes: 6 additions & 0 deletions src/kgcl_schema/grammar/render_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
EdgeCreation,
EdgeDeletion,
NewSynonym,
NewTextDefinition,
NodeAnnotationChange,
NodeCreation,
NodeDeepening,
Expand Down Expand Up @@ -256,3 +257,8 @@ def render(kgcl_instance: Change) -> str:
old_value = kgcl_instance.old_value
new_value = kgcl_instance.new_value
return "deepen " + subject + " from " + old_value + " to " + new_value

if type(kgcl_instance) is NewTextDefinition:
subject = kgcl_instance.about_node
definition = kgcl_instance.new_value
return "add definition " + definition + " to " + subject
12 changes: 12 additions & 0 deletions tests/cases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Tuple, Optional, List, Union

from kgcl_schema.datamodel.kgcl import (
NewTextDefinition,
NodeObsoletionWithDirectReplacement,
NodeRename,
NodeObsoletion,
Expand Down Expand Up @@ -293,4 +294,15 @@
),
None,
),
(
f"add definition 'this is dummy description' to {NUCLEAR_ENVELOPE}",
f"add definition 'this is dummy description' to {NUCLEAR_ENVELOPE_URI}",
NewTextDefinition(
id=UID,
new_value="'this is dummy description'",
about_node="GO:0005635",
about_node_representation="curie",
),
None,
),
]
1 change: 1 addition & 0 deletions tests/test_case_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"RemoveUnder": "Remove node from under another node.",
"EdgeDeletion": "Deletion of an edge.",
"NodeDeepening": "Deepening of a node.",
"NewTextDefinition": "New definition of a node.",
}


Expand Down

0 comments on commit 2b07913

Please sign in to comment.