-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement New Weaviate Repository #61
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
17ec7f7
update: datastew version
mehmetcanay 9787834
refactor: implement new weaviate repository
mehmetcanay 333b296
refactor: fix endpoint ids
mehmetcanay 3ffff7c
Merge branch 'main' of https://github.com/SCAI-BIO/index into refacto…
mehmetcanay 4731bc9
refactor: update datastew version
mehmetcanay a84e345
Fix port
tiadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,13 +107,19 @@ async def get_all_terminologies(): | |
|
||
|
||
@app.put("/terminologies/{id}", tags=["terminologies"]) | ||
async def create_or_update_terminology(id: str, name: str): | ||
async def create_terminology(id: str, name: str): | ||
try: | ||
terminology = Terminology(name=name, id=id) | ||
repository.store(terminology) | ||
return {"message": f"Terminology {id} created or updated successfully"} | ||
return {"message": f"Terminology {id} created successfully"} | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=f"Failed to create or update terminology: {str(e)}") | ||
raise HTTPException(status_code=400, detail=f"Failed to create terminology: {str(e)}") | ||
|
||
|
||
@app.get("/models", tags=["models"]) | ||
async def get_all_models(): | ||
sentence_embedders = repository.get_all_sentence_embedders() | ||
return sentence_embedders | ||
|
||
|
||
@app.get("/concepts", tags=["concepts"]) | ||
|
@@ -123,17 +129,14 @@ async def get_all_concepts(): | |
|
||
|
||
@app.put("/concepts/{id}", tags=["concepts"]) | ||
async def create_or_update_concept(id: str, terminology_id: str, name: str): | ||
async def create_concept(id: str, concept_name: str, terminology_name: str): | ||
try: | ||
terminology = repository.session.query(Terminology).filter(Terminology.id == terminology_id).first() | ||
if not terminology: | ||
raise HTTPException(status_code=404, detail=f"Terminology with id {terminology_id} not found") | ||
|
||
concept = Concept(terminology=terminology, name=name, id=id) | ||
terminology = repository.get_terminology(terminology_name) | ||
concept = Concept(terminology=terminology, pref_label=concept_name, concept_identifier=id) | ||
repository.store(concept) | ||
return {"message": f"Concept {id} created or updated successfully"} | ||
return {"message": f"Concept {id} created successfully"} | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=f"Failed to create or update concept: {str(e)}") | ||
raise HTTPException(status_code=400, detail=f"Failed to create concept: {str(e)}") | ||
|
||
|
||
@app.get("/mappings", tags=["mappings"]) | ||
|
@@ -143,39 +146,38 @@ async def get_all_mappings(): | |
|
||
|
||
@app.put("/concepts/{id}/mappings", tags=["concepts", "mappings"]) | ||
async def create_concept_and_attach_mapping(id: str, terminology_id: str, concept_name: str, text: str): | ||
async def create_concept_and_attach_mapping(id: str, concept_name: str, terminology_name, text: str): | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And fixed here too. |
||
terminology = repository.session.query(Terminology).filter(Terminology.id == terminology_id).first() | ||
if not terminology: | ||
raise HTTPException(status_code=404, detail=f"Terminology with id {terminology_id} not found") | ||
concept = Concept(terminology=terminology, name=concept_name, id=id) | ||
terminology = repository.get_terminology(terminology_name) | ||
concept = Concept(terminology=terminology, pref_label=concept_name, concept_identifier=id) | ||
repository.store(concept) | ||
embedding = embedding_model.get_embedding(text) | ||
mapping = Mapping(concept=concept, text=text, embedding=embedding) | ||
model_name = embedding_model.get_model_name() | ||
mapping = Mapping(concept=concept, text=text, embedding=embedding, sentence_embedder=model_name) | ||
repository.store(mapping) | ||
return {"message": f"Concept {id} created or updated successfully"} | ||
return {"message": f"Concept {id} created successfully"} | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=f"Failed to create or update concept: {str(e)}") | ||
raise HTTPException(status_code=400, detail=f"Failed to create concept: {str(e)}") | ||
|
||
|
||
@app.put("/mappings/", tags=["mappings"]) | ||
async def create_or_update_mapping(concept_id: str, text: str): | ||
async def create_mapping(concept_id: str, text: str): | ||
try: | ||
concept = repository.session.query(Concept).filter(Concept.id == concept_id).first() | ||
if not concept: | ||
raise HTTPException(status_code=404, detail=f"Concept with id {concept_id} not found") | ||
concept = repository.get_concept(concept_id) | ||
embedding = embedding_model.get_embedding(text) | ||
mapping = Mapping(concept=concept, text=text, embedding=embedding) | ||
model_name = embedding_model.get_model_name() | ||
mapping = Mapping(concept=concept, text=text, embedding=embedding, sentence_embedder=model_name) | ||
repository.store(mapping) | ||
return {"message": f"Mapping created or updated successfully"} | ||
return {"message": "Mapping created successfully"} | ||
except Exception as e: | ||
raise HTTPException(status_code=400, detail=f"Failed to create or update mapping: {str(e)}") | ||
raise HTTPException(status_code=400, detail=f"Failed to create mapping: {str(e)}") | ||
|
||
|
||
@app.post("/mappings", tags=["mappings"]) | ||
async def get_closest_mappings_for_text(text: str, limit: int = 5): | ||
async def get_closest_mappings_for_text(text: str, terminology_name: str = "SNOMED CT", | ||
sentence_embedder: str = "sentence-transformers/all-mpnet-base-v2", limit: int = 5): | ||
embedding = embedding_model.get_embedding(text).tolist() | ||
closest_mappings = repository.get_closest_mappings_with_similarities(embedding, limit) | ||
closest_mappings = repository.get_terminology_and_model_specific_closest_mappings(embedding, terminology_name, sentence_embedder, limit) | ||
mappings = [] | ||
for mapping, similarity in closest_mappings: | ||
concept = mapping.concept | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless the request param name matches the param name, this should not work afaik
Test for e.g.
/concepts/some_id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I missed it. Fixed in the next push.