Skip to content

Commit

Permalink
Add deprecated slot, down rank deprecated search results (#474)
Browse files Browse the repository at this point in the history
Adds deprecated so that we can handle obsolete ontology terms properly
  • Loading branch information
kevinschaper authored Nov 16, 2023
1 parent 7a3d713 commit 606df24
Show file tree
Hide file tree
Showing 33 changed files with 14,605 additions and 18,939 deletions.
57 changes: 25 additions & 32 deletions backend/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ packages = [
python = "^3.9"
pydantic = "^1.10.2"
curies = "<1"
linkml = "^1.6.1"
linkml = "^1.6.2"
prefixmaps = "^0.1.7"

requests = "^2.28.1"
Expand Down
12 changes: 12 additions & 0 deletions backend/src/monarch_py/datamodels/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ class Entity(ConfiguredBaseModel):
category: Optional[str] = Field(None)
name: Optional[str] = Field(None)
full_name: Optional[str] = Field(None, description="""The long form name of an entity""")
deprecated: Optional[bool] = Field(
None,
description="""A boolean flag indicating that an entity is no longer considered current or valid.""",
)
description: Optional[str] = Field(None)
xref: Optional[List[str]] = Field(default_factory=list)
provided_by: Optional[str] = Field(None)
Expand Down Expand Up @@ -474,6 +478,10 @@ class Node(Entity):
category: Optional[str] = Field(None)
name: Optional[str] = Field(None)
full_name: Optional[str] = Field(None, description="""The long form name of an entity""")
deprecated: Optional[bool] = Field(
None,
description="""A boolean flag indicating that an entity is no longer considered current or valid.""",
)
description: Optional[str] = Field(None)
xref: Optional[List[str]] = Field(default_factory=list)
provided_by: Optional[str] = Field(None)
Expand Down Expand Up @@ -575,6 +583,10 @@ class SearchResult(Entity):
category: str = Field(...)
name: str = Field(...)
full_name: Optional[str] = Field(None, description="""The long form name of an entity""")
deprecated: Optional[bool] = Field(
None,
description="""A boolean flag indicating that an entity is no longer considered current or valid.""",
)
description: Optional[str] = Field(None)
xref: Optional[List[str]] = Field(default_factory=list)
provided_by: Optional[str] = Field(None)
Expand Down
8 changes: 8 additions & 0 deletions backend/src/monarch_py/datamodels/model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ classes:
- category
- name
- full_name
- deprecated
- description
- xref
- provided_by
Expand Down Expand Up @@ -304,6 +305,13 @@ slots:
The category of the counterpart entity in a given association,
eg. the category of the entity that is not the subject
range: string
deprecated:
description: >-
A boolean flag indicating that an entity is no longer considered current or valid.
range: boolean
exact_mappings:
- oboInOwl:ObsoleteClass

description:
range: string
direction:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def parse_association_counts(query_result: SolrQueryResult, entity: str) -> Asso
def parse_entity(solr_document: Dict) -> Entity:
try:
entity = Entity(**solr_document)

entity.uri = get_uri(entity.id)
except ValidationError:
logger.error(f"Validation error for {solr_document}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ def entity_boost():
"""Shared boost function between search and autocomplete"""
disease_boost = 'if(termfreq(category,"biolink:Disease"),10.0,1)'
human_gene_boost = 'if(and(termfreq(in_taxon,"NCBITaxon:9606"),termfreq(category,"biolink:Gene")),5.0,1)'
return f"product({disease_boost},{human_gene_boost})"
obsolete_unboost = 'if(termfreq(deprecated,"true"),0.1,1)'
return f"product({disease_boost},{human_gene_boost},{obsolete_unboost})"


def entity_query_fields():
Expand Down
4 changes: 2 additions & 2 deletions backend/src/monarch_py/service/solr_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get(self, id):
response.raise_for_status()
entity = response.json()["doc"]
try:
self._strip_json(entity, "_version_")
self._strip_json(entity, "_version_", "iri")
except TypeError: # if entity is None
return None
return entity
Expand All @@ -33,7 +33,7 @@ def query(self, q: SolrQuery) -> SolrQueryResult:
response.raise_for_status()
solr_query_result = SolrQueryResult.parse_obj(data)
for doc in solr_query_result.response.docs:
self._strip_json(doc, "_version_")
self._strip_json(doc, "_version_", "iri")

return solr_query_result

Expand Down
Loading

0 comments on commit 606df24

Please sign in to comment.