""" Retrieve top k candidate standard terms for normalization using oaklib. """ # import argparse from oaklib import get_adapter from oaklib.datamodels.search import SearchConfiguration adapter = get_adapter("ols:") def get_candidates(term: str, top_k: int = 10) -> list[str]: """ Get top k candidates for RAG. """ # Set config for search (limit # terms returned) cfg = SearchConfiguration(limit=top_k) results = adapter.basic_search(term, config=cfg) labels = list(adapter.labels(results)) # list of tuples of ids and labels # print(f"## Query: {term} -> {labels}") candidates = list(label for _, label in labels) return candidates # def main(): # parser = argparse.ArgumentParser( # description="Fetch top-K candidate passages for a given term (RAG)" # ) # parser.add_argument( # "term", type=str, help="The query term or prompt for which to retrieve candidates" # ) # parser.add_argument( # "-k", # "--top_k", # type=int, # default=10, # help="Number of top candidates to return (default: 10)", # ) # args = parser.parse_args() # # Call your function # candidates = get_candidates(args.term) # print(f"\nTerm: {args.term!r}") # print(f"Top {args.top_k} candidates:") # for i, cand in enumerate(candidates, start=1): # print(f" {i:2d}. {cand}") # if __name__ == "__main__": # main()