66from typing import List
77
88from .openai_client import CoordinateParsingClient
9- from .schema import Analysis
109
1110logger = logging .getLogger (__name__ )
1211
1312
1413class CoordinateProcessor :
1514 """Processor for parsing coordinates from activation tables."""
1615
17- def __init__ (self , model : str = "gpt-4o-mini" ):
16+ def __init__ (self , model : str = "gpt-4o-mini" ,
17+ path_preference : List [str ] = ['table_raw_path' , 'table_data_path' ]):
1818 """
1919 Initialize the coordinate processor.
2020
2121 Args:
2222 model: The model to use for parsing
2323 """
2424 self .model = model
25+ self .path_preference = path_preference
2526 self .client = CoordinateParsingClient ()
26-
27- def process_study (self , study ):
28- """
29- Process all activation tables for a study and extract analyses.
30-
31- Args:
32- study: The study to process
33-
34- Returns:
35- List of analyses extracted from the study's tables
36- """
37- # Import locally to avoid circular imports
38- from autonima .models .types import Study , ActivationTable
39-
40- if not study .activation_tables :
41- return []
42-
43- all_analyses = []
44-
45- for table in study .activation_tables :
46- try :
47- # Load the table data
48- table_path = Path (table .table_path )
49- if not table_path .exists ():
50- logger .warning (f"Table file not found: { table_path } " )
51- continue
52-
53- # Read the table as text
54- with open (table_path , "r" , encoding = "utf-8" ) as f :
55- reader = csv .reader (f )
56- rows = list (reader )
57- table_text = "\n " .join (["," .join (r ) for r in rows ])
58-
59- # Create a prompt for the table
60- prompt = self ._create_table_prompt (
61- table_text ,
62- table_caption = table .table_caption or "" ,
63- table_foot = table .table_foot or ""
64- )
65-
66- # Parse the table
67- result = self .client .parse_analyses (prompt , model = self .model )
68-
69- # Add the analyses to our list
70- all_analyses .extend (result .analyses )
71-
72- except Exception as e :
73- logger .warning (f"Error processing table { table .table_path } : { e } " )
74- continue
75-
76- return all_analyses
27+
7728
7829 def process_single_table (self , table ):
7930 """
@@ -87,7 +38,15 @@ def process_single_table(self, table):
8738 """
8839 try :
8940 # Load the table data
90- table_path = Path (table .table_path )
41+ for path_attr in self .path_preference :
42+ table_path_value = getattr (table , path_attr , None )
43+ if table_path_value :
44+ table_path = Path (table_path_value )
45+ break
46+ else :
47+ logger .warning (f"No valid table path found for table: { table .table_id } " )
48+ return []
49+ table_path = Path (table_path )
9150 if not table_path .exists ():
9251 logger .warning (f"Table file not found: { table_path } " )
9352 return []
@@ -107,7 +66,6 @@ def process_single_table(self, table):
10766
10867 # Parse the table
10968 result = self .client .parse_analyses (prompt , model = self .model )
110-
11169 return result .analyses
11270
11371 except Exception as e :
0 commit comments