2% drs2xml.pl, by Johan Bos
    3
    4/*========================================================================
    5   File Search Paths
    6========================================================================*/
    7
    8file_search_path(semlib,     'src/prolog/lib').
    9file_search_path(boxer,      'src/prolog/boxer').
   10file_search_path(knowledge,  'src/prolog/boxer/knowledge').
   11file_search_path(lex,        'src/prolog/boxer/lex').
   12
   13
   14/*========================================================================
   15   Load other libraries
   16========================================================================*/
   17
   18:- use_module(boxer(xdrs2xml),[xdrs2xml/2]).   19
   20
   21/*========================================================================
   22   Main
   23========================================================================*/
   24
   25convert(In,Out):-
   26   openOutput(Out,Stream),
   27   openInput(In,Tags,DRS),
   28   xdrs2xml(xdrs(Tags,DRS),Stream),
   29   close(Stream).
   30
   31
   32/*------------------------------------------------------------------------
   33   Open Input File
   34------------------------------------------------------------------------*/
   35
   36openInput(Input,Tags,DRS):-
   37   atomic(Input), 
   38   access_file(Input,read), !,
   39   open(Input,read,Stream),
   40   read(Stream,sem(_,Tags,DRS)),
   41   close(Stream).
   42
   43openInput(Input,_,_):-
   44   format('cannot read file ~p~n',[Input]),
   45   halt.
   46
   47
   48/*------------------------------------------------------------------------
   49   Open Output File
   50------------------------------------------------------------------------*/
   51
   52openOutput(Output,Stream):-
   53   atomic(Output), 
   54   \+ Output=user_output, 
   55   ( access_file(Output,write), !,
   56     open(Output,write,Stream,[encoding(utf8)])
   57   ; format('cannot write to specified file ~p~n',[Output]),
   58     Stream=user_output ), !.
   59
   60openOutput(user_output).
   61
   62
   63/* =======================================================================
   64   Definition of start
   65========================================================================*/
   66
   67start:-
   68   current_prolog_flag(argv,[swipl,_,_,In,Out]), !,
   69   convert(In,Out),
   70   halt.
   71
   72start:-
   73   current_prolog_flag(argv,[In,Out]), !,
   74   convert(In,Out),
   75   halt.
   76
   77start:- 
   78   write('usage: swipl -l src/prolog/boxer/drs2xml.pl INPUT OUTPUT'),nl,
   79   halt.
   80
   81:- start.