Skip to content

Commit

Permalink
Update semsearch to take a search category enumeration value rather t…
Browse files Browse the repository at this point in the history
…han a raw prefix, plus generate fixtures and manually repair the model so that the scores are numbers rather than strings.
  • Loading branch information
kevinschaper committed Dec 13, 2023
1 parent e3bcfae commit 767905b
Show file tree
Hide file tree
Showing 10 changed files with 2,122 additions and 1,624 deletions.
4 changes: 2 additions & 2 deletions backend/src/monarch_py/api/additional_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ class SemsimCompareRequest(BaseModel):

class SemsimSearchRequest(BaseModel):
termset: List[str] = Field(..., title="Termset to search")
prefix: str = Field(..., title="Prefix to search for")
limit: Optional[int] = Field(..., title="Limit the number of results")
category: SemsimSearchCategory = Field(..., title="Category to search for")
limit: Optional[int] = Field(10, title="Limit the number of results", ge=1, le=50)
22 changes: 11 additions & 11 deletions backend/src/monarch_py/api/semsim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi import APIRouter, HTTPException, Path, Query
from fastapi import APIRouter, Path, Query

from monarch_py.api.additional_models import SemsimCompareRequest, SemsimSearchRequest, SemsimSearchCategory
from monarch_py.api.config import semsimian
Expand Down Expand Up @@ -54,14 +54,14 @@ def _post_compare(request: SemsimCompareRequest):
@router.get("/search/{termset}/{prefix}")
def _search(
termset: str = Path(..., title="Termset to search"),
prefix: str = Path(..., title="Prefix to search for"),
limit: int = Query(default=10, ge=0, le=500),
category: SemsimSearchCategory = Path(..., title="Category of entities to search for"),
limit: int = Query(default=10, ge=1, le=50),
):
"""Search for terms in a termset
<b>Args:</b> <br>
termset (str, optional): Termset to search. Defaults to "". <br>
prefix (str, optional): Prefix to search for. Defaults to "". <br>
termset (str, optional): Comma separated list of term IDs to find matches for. <br>
category (str, optional): Category of entities to search for. <br>
limit (int, optional): Limit the number of results. Defaults to 10.
<b>Returns:</b> <br>
Expand All @@ -72,11 +72,11 @@ def _search(
f"""
Running semsim search:
termset: {termset}
prefix: {prefix}
category: {category}
"""
)
results = semsimian().search(termset=termset.split(","), prefix=parse_similarity_prefix(prefix), limit=limit)

results = semsimian().search(termset=termset.split(","), prefix=parse_similarity_prefix(category), limit=limit)
return results


Expand All @@ -88,10 +88,10 @@ def _post_search(request: SemsimSearchRequest):
Example: <br>
<pre>
{
"termset": ["HP:0000001", "HP:0000002"],
"prefix": "ZFIN",
"termset": ["HP:0002104", "HP:0012378", "HP:0012378", "HP:0012378"],
"category": "Human Diseases",
"limit": 5
}
</pre>
"""
return semsimian().search(request.termset, parse_similarity_prefix(request.prefix), request.limit)
return semsimian().search(request.termset, parse_similarity_prefix(request.category.value), request.limit)
2 changes: 1 addition & 1 deletion backend/tests/fixtures/association_counts_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def association_counts_response():
return {
"responseHeader": {
"QTime": 2,
"QTime": 1,
"params": {
"facet.query": [
'(category:"biolink:DiseaseToPhenotypicFeatureAssociation") AND (subject:"MONDO:0020121" OR subject_closure:"MONDO:0020121")',
Expand Down
1,852 changes: 1,066 additions & 786 deletions backend/tests/fixtures/phenotype_explorer_search.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion backend/tests/fixtures/search_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def search_response():
return {
"responseHeader": {
"QTime": 0,
"QTime": 2,
"params": {
"mm": "100%",
"q": "fanconi",
Expand Down
Loading

0 comments on commit 767905b

Please sign in to comment.