maseiler commited on
Commit
f26b169
1 Parent(s): 1f35211

Add get_diseases_related_to_clinical_trials

Browse files
Files changed (1) hide show
  1. utils.py +22 -0
utils.py CHANGED
@@ -150,6 +150,28 @@ def get_diseases_related_to_a_textual_description(
150
 
151
  return [{"uri": row[0], "distance": row[1]} for row in data]
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  if __name__ == "__main__":
155
  username = "demo"
 
150
 
151
  return [{"uri": row[0], "distance": row[1]} for row in data]
152
 
153
+ def get_diseases_related_to_clinical_trials(
154
+ diseases: List[str], encoder
155
+ ) -> List[str]:
156
+ # Embed the diseases using sentence-transformers
157
+ diseases_string = ", ".join(diseases)
158
+ disease_embedding = get_embedding(diseases_string, encoder)
159
+ print(f"Size of the embedding: {len(disease_embedding)}")
160
+ string_representation = str(disease_embedding.tolist())[1:-1]
161
+ print(f"String representation: {string_representation}")
162
+
163
+ with engine.connect() as conn:
164
+ with conn.begin():
165
+ sql = f"""
166
+ SELECT TOP 5 d.uri, VECTOR_COSINE(d.embedding, TO_VECTOR('{string_representation}', DOUBLE)) AS distance
167
+ FROM Test.ClinicalTrials d
168
+ ORDER BY distance DESC
169
+ """
170
+ result = conn.execute(text(sql))
171
+ data = result.fetchall()
172
+
173
+ return [{"uri": row[0], "distance": row[1]} for row in data]
174
+
175
 
176
  if __name__ == "__main__":
177
  username = "demo"