Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checks if synonym val exists before access #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matentzn
Copy link

The current obographs serialiser creates

{
      "id" : "http://purl.obolibrary.org/obo/OBA_2050220",
      "lbl" : "vascular cell adhesion protein 1 amount",
      "type" : "CLASS",
      "meta" : {
        "definition" : {
          "val" : "The amount of a vascular cell adhesion protein 1 when measured in anatomical entity.",
          "xrefs" : [ "AUTO:patterns/patterns/entity_attribute_location" ]
        },
        "synonyms" : [ {
          "pred" : "hasExactSynonym"
        }]
      }
    }

So we need to check if the value exists before accessing it to not fail hard.

This is not tested.

The current obographs serialiser creates

```
{
      "id" : "http://purl.obolibrary.org/obo/OBA_2050220",
      "lbl" : "vascular cell adhesion protein 1 amount",
      "type" : "CLASS",
      "meta" : {
        "definition" : {
          "val" : "The amount of a vascular cell adhesion protein 1 when measured in anatomical entity.",
          "xrefs" : [ "AUTO:patterns/patterns/entity_attribute_location" ]
        },
        "synonyms" : [ {
          "pred" : "hasExactSynonym"
        }]
      }
    }
```

So we need to check if the value exists before accessing it to not fail hard.

This is not tested.
Copy link
Contributor

@cmungall cmungall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course we should use the pydantic from the linkml

@@ -333,7 +333,7 @@ def parse_meta(self, node: str, meta: Dict) -> Dict:

if "synonyms" in meta:
# parse 'synonyms' as 'synonym'
synonyms = [s["val"] for s in meta["synonyms"]]
synonyms = [s["val"] for s in meta["synonyms"] if "val" in s]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.get

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
synonyms = [s["val"] for s in meta["synonyms"] if "val" in s]
synonyms = [s.get("val") for s in meta.get("synonyms", []) if s.get("val")]

like this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants