@@ -40,14 +40,37 @@ class GrobidClient(ApiClient):
4040
4141 def __init__ (
4242 self ,
43- grobid_server = 'http://localhost:8070' ,
44- batch_size = 1000 ,
43+ grobid_server = None ,
44+ batch_size = None ,
4545 coordinates = None ,
46- sleep_time = 5 ,
47- timeout = 180 ,
46+ sleep_time = None ,
47+ timeout = None ,
4848 config_path = None ,
4949 check_server = True
5050 ):
51+ # Set default coordinates if None provided
52+ if coordinates is None :
53+ coordinates = [
54+ "title" ,
55+ "persName" ,
56+ "affiliation" ,
57+ "orgName" ,
58+ "formula" ,
59+ "figure" ,
60+ "ref" ,
61+ "biblStruct" ,
62+ "head" ,
63+ "p" ,
64+ "s" ,
65+ "note"
66+ ]
67+
68+ # Set default values for parameters that are None
69+ default_grobid_server = grobid_server if grobid_server is not None else 'http://localhost:8070'
70+ default_batch_size = batch_size if batch_size is not None else 1000
71+ default_sleep_time = sleep_time if sleep_time is not None else 5
72+ default_timeout = timeout if timeout is not None else 180
73+
5174 # Set default coordinates if None provided
5275 if coordinates is None :
5376 coordinates = [
@@ -66,11 +89,11 @@ def __init__(
6689 ]
6790
6891 self .config = {
69- 'grobid_server' : grobid_server ,
70- 'batch_size' : batch_size ,
92+ 'grobid_server' : default_grobid_server ,
93+ 'batch_size' : default_batch_size ,
7194 'coordinates' : coordinates ,
72- 'sleep_time' : sleep_time ,
73- 'timeout' : timeout ,
95+ 'sleep_time' : default_sleep_time ,
96+ 'timeout' : default_timeout ,
7497 'logging' : {
7598 'level' : 'INFO' ,
7699 'format' : '%(asctime)s - %(name)s - %(levelname)s - %(message)s' ,
@@ -85,18 +108,18 @@ def __init__(
85108 if config_path :
86109 self ._load_config (config_path )
87110
88- # Ensure constructor parameters take precedence over config file values
89- # This ensures CLI arguments override config file values
90- # Only override if the parameter was explicitly provided (not the default)
91- if grobid_server != 'http://localhost:8070' :
111+ # Only override config file values if constructor parameters were explicitly provided (not None)
112+ # This ensures CLI arguments override config file values, but allows config files to be used
113+ # when no constructor parameters are provided
114+ if grobid_server is not None :
92115 self .config ['grobid_server' ] = grobid_server
93- if batch_size != 1000 :
116+ if batch_size is not None :
94117 self .config ['batch_size' ] = batch_size
95- if coordinates is not None : # coordinates has a complex default, so check if explicitly provided
118+ if coordinates is not None :
96119 self .config ['coordinates' ] = coordinates
97- if sleep_time != 5 :
120+ if sleep_time is not None :
98121 self .config ['sleep_time' ] = sleep_time
99- if timeout != 180 :
122+ if timeout is not None :
100123 self .config ['timeout' ] = timeout
101124
102125 # Configure logging based on config
@@ -734,8 +757,8 @@ def main():
734757 )
735758 parser .add_argument (
736759 "--server" ,
737- default = "http://localhost:8070" ,
738- help = "GROBID server URL ( default: http://localhost:8070) " ,
760+ default = None ,
761+ help = "GROBID server URL overide of the config file. If config not provided, default is http://localhost:8070" ,
739762 )
740763
741764 args = parser .parse_args ()
@@ -755,7 +778,12 @@ def main():
755778
756779 # Initialize GrobidClient which will configure logging based on config.json
757780 try :
758- client = GrobidClient (grobid_server = args .server , config_path = config_path )
781+ # Only pass grobid_server if it was explicitly provided (not the default)
782+ client_kwargs = {'config_path' : config_path }
783+ if args .server is not None : # Only override if user specified a different server
784+ client_kwargs ['grobid_server' ] = args .server
785+
786+ client = GrobidClient (** client_kwargs )
759787 # Now use the client's logger for all subsequent logging
760788 logger = client .logger
761789 except ServerUnavailableException as e :
0 commit comments