@@ -285,20 +285,19 @@ def _test_server_connection(self) -> Tuple[bool, int]:
285285 raise ServerUnavailableException (error_msg ) from e
286286
287287 def _output_file_name (self , input_file , input_path , output ):
288- # we use ntpath here to be sure it will work on Windows too
288+ # Use pathlib for consistent cross-platform path handling
289+ input_file_path = pathlib .Path (input_file )
290+
289291 if output is not None :
290- input_file_name = str ( os . path . relpath ( os . path . abspath ( input_file ), input_path ))
291- filename = os . path . join (
292- output , os . path . splitext ( input_file_name )[ 0 ] + ".grobid.tei.xml"
293- )
292+ # Calculate relative path from input_path, then join with output directory
293+ input_path_abs = pathlib . Path ( input_path ). resolve ()
294+ input_file_rel = input_file_path . resolve (). relative_to ( input_path_abs )
295+ filename = pathlib . Path ( output ) / f" { input_file_rel . stem } .grobid.tei.xml"
294296 else :
295- input_file_name = ntpath .basename (input_file )
296- filename = os .path .join (
297- ntpath .dirname (input_file ),
298- os .path .splitext (input_file_name )[0 ] + ".grobid.tei.xml" ,
299- )
297+ # Use the same directory as the input file
298+ filename = input_file_path .parent / f"{ input_file_path .stem } .grobid.tei.xml"
300299
301- return filename
300+ return str ( filename )
302301
303302 def ping (self ) -> Tuple [bool , int ]:
304303 """
0 commit comments