% This file is part of the Attempto Parsing Engine (APE). % Copyright 2008-2013, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). % % The Attempto Parsing Engine (APE) is free software: you can redistribute it and/or modify it % under the terms of the GNU Lesser General Public License as published by the Free Software % Foundation, either version 3 of the License, or (at your option) any later version. % % The Attempto Parsing Engine (APE) is distributed in the hope that it will be useful, but WITHOUT % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR % PURPOSE. See the GNU Lesser General Public License for more details. % % You should have received a copy of the GNU Lesser General Public License along with the Attempto % Parsing Engine (APE). If not, see http://www.gnu.org/licenses/. :- module(drs_to_html, [ drs_to_html/2, drs_to_html_nocontainer/2, header/2, header/1, footer/1 ]). /** Visualize a DRS using HTML and CSS @author Kaarel Kaljurand @version 2008-03-16 */ % Operators used in the DRS. :- op(400, fx, -). :- op(400, fx, ~). :- op(500, xfx, =>). :- op(500, xfx, v). % :- style_check(-atom). %% drs_to_html(+Drs:term, -DrsHtml:atom) is det. % % @param Drs is Attempto DRS % @param DrsHtml is the DRS formatted in HTML (with HTML header and footer) % drs_to_html(Drs, DrsHtml) :- copy_term(Drs, DrsCopy), ape_numbervars(DrsCopy, 0, _), DrsCopy = drs(Dom, Conds), header(Header), footer(Footer), with_output_to(atom(CondsHtml), format_condlist(Conds)), !, format(atom(DrsHtml), '~w
~W
~w
~w~n', [Header, Dom, [numbervars(true)], CondsHtml, Footer]). drs_to_html(_, 'ERROR'). %% drs_to_html_nocontainer(+Drs:term, -DrsHtml:atom) is det. % % @param Drs is Attempto DRS % @param DrsHtml is the DRS formatted in HTML % drs_to_html_nocontainer(Drs, DrsHtml) :- copy_term(Drs, DrsCopy), ape_numbervars(DrsCopy, 0, _), DrsCopy = drs(Dom, Conds), with_output_to(atom(CondsHtml), format_condlist(Conds)), !, format(atom(DrsHtml), '
~W
~w
~n', [Dom, [numbervars(true)], CondsHtml]). drs_to_html_nocontainer(_, 'ERROR'). %% format_condlist(+CondList:list) is det. % % @param CondList is a list of DRS conditions % format_condlist([]). format_condlist([Condition | CondList]) :- format_condition(Condition), format_condlist(CondList). %% format_condition(+Condition:term) is det. % % @param Condition is a DRS condition % format_condition(-drs(Dom, Conds)) :- !, format('
¬
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(~drs(Dom, Conds)) :- !, format('
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(can(drs(Dom, Conds))) :- !, format('
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(must(drs(Dom, Conds))) :- !, format('
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(should(drs(Dom, Conds))) :- !, format('
SHOULD
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(may(drs(Dom, Conds))) :- !, format('
MAY
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(question(drs(Dom, Conds))) :- !, format('
QUESTION
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(command(drs(Dom, Conds))) :- !, format('
COMMAND
~W
', [Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(Conds) :- is_list(Conds), !, format('
', []), format_condlist(Conds), format('
', []). format_condition(Label:drs(Dom, Conds)) :- !, format('
~W :
~W
', [Label, [numbervars(true)], Dom, [numbervars(true)]]), format_condlist(Conds), format('
', []). format_condition(drs(Dom1, Conds1) v drs(Dom2, Conds2)) :- !, format('
~W
', [Dom1, [numbervars(true)]]), format_condlist(Conds1), format('
~W
', [Dom2, [numbervars(true)]]), format_condlist(Conds2), format('
', []). format_condition(drs(Dom1, Conds1) => drs(Dom2, Conds2)) :- !, format('
~W
', [Dom1, [numbervars(true)]]), format_condlist(Conds1), format('
~W
', [Dom2, [numbervars(true)]]), format_condlist(Conds2), format('
', []). format_condition(Condition-Id) :- !, format('~W
', [Condition-Id, [numbervars(true)]]). format_condition(_, 'ERROR'). %% header(+Title:atom, -Header:atom) is det. %% header(-Header:atom) is det. % % @param Title is the content for the title-element in the HTML-header % @param Header is an HTML header % % Generate an HTML-header. % header(Header) :- header('', Header). header(Title, Header) :- with_output_to(atom(Header), format(' ~w ', [Title])). %% footer(-Footer:atom) is det. % % @param Footer is an HTML footer % % Generate an HTML-footer. % footer('\n').