Skip to content

Commit

Permalink
Definitions should be enclosed in double quotes while updating via KG…
Browse files Browse the repository at this point in the history
…CL (#520)

* Definitions should be enclosed in double quotes

* not needed

* fixed definition to have double quotes

* moved adding of quotes

* reverted back to earlier solution

* reverted everything

* formatted and commented

* removed comment

* rolled back

* removed unnecessary strip()

* def double quotes while writing

* undo line break

* no need for double quote hardcoding

* removing `def` specific code

* remove single quotes from definition

* Adding double quotes to new defs

* strip single quotes

* bumped setup-python version
  • Loading branch information
hrshdhgd authored Apr 12, 2023
1 parent c1d4f55 commit 600fcf6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

Expand Down
4 changes: 4 additions & 0 deletions src/oaklib/implementations/pronto/pronto_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,10 @@ def apply_patch(
for syn in t.synonyms:
if syn.description == patch.old_value:
syn.description = patch.new_value
elif isinstance(patch, kgcl.NewTextDefinition):
t = self._entity(patch.about_node, strict=True)
xrefs = t.definition.xrefs if t.definition else []
t.definition = pronto.Definition(patch.new_value, xrefs=xrefs)
elif isinstance(patch, kgcl.NodeTextDefinitionChange):
t = self._entity(patch.about_node, strict=True)
xrefs = t.definition.xrefs if t.definition else []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,12 +802,13 @@ def apply_patch(
modified_entities.append(patch.about_node)
elif isinstance(patch, kgcl.NewTextDefinition):
t = self._stanza(patch.about_node, strict=True)
t.add_tag_value(TAG_DEFINITION, patch.new_value)
t.add_quoted_tag_value(TAG_DEFINITION, patch.new_value.strip("'"), xrefs=[])
modified_entities.append(patch.about_node)
elif isinstance(patch, kgcl.NodeTextDefinitionChange):
t = self._stanza(patch.about_node, strict=True)
for tv in t.tag_values:
if tv.tag == TAG_DEFINITION:
# The strip() portion is to handle a KGCL bug
tv.replace_quoted_part(patch.new_value.strip("'"))
elif isinstance(patch, kgcl.NewSynonym):
t = self._stanza(patch.about_node, strict=True)
Expand Down
10 changes: 10 additions & 0 deletions src/oaklib/implementations/simpleobo/simple_obo_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@ def add_tag_value(self, tag: TAG, val: str) -> None:
"""
self.tag_values.append(TagValue(tag, val))

def add_quoted_tag_value(self, tag: TAG, val: str, xrefs: List[str]) -> None:
"""
Adds a tag-value pair
:param tag:
:param val:
:return:
"""
self.tag_values.append(TagValue(tag, f"\"{val}\" [{','.join(xrefs)}]"))

def add_tag_value_pair(self, tag: TAG, val1: str, val2: str) -> None:
"""
Adds a tag-value pair where the value is a pair
Expand Down

0 comments on commit 600fcf6

Please sign in to comment.