11import requests
22import json
33import logging
4- from typing import List , Dict , Any , Optional
4+ import pandas as pd
5+ from typing import List , Dict , Any , Optional , Union
6+ from vfb_connect import vfb
57
68class SolrTermInfoFetcher :
79 """Fetches term information directly from the Solr server instead of using VfbConnect"""
@@ -10,20 +12,21 @@ def __init__(self, solr_url: str = "https://solr.virtualflybrain.org/solr/vfb_js
1012 """Initialize with the Solr server URL"""
1113 self .solr_url = solr_url
1214 self .logger = logging .getLogger (__name__ )
15+ self .vfb = vfb
1316
1417 def get_TermInfo (self , short_forms : List [str ],
1518 return_dataframe : bool = False ,
16- summary : bool = False ) -> List [Dict [str , Any ]]:
19+ summary : bool = False ) -> Union [ List [Dict [str , Any ]], pd . DataFrame ]:
1720 """
1821 Fetch term info from Solr directly, mimicking VFBconnect's interface
1922
2023 Args:
2124 short_forms: List of term IDs to fetch
22- return_dataframe: If True, return as pandas DataFrame (not fully implemented)
25+ return_dataframe: If True, return as pandas DataFrame
2326 summary: If True, return summarized version
2427
2528 Returns:
26- List of term info dictionaries
29+ List of term info dictionaries or DataFrame
2730 """
2831 results = []
2932
@@ -54,7 +57,6 @@ def get_TermInfo(self, short_forms: List[str],
5457
5558 # Extract and parse the term_info string which is itself JSON
5659 term_info_str = docs [0 ]["term_info" ][0 ]
57- # No need to handle escapes - json.loads does that automatically
5860 term_info_obj = json .loads (term_info_str )
5961 results .append (term_info_obj )
6062
@@ -65,9 +67,23 @@ def get_TermInfo(self, short_forms: List[str],
6567 except Exception as e :
6668 self .logger .error (f"Unexpected error for { short_form } : { e } " )
6769
68- # Handle dataframe conversion if needed (this would need to be implemented)
69- if return_dataframe :
70- self .logger .warning ("return_dataframe=True not fully implemented" )
71- # You would need to implement pandas DataFrame conversion logic here
70+ # Convert to DataFrame if requested
71+ if return_dataframe and results :
72+ try :
73+ return pd .json_normalize (results )
74+ except Exception as e :
75+ self .logger .error (f"Error converting to DataFrame: { e } " )
76+ return results
7277
73- return results
78+ return results
79+
80+ # Pass through any non-implemented methods to VFBconnect
81+ def __getattr__ (self , name ):
82+ """
83+ Automatically pass through any non-implemented methods to VFBconnect
84+
85+ This allows us to use this class as a drop-in replacement for VfbConnect
86+ while only implementing the methods we want to customize.
87+ """
88+ self .logger .debug (f"Passing through method call: { name } " )
89+ return getattr (self .vfb , name )
0 commit comments