Skip to content

Commit

Permalink
Merge pull request #25 from INCATools/remove-synonym
Browse files Browse the repository at this point in the history
Remove synonym
  • Loading branch information
hrshdhgd authored Mar 31, 2023
2 parents 720ec8b + beff479 commit 29eaa00
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/data/examples/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,21 @@ Test_5:
command_with_curie: create broad synonym 'foo'@en for GO:0005634
command_with_uri: create broad synonym 'foo'@en for http://purl.obolibrary.org/obo/GO_0005634
Test_6:
id: CHANGE:001
type: RemoveSynonym
old_value: foo
about_node: GO:0005634
about_node_representation: curie
command_with_curie: remove synonym 'foo' for GO:0005634
command_with_uri: remove synonym 'foo' for http://purl.obolibrary.org/obo/GO_0005634
Test_7:
id: CHANGE:001
type: ClassCreation
about_node_representation: curie
node_id: GO:9999999
command_with_curie: create GO:9999999
command_with_uri: create http://purl.obolibrary.org/obo/GO_9999999
Test_7:
Test_8:
id: CHANGE:001
type: NodeCreation
about_node: GO:9999999
Expand All @@ -66,7 +74,7 @@ Test_7:
name: '''foo'''
command_with_curie: create node GO:9999999 'foo'
command_with_uri: TODO
Test_8:
Test_9:
id: CHANGE:001
type: EdgeCreation
object_type: curie
Expand All @@ -78,7 +86,7 @@ Test_8:
command_with_curie: create edge GO:0005634 BFO:0000050 GO:0009411
command_with_uri: create edge http://purl.obolibrary.org/obo/GO_0005634 http://purl.obolibrary.org/obo/BFO_0000050
http://purl.obolibrary.org/obo/GO_0009411
Test_9:
Test_10:
id: CHANGE:001
type: PlaceUnder
object_type: curie
Expand All @@ -90,7 +98,7 @@ Test_9:
command_with_curie: create edge GO:0005634 rdfs:subClassOf GO:0009411
command_with_uri: create edge http://purl.obolibrary.org/obo/GO_0005634 http://www.w3.org/2000/01/rdf-schema#subClassOf
http://purl.obolibrary.org/obo/GO_0009411
Test_10:
Test_11:
id: CHANGE:001
type: PredicateChange
old_value: BFO:0000050
Expand All @@ -106,7 +114,7 @@ Test_10:
object_representation: curie
command_with_curie: change relationship between GO:0005635 and GO:0005634 from BFO:0000050
to rdfs:subClassOf
Test_11:
Test_12:
id: CHANGE:001
type: PredicateChange
old_value: rdfs:subClassOf
Expand All @@ -125,7 +133,7 @@ Test_11:
command_with_uri: change relationship between http://purl.obolibrary.org/obo/GO_0005634
and http://purl.obolibrary.org/obo/GO_0043231 from http://www.w3.org/2000/01/rdf-schema#subClassOf
to http://purl.obolibrary.org/obo/BFO_0000050
Test_12:
Test_13:
id: CHANGE:001
type: RemoveUnder
object_type: curie
Expand All @@ -137,7 +145,7 @@ Test_12:
command_with_curie: delete edge GO:0005634 rdfs:subClassOf GO:0043231
command_with_uri: delete edge http://purl.obolibrary.org/obo/GO_0005634 http://www.w3.org/2000/01/rdf-schema#subClassOf
http://purl.obolibrary.org/obo/GO_0043231
Test_13:
Test_14:
id: CHANGE:001
type: EdgeDeletion
object_type: curie
Expand All @@ -148,7 +156,7 @@ Test_13:
predicate_type: curie
command_with_curie: delete edge GO:0005635 BFO:0000050 GO:0005634
command_with_uri: TODO
Test_14:
Test_15:
id: CHANGE:001
type: NodeDeepening
old_value: GO:0043231
Expand Down
9 changes: 9 additions & 0 deletions src/docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ about_node: GO:0005634
about_node_representation: curie
qualifier: exact
```
## Example: Removal of a synonym.
Class: [`RemoveSynonym`](https://w3id.org/kgcl/RemoveSynonym) </br></br>Command: `remove synonym 'foo' for GO:0005634`</br></br>YAML:
```
id: CHANGE:001
old_value: foo
about_node: GO:0005634
about_node_representation: curie
```
## Example: Creation of new class.
Class: [`ClassCreation`](https://w3id.org/kgcl/ClassCreation) </br></br>Command: `create GO:9999999`</br></br>YAML:
Expand Down
3 changes: 3 additions & 0 deletions src/kgcl_schema/grammar/kgcl.lark
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
| create_edge
| delete_edge
| create_synonym
| remove_synonym
| remove_from_subset
| add_to_subset

Expand All @@ -23,6 +24,8 @@ create_class: "create" _WS id
create_synonym: "create" _WS [synonym_qualifier _WS] "synonym" _WS synonym ["@" language] _WS "for" _WS entity
synonym_qualifier : /exact|narrow|broad|related/

remove_synonym: "remove" _WS "synonym" _WS synonym ["@" language] _WS "for" _WS entity

delete : "delete" _WS entity

obsolete : "obsolete" _WS entity
Expand Down
24 changes: 24 additions & 0 deletions src/kgcl_schema/grammar/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
NodeUnobsoletion,
PlaceUnder,
PredicateChange,
RemoveSynonym,
RemovedNodeFromSubset,
RemoveUnder,
Session,
Expand Down Expand Up @@ -116,6 +117,8 @@ def parse_statement(input: str) -> Change:
return parse_create_synonym(tree, id)
elif command == "remove_from_subset":
return parse_remove_from_subset(tree, id)
elif command == "remove_synonym":
return parse_remove_synonym(tree, id)
else:
raise NotImplementedError("No implementation for KGCL command: " + command)

Expand Down Expand Up @@ -174,6 +177,27 @@ def parse_create_synonym(tree, id):
)


def parse_remove_synonym(tree, id):
"""Remove a synonym."""
entity_token = extract(tree, "entity")
entity, representation = get_entity_representation(entity_token)

synonym_string_token = extract(tree, "synonym")
synonym, _ = get_entity_representation(synonym_string_token)

language_token = extract(tree, "language")
# qualifier_token = extract(tree, "synonym_qualifier")

return RemoveSynonym(
id=id,
old_value=synonym,
about_node=entity,
about_node_representation=representation,
# qualifier=qualifier_token,
language=language_token,
)


def parse_create_class(tree, id):
"""Create new class."""
term_id_token = extract(tree, "id")
Expand Down
17 changes: 17 additions & 0 deletions src/kgcl_schema/grammar/render_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
NodeUnobsoletion,
PlaceUnder,
PredicateChange,
RemoveSynonym,
RemoveUnder,
Change,
)
Expand Down Expand Up @@ -209,6 +210,22 @@ def render(kgcl_instance: Change) -> str:
else:
return "create synonym " + synonym + " for " + subject

if type(kgcl_instance) is RemoveSynonym:
subject = render_entity(kgcl_instance.about_node, "uri")
synonym = render_entity(kgcl_instance.old_value, "label")
# qualifier = kgcl_instance.qualifier
language = kgcl_instance.language

if language is not None:
synonym = synonym + "@" + language

# if qualifier is not None:
# return (
# "remove " + qualifier + " synonym" + " " + synonym + " for " + subject
# )
# else:
return "remove synonym " + synonym + " for " + subject

if type(kgcl_instance) is PlaceUnder:
subclass = render_entity(kgcl_instance.subject, "uri")
superclass = render_entity(kgcl_instance.object, "uri")
Expand Down
12 changes: 12 additions & 0 deletions tests/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
NodeCreation,
EdgeCreation,
PlaceUnder,
RemoveSynonym,
RemoveUnder,
EdgeDeletion,
NodeDeepening,
Expand Down Expand Up @@ -131,6 +132,17 @@
),
None,
),
(
f"remove synonym 'foo' for {NUCLEUS}",
f"remove synonym 'foo' for {NUCLEUS_URI}",
RemoveSynonym(
id=UID,
about_node=NUCLEUS,
about_node_representation="curie",
old_value="foo",
),
None,
),
(
f"create {NEW_TERM}",
f"create {NEW_TERM_URI}",
Expand Down
1 change: 1 addition & 0 deletions tests/test_case_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"NodeRename": "Rename node.",
"NodeObsoletion": "Obsolete node.",
"NewSynonym": "Addition of a new synonym.",
"RemoveSynonym": "Removal of a synonym.",
"ClassCreation": "Creation of new class.",
"PredicateChange": "Change predicate.",
"Change": "Change node.",
Expand Down

0 comments on commit 29eaa00

Please sign in to comment.