88from typing import Dict , List , Optional , Union
99
1010from .base_client import BaseClient , AsyncBaseClient
11- from . import ParseResponse , EquationExtractionResponse , EquationProcessingResponse
11+ from . import ParseResponse , EquationProcessingResponse
1212from .axtract .axtract_report import create_report
1313from .axtract .validation_results import display_full_results
14- from .axtract .interactive_table import _create_variable_dict
15- from .types .variable_requirement import VariableRequirement as ApiVariableRequirement
14+ from .axtract .interactive_table import _create_variable_dict , VariableRequirement
15+ from .types .variable_requirement import VariableRequirement
16+ from .types .validate_equations_body import ValidateEquationsBody
1617
1718
1819class Axiomatic (BaseClient ):
@@ -27,36 +28,83 @@ def __init__(self, *args, **kwargs):
2728
2829
2930class AxtractHelper :
30- from .axtract .interactive_table import VariableRequirement
31-
3231 _ax_client : Axiomatic
3332
3433 def __init__ (self , ax_client : Axiomatic ):
34+ """Initialize the AxtractHelper with an Axiomatic client.
35+
36+ Args:
37+ ax_client (Axiomatic): The Axiomatic client instance to use for API calls
38+ """
3539 self ._ax_client = ax_client
3640
37- def create_report (self , response : EquationExtractionResponse , path : str ):
41+ def create_report (self , response : EquationProcessingResponse , path : str ):
42+ """Create a report from equation extraction results.
43+
44+ Args:
45+ response (EquationExtractionResponse): The extracted equations and their metadata
46+ path (str): Directory path where the report should be saved
47+ """
3848 create_report (response , path )
3949
4050 def analyze_equations (
4151 self ,
4252 file_path : Optional [str ] = None ,
4353 url_path : Optional [str ] = None ,
4454 parsed_paper : Optional [ParseResponse ] = None ,
45- ) -> Optional [EquationExtractionResponse ]:
55+ ) -> Optional [EquationProcessingResponse ]:
56+ """Analyze and extract equations from a scientific document.
57+
58+ This method supports three input methods:
59+ 1. Local PDF file path
60+ 2. URL to a PDF (with special handling for arXiv URLs)
61+ 3. Pre-parsed paper data
62+
63+ Args:
64+ file_path (Optional[str]): Path to a local PDF file
65+ url_path (Optional[str]): URL to a PDF file (supports arXiv links)
66+ parsed_paper (Optional[ParseResponse]): Pre-parsed paper data
67+
68+ Returns:
69+ Optional[EquationExtractionResponse]: Extracted equations and their metadata.
70+ Returns None if no valid input is provided.
71+
72+ Examples:
73+ # From local file
74+ client.analyze_equations(file_path="path/to/paper.pdf")
75+
76+ # From URL
77+ client.analyze_equations(url_path="https://arxiv.org/pdf/2203.00001.pdf")
78+
79+ # From parsed paper
80+ client.analyze_equations(parsed_paper=parsed_data)
81+ """
4682 if file_path :
4783 with open (file_path , "rb" ) as pdf_file :
48- response = self ._ax_client .document .equation .from_pdf (document = pdf_file )
84+ parsed_document = self ._ax_client .document .parse (file = pdf_file )
85+ print ("We are almost there" )
86+ response = self ._ax_client .document .equation .process (
87+ markdown = parsed_document .markdown ,
88+ interline_equations = parsed_document .interline_equations ,
89+ inline_equations = parsed_document .inline_equations
90+ )
4991
5092 elif url_path :
5193 if "arxiv" in url_path and "abs" in url_path :
5294 url_path = url_path .replace ("abs" , "pdf" )
5395 url_file = requests .get (url_path )
5496 from io import BytesIO
5597 pdf_stream = BytesIO (url_file .content )
56- response = self ._ax_client .document .equation .from_pdf (document = pdf_stream )
98+ parsed_document = self ._ax_client .document .parse (file = url_file .content )
99+ print ("We are almost there" )
100+ response = self ._ax_client .document .equation .process (
101+ markdown = parsed_document .markdown ,
102+ interline_equations = parsed_document .interline_equations ,
103+ inline_equations = parsed_document .inline_equations
104+ )
57105
58106 elif parsed_paper :
59- response = EquationExtractionResponse .model_validate (
107+ response = EquationProcessingResponse .model_validate (
60108 self ._ax_client .document .equation .process (** parsed_paper .model_dump ()).model_dump ()
61109 )
62110
@@ -68,22 +116,55 @@ def analyze_equations(
68116
69117 def validate_equations (
70118 self ,
71- requirements : List [VariableRequirement ],
72- loaded_equations : EquationExtractionResponse ,
119+ requirements : list [VariableRequirement ],
120+ loaded_equations : EquationProcessingResponse ,
73121 show_hypergraph : bool = True ,
122+ include_internal_model : bool = False ,
74123 ):
75- api_requirements = [
76- ApiVariableRequirement (
77- symbol = req .symbol , name = req .name , value = req .value , units = req .units , tolerance = req .tolerance
78- )
79- for req in requirements
80- ]
124+ """Validate equations against a set of variable requirements.
125+
126+ Args:
127+ requirements: List of variable requirements to validate
128+ loaded_equations: Previously processed equations to validate
129+ show_hypergraph: Whether to display the validation results graph (default: True)
130+ include_internal_model: Whether to include internal model equations in validation (default: False)
131+
132+ Returns:
133+ EquationValidationResult containing the validation results
134+ """
135+ # Convert loaded_equations to dict first to ensure proper serialization
136+ equations_dict = loaded_equations .model_dump () if hasattr (loaded_equations , 'model_dump' ) else loaded_equations .dict ()
137+
138+ request_body = ValidateEquationsBody (
139+ variables = requirements ,
140+ paper_equations = equations_dict ,
141+ include_internal_model = include_internal_model
142+ )
143+
144+ print (request_body .model_dump_json ())
145+
146+ api_response = self ._ax_client .document .equation .validate (request_body .model_dump_json ())
147+
148+ if show_hypergraph :
149+ pass
150+
151+ return api_response
152+
153+
154+
155+
156+ def set_numerical_requirements (self , extracted_equations : EquationProcessingResponse ):
157+ """Launch an interactive interface for setting numerical requirements for equations.
81158
82- variable_dict = _create_variable_dict (loaded_equations )
83- api_response = self ._ax_client .document .equation .validate (request = api_requirements )
84- display_full_results (api_response .model_dump (), variable_dict , show_hypergraph = show_hypergraph )
159+ This method opens an interactive table interface where users can specify
160+ requirements for variables found in the extracted equations.
85161
86- def set_numerical_requirements (self , extracted_equations ):
162+ Args:
163+ extracted_equations: The equations to set requirements for
164+
165+ Returns:
166+ The requirements set through the interactive interface
167+ """
87168 from .axtract .interactive_table import interactive_table
88169
89170 result = interactive_table (extracted_equations )
@@ -255,4 +336,4 @@ def _load_objects_from_base64(self, encoded_dict):
255336 return loaded_objects
256337
257338
258- class AsyncAxiomatic (AsyncBaseClient ): ...
339+ class AsyncAxiomatic (AsyncBaseClient ): ...
0 commit comments