@@ -20,17 +20,19 @@ class Action(Base):
2020 __tablename__ = 'action'
2121 status = Column (String , primary_key = True )
2222
23- def get_status_new (self ):
23+ def get_status_new (self ) -> str :
2424 """
25+ returns the initial status
2526
26- :return:
27+ :return: string indicating the initial status
2728 """
2829 return 'initial'
2930
30- def get_status_retry (self ):
31+ def get_status_retry (self ) -> str :
3132 """
33+ returns the retry status
3234
33- :return:
35+ :return: string indicating the retry status
3436 """
3537 return 'retry'
3638
@@ -49,50 +51,57 @@ class Parser(Base):
4951 reference_service_endpoint = Column (String )
5052 matches = Column (JSONB , default = dict )
5153
52- def __init__ (self , name , extension_pattern , reference_service_endpoint , matches = []):
54+ def __init__ (self , name : str , extension_pattern : str , reference_service_endpoint : str , matches : list = []):
5355 """
56+ initializes a parser object
5457
55- :param name:
56- :param extension_pattern:
57- :param reference_service_endpoint:
58- :param matches:
58+ :param name: name of the parser
59+ :param extension_pattern: reference file extension pattern used by the parser
60+ :param reference_service_endpoint: endpoint for the reference service
61+ :param matches: list of matches for the parser-reference file mapping
5962 """
6063 self .name = name
6164 self .extension_pattern = extension_pattern
6265 self .reference_service_endpoint = reference_service_endpoint
6366 self .matches = matches
6467
65- def get_name (self ):
68+ def get_name (self ) -> str :
6669 """
70+ returns the name of the parser
6771
68- :return:
72+ :return: string indicating the name of the parser
6973 """
7074 return self .name
7175
72- def get_extension_pattern (self ):
76+ def get_extension_pattern (self ) -> str :
7377 """
78+ returns the extension pattern of the reference files processed by the parser
7479
75- :return:
80+ :return: string indicating the file extension pattern
7681 """
7782 return self .extension_pattern
7883
79- def get_endpoint (self ):
84+ def get_endpoint (self ) -> str :
8085 """
86+ returns the reference service endpoint to resolve references
8187
82- :return:
88+ :return: string indicating the reference service endpoint
8389 """
8490 return self .reference_service_endpoint
8591
86- def get_matches (self ):
92+ def get_matches (self ) -> list :
8793 """
94+ returns the list of mappings for the parser
8895
89- :return:
96+ :return: list of matches
9097 """
9198 return self .matches
9299
93- def toJSON (self ):
100+ def toJSON (self ) -> dict :
94101 """
95- :return: values formatted as python dict
102+ converts the parser object to a JSON dictionary
103+
104+ :return: dictionary containing the parser details
96105 """
97106 return {
98107 'name' : self .name ,
@@ -103,28 +112,37 @@ def toJSON(self):
103112
104113
105114class ReferenceSource (Base ):
115+ """
116+ This class represents the source of a reference in the database,
117+ each entry links a source file with its resolved version and
118+ the parser used to process the reference.
119+ It serves as the initial record for the reference processing pipeline.
120+ """
106121 __tablename__ = 'reference_source'
107122 bibcode = Column (String , primary_key = True )
108123 source_filename = Column (String , primary_key = True )
109124 resolved_filename = Column (String )
110125 parser_name = Column (String , ForeignKey ('parser.name' ))
111126
112- def __init__ (self , bibcode , source_filename , resolved_filename , parser_name ):
127+ def __init__ (self , bibcode : str , source_filename : str , resolved_filename : str , parser_name : str ):
113128 """
129+ initializes a reference source object
114130
115- :param bibcode:
116- :param source_filename:
117- :param resolved_filename:
118- :param parser_name:
131+ :param bibcode: unique bibcode for the reference source
132+ :param source_filename: name of the reference file
133+ :param resolved_filename: name of the resolved file for future use
134+ :param parser_name: name of the parser used
119135 """
120136 self .bibcode = bibcode
121137 self .source_filename = source_filename
122138 self .resolved_filename = resolved_filename
123139 self .parser_name = parser_name
124140
125- def toJSON (self ):
141+ def toJSON (self ) -> dict :
126142 """
127- :return: values formatted as python dict, if no values found returns empty structure, not None
143+ converts the reference source object to a JSON dictionary
144+
145+ :return: dictionary containing reference source details
128146 """
129147 return {
130148 'bibcode' : self .bibcode ,
@@ -135,6 +153,10 @@ def toJSON(self):
135153
136154
137155class ProcessedHistory (Base ):
156+ """
157+ This class tracks the processing history of a resolved reference, recording details about the processing status,
158+ reference file timestamp, and the total number of references parsed.
159+ """
138160 __tablename__ = 'processed_history'
139161 __table_args__ = (ForeignKeyConstraint ( ['bibcode' , 'source_filename' ], ['reference_source.bibcode' , 'reference_source.source_filename' ]),)
140162 id = Column (Integer , primary_key = True )
@@ -145,15 +167,16 @@ class ProcessedHistory(Base):
145167 date = Column (DateTime , default = func .now ())
146168 total_ref = Column (Integer )
147169
148- def __init__ (self , bibcode , source_filename , source_modified , status , date , total_ref ):
170+ def __init__ (self , bibcode : str , source_filename : str , source_modified : DateTime , status : str , date : DateTime , total_ref : int ):
149171 """
172+ initializes a processed history object
150173
151- :param bibcode:
152- :param source_filename:
153- :param source_modified:
154- :param status:
155- :param date:
156- :param total_ref:
174+ :param bibcode: bibcode for the reference source
175+ :param source_filename: name of the source reference file
176+ :param source_modified: timestamp of the reference file at the time it was read
177+ :param status: first time processing, or reprocessing this list of references
178+ :param date: date of processing
179+ :param total_ref: total number of references parsed
157180 """
158181 self .bibcode = bibcode
159182 self .source_filename = source_filename
@@ -162,9 +185,11 @@ def __init__(self, bibcode, source_filename, source_modified, status, date, tota
162185 self .date = date
163186 self .total_ref = total_ref
164187
165- def toJSON (self ):
188+ def toJSON (self ) -> dict :
166189 """
167- :return: values formatted as python dict, if no values found returns empty structure, not None
190+ converts the processed history object to a JSON dictionary
191+
192+ :return: dictionary containing processed history details
168193 """
169194 return {
170195 'bibcode' : self .bibcode ,
@@ -177,6 +202,10 @@ def toJSON(self):
177202
178203
179204class ResolvedReference (Base ):
205+ """
206+ This class stores information about references that have been resolved, including the reference string, score,
207+ and its associated history entry.
208+ """
180209 __tablename__ = 'resolved_reference'
181210 history_id = Column (Integer , ForeignKey ('processed_history.id' ), primary_key = True )
182211 item_num = Column (Integer , primary_key = True )
@@ -185,14 +214,16 @@ class ResolvedReference(Base):
185214 score = Column (Numeric )
186215 reference_raw = Column (String )
187216
188- def __init__ (self , history_id , item_num , reference_str , bibcode , score , reference_raw ):
217+ def __init__ (self , history_id : int , item_num : int , reference_str : str , bibcode : str , score : float , reference_raw : str ):
189218 """
219+ initializes a resolved reference object
190220
191- :param history_id:
192- :param item_num
193- :param reference_str:
194- :param bibcode:
195- :param score:
221+ :param history_id: ID of the related processed history entry
222+ :param item_num: order of the reference within the source
223+ :param reference_str: reference string
224+ :param bibcode: resolved bibcode
225+ :param score: confidence score of the resolved reference
226+ :param reference_raw: raw reference string
196227 """
197228 self .history_id = history_id
198229 self .item_num = item_num
@@ -201,35 +232,28 @@ def __init__(self, history_id, item_num, reference_str, bibcode, score, referenc
201232 self .score = score
202233 self .reference_raw = reference_raw
203234
204- def toJSON (self ):
235+ def toJSON (self ) -> dict :
205236 """
206- :return: values formatted as python dict, if no values found returns empty structure, not None
237+ converts the resolved reference object to a JSON dictionary
238+
239+ :return: dictionary containing resolved reference details
207240 """
208- if self .reference_raw :
209- return {
210- 'history_id' : self .history_id ,
211- 'reference_str' : self .reference_str ,
212- 'bibcode' : self .bibcode ,
213- 'score' : self .score ,
214- 'item_num' : self .item_num ,
215- 'reference_raw' : self .reference_raw
216- }
217- # do not include reference_raw if it is None
218241 return {
219242 'history_id' : self .history_id ,
220243 'reference_str' : self .reference_str ,
221244 'bibcode' : self .bibcode ,
222245 'score' : self .score ,
223246 'item_num' : self .item_num ,
247+ ** ({'reference_raw' : self .reference_raw } if self .reference_raw else {})
224248 }
225249
226250
227251class CompareClassic (Base ):
228252 """
229253 This table is for comparing classic resolver with service reference,
230254 keeps track of service reference that matched classic reference
231- bibcode and score here is for classic
232-
255+ bibcode and score here is for classic, should be a temparary class
256+ only used during development/testing and verification
233257 """
234258 __tablename__ = 'compare_classic'
235259 history_id = Column (Integer , ForeignKey ('processed_history.id' ), primary_key = True )
@@ -238,24 +262,27 @@ class CompareClassic(Base):
238262 score = Column (Numeric )
239263 state = Column (String )
240264
241- def __init__ (self , history_id , item_num , bibcode , score , state ):
265+ def __init__ (self , history_id : int , item_num : int , bibcode : str , score : Numeric , state : str ):
242266 """
267+ initializes a compare classic object
243268
244- :param history_id:
245- :param item_num:
246- :param bibcode:
247- :param classic_score:
248- :param state:
269+ :param history_id: ID of the related processed history entry
270+ :param item_num: order of the reference within the source
271+ :param bibcode: resolved bibcode
272+ :param score: confidence score of the resolved reference
273+ :param state: comparison state (ie, matched, unmatched, etc.)
249274 """
250275 self .history_id = history_id
251276 self .item_num = item_num
252277 self .bibcode = bibcode
253278 self .score = score
254279 self .state = state
255280
256- def toJSON (self ):
281+ def toJSON (self ) -> dict :
257282 """
258- :return: values formatted as python dict, if no values found returns empty structure, not None
283+ converts the compare classic object to a JSON dictionary
284+
285+ :return: dictionary containing compare classic details
259286 """
260287 return {
261288 'history_id' : self .history_id ,
0 commit comments