1% This file is part of the Attempto Parsing Engine (APE).
    2% Copyright 2008-2013, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
    4% The Attempto Parsing Engine (APE) is free software: you can redistribute it and/or modify it
    5% under the terms of the GNU Lesser General Public License as published by the Free Software
    6% Foundation, either version 3 of the License, or (at your option) any later version.
    8% The Attempto Parsing Engine (APE) is distributed in the hope that it will be useful, but WITHOUT
    9% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
   10% PURPOSE. See the GNU Lesser General Public License for more details.
   12% You should have received a copy of the GNU Lesser General Public License along with the Attempto
   13% Parsing Engine (APE). If not, see http://www.gnu.org/licenses/.
   16:- module(drs_reverse, [drs_reverse/2]).   17
   18:- use_module(drs_ops).

Reverse a DRS

- Kaarel Kaljurand
- Tobias Kuhn
- 2008-05-13


 drs_reverse(+Drs:term, -DrsReversed:term) is det
Reverses all domains (lists of referents) and condition lists of the input DRS.
Drs- is an Attempto DRS
DrsReversed- is the DRS with its domain and conditions reversed
   37drs_reverse(drs([], []), drs([], [])) :- !.
   39drs_reverse(drs(Dom, Conds), drs(DomR, CondsR)) :-
   40	reverse(Dom, DomR),
   41	reverse(Conds, Conds1),
   42	conds_reverse(Conds1, CondsR).
 conds_reverse(+Conditions:list, -ConditionsReversed:list) is det
Reverses each condition in a list of conditions.
Conditions- is a list of conditions
ConditionsReversed- is a list of conditions reversed
   52conds_reverse([], []).
   54conds_reverse([First | Conds], [FirstR | CondsR]) :-
   55	condition_reverse(First, FirstR),
   56	conds_reverse(Conds, CondsR).
 condition_reverse(+Condition:term, -ConditionReversed:term) is det
If the input is a complex condition then reverses its component DRSs. If the input is an atomic condition then does nothing.
Condition- is a DRS condition
ConditionReversed- is the condition reversed
   67condition_reverse(Drs, DrsR) :-
   68	Drs =.. [Op, SubDrs],
   69	unary_drs_operator(Op),
   70	drs_reverse(SubDrs, SubDrsR),
   71	!,
   72	DrsR =.. [Op, SubDrsR].
   74condition_reverse(Drs, DrsR) :-
   75	Drs =.. [Op, SubDrs1, SubDrs2],
   76	binary_drs_operator(Op),
   77	drs_reverse(SubDrs1, SubDrs1R),
   78	drs_reverse(SubDrs2, SubDrs2R),
   79	!,
   80	DrsR =.. [Op, SubDrs1R, SubDrs2R].
   82condition_reverse([H|T], R) :-
   83	reverse([H|T], R1),
   84	conds_reverse(R1, R),
   85	!.
   87condition_reverse(Label:Drs, Label:DrsR) :-
   88	drs_reverse(Drs, DrsR),
   89	!.
   91condition_reverse(Cond, Cond)