Skip to content

Commit

Permalink
Fix name lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Apr 11, 2024
1 parent 87a444b commit c973e79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions src/semra/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import semra
from semra import Evidence, MappingSet, Reference
from semra.io import _get_name_by_curie
from semra.rules import RELATIONS

__all__ = [
Expand All @@ -42,12 +41,12 @@ def _safe_curie(curie_or_luid: ReferenceHint, prefix: str) -> str:
return f"{prefix}:{curie_or_luid}"


#: A cypher query that if it returns a result signifies that there are concept names in the database
HAS_NAMES_CYPHER = "MATCH (n:concept) WHERE n.name is not null RETURN n LIMIT 1"

#: A cypher query that gets all of the databases' relation types
RELATIONS_CYPHER = "CALL db.relationshipTypes() YIELD relationshipType RETURN relationshipType"

#: A cypher query format string for getting the name of a concept
CONCEPT_NAME_CYPHER = "MATCH (n:concept) WHERE n.curie = $curie RETURN n.name LIMIT 1"


class Neo4jClient:
"""A client to Neo4j."""
Expand Down Expand Up @@ -76,7 +75,6 @@ def __init__(
self._rel_q = "|".join(
f"`{reference.curie}`" for reference in RELATIONS if reference.curie in self._all_relations
)
self._database_has_names = len(self.read_query(HAS_NAMES_CYPHER)) > 1

def __del__(self):
"""Ensure driver is shut down when client is destroyed."""
Expand Down Expand Up @@ -330,11 +328,12 @@ def get_concept_name(self, curie: ReferenceHint) -> str | None:
"""Get the name for a CURIE or reference."""
if isinstance(curie, Reference):
curie = curie.curie
if not self._database_has_names:
# return _get_name_by_curie(curie)
try:
name = self.read_query(CONCEPT_NAME_CYPHER, curie=curie)[0][0]
except Exception:
return None
query = "MATCH (n:concept) WHERE n.curie = $curie RETURN n.name"
return self.read_query(query)[0][0]
else:
return name

def sample_mappings_from_set(self, curie: ReferenceHint, n: int = 10) -> t.List:
"""Get n mappings from a given set (by CURIE)."""
Expand Down
2 changes: 1 addition & 1 deletion src/semra/templates/concept.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<div class="card">
<div class="card-body">
<h5 class="card-title">
{{ name }} <a class="badge badge-info" href="https://bioregistry.io/{{ curie }}">{{ curie }}</a>
{{ name }} <a class="badge badge-info" href="https://bioregistry.io/{{ curie }}"><code>{{ curie }}</code></a>
</h5>
<h6>Exact Matches</h6>
</div>
Expand Down

0 comments on commit c973e79

Please sign in to comment.