Skip to content

Commit

Permalink
Fixing missing OWL label as alias bug, see #52
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed Apr 30, 2022
1 parent a7e12bd commit 8b73408
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jupyter = "^1.0.0"
sphinx-rtd-theme = "^1.0.0"
sphinx-click = "^3.1.0"
myst-parser = "^0.17.0"
linkml = "^1.2.4"
linkml = "^1.2.10"
sphinxcontrib-mermaid = "^0.7.1"
coverage = "^6.3.2"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _alias_predicates(self) -> List[PRED_CURIE]:

def alias_map_by_curie(self, curie: CURIE) -> ALIAS_MAP:
uri = self.curie_to_sparql(curie)
alias_pred_uris = [self.curie_to_sparql(p) for p in self._alias_predicates()]
alias_pred_uris = [self.curie_to_sparql(p) for p in self._alias_predicates() + [LABEL_PREDICATE]]
query = SparqlQuery(select=['?p', '?o'],
where=[f'{uri} ?p ?o',
_sparql_values('p', alias_pred_uris)])
Expand All @@ -294,7 +294,7 @@ def alias_map_by_curie(self, curie: CURIE) -> ALIAS_MAP:
{'oboInOwl': 'http://www.geneontology.org/formats/oboInOwl#'})
m = defaultdict(list)
for row in bindings:
m[row['p']['value']].append(row['o']['value'])
m[self.uri_to_curie(row['p']['value'])].append(row['o']['value'])
return m

def get_curies_by_label(self, label: str) -> List[CURIE]:
Expand Down
3 changes: 3 additions & 0 deletions src/oaklib/interfaces/basic_ontology_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def alias_map_by_curie(self, curie: CURIE) -> ALIAS_MAP:
"""
Returns aliases keyed by alias type (scope in OBO terms)
- The alias map MUST include rdfs:label annotations
- The alias map MAY include other properties the implementation deems to serve an alias role
:param curie:
:return:
"""
Expand Down
8 changes: 8 additions & 0 deletions tests/test_implementations/test_pronto.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def test_synonyms(self):
'cellular component',
'cell or subcellular entity',
'subcellular entity'])
syns = self.oi.aliases_by_curie(NUCLEUS)
logging.info(syns)
self.assertCountEqual(syns, ['nucleus', 'cell nucleus', 'horsetail nucleus'])
syn_pairs = list(self.oi.alias_map_by_curie(NUCLEUS).items())
self.assertCountEqual(syn_pairs,
[('oio:hasExactSynonym', ['cell nucleus']),
('oio:hasNarrowSynonym', ['horsetail nucleus']),
('rdfs:label', ['nucleus'])])

def test_subsets(self):
oi = self.oi
Expand Down
9 changes: 9 additions & 0 deletions tests/test_implementations/test_sparql.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def test_synonyms(self):
syns = self.oi.aliases_by_curie(CELLULAR_COMPONENT)
logging.info(syns)
assert 'cellular component' in syns
assert 'cellular_component' in syns
syns = self.oi.aliases_by_curie(NUCLEUS)
logging.info(syns)
self.assertCountEqual(syns, ['nucleus', 'cell nucleus', 'horsetail nucleus'])
syn_pairs = list(self.oi.alias_map_by_curie(NUCLEUS).items())
self.assertCountEqual(syn_pairs,
[('oio:hasExactSynonym', ['cell nucleus']),
('oio:hasNarrowSynonym', ['horsetail nucleus']),
('rdfs:label', ['nucleus'])])

def test_all_entity_curies(self):
curies = list(self.oi.all_entity_curies())
Expand Down
11 changes: 11 additions & 0 deletions tests/test_implementations/test_ubergraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ def test_synonyms(self):
logging.info(syns)
assert 'cellular component' in syns

@unittest.skip('This test is too rigid as synonyms are liable to change')
def test_synonyms_granular(self):
syns = self.oi.aliases_by_curie(NUCLEUS)
logging.info(syns)
self.assertCountEqual(syns, ['nucleus', 'cell nucleus', 'horsetail nucleus'])
syn_pairs = list(self.oi.alias_map_by_curie(NUCLEUS).items())
self.assertCountEqual(syn_pairs,
[('oio:hasExactSynonym', ['cell nucleus']),
('oio:hasNarrowSynonym', ['horsetail nucleus']),
('rdfs:label', ['nucleus'])])

def test_definition(self):
defn = self.oi.get_definition_by_curie('GO:0005575')
logging.info(defn)
Expand Down

0 comments on commit 8b73408

Please sign in to comment.