@@ -174,6 +174,108 @@ for (c in concepts) {
174174}
175175cat(" \n " )
176176
177+ # ============================================================================
178+ # Semantic Search
179+ # ============================================================================
180+
181+ cat(" 7. Semantic search (natural language)\n " )
182+ cat(" -------------------------------------\n " )
183+
184+ # Search using natural language - understands clinical intent
185+ results <- client $ search $ semantic(" high blood sugar levels" , page_size = 5 )
186+
187+ cat(" Semantic results for 'high blood sugar levels':\n " )
188+ for (r in results $ data $ results ) {
189+ cat(sprintf(" [%d] %s (similarity: %.2f)\n " ,
190+ r $ concept_id , r $ concept_name , r $ similarity_score ))
191+ }
192+ cat(" \n " )
193+
194+ # ============================================================================
195+ # Semantic Search with Filters
196+ # ============================================================================
197+
198+ cat(" 8. Semantic search with filters\n " )
199+ cat(" -------------------------------\n " )
200+
201+ results <- client $ search $ semantic(
202+ " heart attack" ,
203+ vocabulary_ids = " SNOMED" ,
204+ domain_ids = " Condition" ,
205+ threshold = 0.5 ,
206+ page_size = 5
207+ )
208+
209+ cat(" Filtered semantic results for 'heart attack':\n " )
210+ for (r in results $ data $ results ) {
211+ cat(sprintf(" [%d] %s (similarity: %.2f)\n " ,
212+ r $ concept_id , r $ concept_name , r $ similarity_score ))
213+ }
214+ cat(" \n " )
215+
216+ # ============================================================================
217+ # Auto-Paginated Semantic Search
218+ # ============================================================================
219+
220+ cat(" 9. Auto-paginated semantic search\n " )
221+ cat(" ----------------------------------\n " )
222+
223+ all_results <- client $ search $ semantic_all(
224+ " chronic kidney disease" ,
225+ page_size = 10 ,
226+ max_pages = 3 ,
227+ progress = FALSE
228+ )
229+
230+ cat(sprintf(" Fetched %d concepts for 'chronic kidney disease':\n " , nrow(all_results )))
231+ if (nrow(all_results ) > 0 ) {
232+ for (i in seq_len(min(5 , nrow(all_results )))) {
233+ cat(sprintf(" [%d] %s\n " ,
234+ all_results $ concept_id [i ],
235+ all_results $ concept_name [i ]))
236+ }
237+ if (nrow(all_results ) > 5 ) {
238+ cat(sprintf(" ... and %d more\n " , nrow(all_results ) - 5 ))
239+ }
240+ }
241+ cat(" \n " )
242+
243+ # ============================================================================
244+ # Similarity Search
245+ # ============================================================================
246+
247+ cat(" 10. Similarity search\n " )
248+ cat(" ---------------------\n " )
249+
250+ # Find concepts similar to Type 2 diabetes mellitus
251+ similar <- client $ search $ similar(
252+ concept_id = 201826 ,
253+ algorithm = " hybrid" ,
254+ similarity_threshold = 0.6 ,
255+ page_size = 5
256+ )
257+
258+ cat(" Concepts similar to 'Type 2 diabetes mellitus':\n " )
259+ for (s in similar $ similar_concepts ) {
260+ cat(sprintf(" [%d] %s (score: %.2f)\n " ,
261+ s $ concept_id , s $ concept_name , s $ similarity_score ))
262+ }
263+ cat(" \n " )
264+
265+ # Similarity by natural language query
266+ similar <- client $ search $ similar(
267+ query = " high blood pressure" ,
268+ algorithm = " semantic" ,
269+ page_size = 5
270+ )
271+
272+ cat(" Concepts similar to 'high blood pressure' (semantic):\n " )
273+ for (s in similar $ similar_concepts ) {
274+ cat(sprintf(" [%d] %s (score: %.2f)\n " ,
275+ s $ concept_id , s $ concept_name , s $ similarity_score ))
276+ }
277+ cat(" \n " )
278+
177279# ============================================================================
178280# Done
179281# ============================================================================
0 commit comments