View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Jan Wielemaker
    4    E-mail:        J.Wielemaker@cs.vu.nl
    5    WWW:           http://www.swi-prolog.org
    6    Copyright (C): 2014-2015, VU University Amsterdam
    7
    8    This program is free software; you can redistribute it and/or
    9    modify it under the terms of the GNU General Public License
   10    as published by the Free Software Foundation; either version 2
   11    of the License, or (at your option) any later version.
   12
   13    This program is distributed in the hope that it will be useful,
   14    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16    GNU General Public License for more details.
   17
   18    You should have received a copy of the GNU General Public
   19    License along with this library; if not, write to the Free Software
   20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
   21
   22    As a special exception, if you link this library with other files,
   23    compiled with a Free Software compiler, to produce an executable, this
   24    library does not by itself cause the resulting executable to be covered
   25    by the GNU General Public License. This exception does not however
   26    invalidate any other reasons why the executable file might be covered by
   27    the GNU General Public License.
   28*/
   29
   30:- module(swish_render_pic,
   31	  [ term_rendering//3			% +Term, +Vars, +Options
   32	  ,clauses//1
   33	  ]).   34:- use_module(library(apply)).   35:- use_module(library(lists)).   36:- use_module(library(option)).   37:- use_module(library(http/html_write)).   38:- use_module(library(http/term_html)).   39:- use_module(library(pascal)).   40:- use_module('../render').   41
   42:- register_renderer(pic, "Render a probabilistic constraint logic theory").

SWISH table renderer

Render table-like data. */

 term_rendering(+Term, +Vars, +Options)//
Renders Term as a table. This renderer recognises several representations of table-like data:
A list of terms of equal arity
A list of lists of equal length
To be done
- : recognise more formats
   59term_rendering(Term, _Vars, _Options) -->
   60	{is_list_of_clauses(Term)
   61	}, !,
   62	html(pre(\clauses(Term))).
   63
   64clauses([]) --> [].
   65clauses([HC|T]) -->
   66	{
   67	 numbervars(HC,0,_),
   68         HC=rule((H:-B),P),!
   69	},
   70	pic(H,B,P),
   71	clauses(T).
   72
   73pic(H,B,P)-->
   74  {
   75    format(atom(Prob),'~f ::~n',[P]),
   76    format(atom(I),'--->~n',[])},
   77  [Prob],
   78  conj(B),
   79  [I],
   80  head(H).
   81
   82head([])-->!,
   83  {format(atom(A),"false.~n~n",[])},
   84  [A].
   85
   86head([((+),Conj)])-->!,
   87  {format(atom(A),"",[])},
   88  [A],
   89  conj(Conj),
   90  {format(atom(B),".~n~n",[])},
   91  [B].
   92
   93head([((-),Conj)])-->!,
   94  {format(atom(A),"not(",[])},
   95  [A],
   96  conj(Conj),
   97  {format(atom(B),").~n~n",[])},
   98  [B].
   99
  100head([((+),Conj)|Rest])-->
  101  {format(atom(A),"",[])},
  102  [A],
  103  conj(Conj),
  104  {format(atom(B),"~n\\/~n",[])},
  105  [B],
  106  head(Rest).
  107
  108head([((-),Conj)|Rest])-->
  109  {format(atom(A),"not(",[])},
  110  [A],
  111  conj(Conj),
  112  {format(atom(B),")\\/",[])},
  113  [B],
  114  head(Rest).
  115
  116conj([])-->
  117  {format(atom(A),"true",[])},
  118  [A].
  119
  120conj([H])-->
  121  {format(atom(A),"~q",[H])},!,
  122  [A].
  123
  124conj([H|T])-->
  125  {format(atom(A),"~q/\\",[H])},
  126  [A],
  127  conj(T).
 is_list_of_terms(@Term, -Rows, -Cols) is semidet
Recognises a list of terms with the same functor and non-zero ariry.
  139is_list_of_clauses(Term) :-
  140	is_list(Term), Term \== [],
  141	maplist(is_clause, Term).
  142
  143is_clause(rule((_H :- _B),_)).
 is_list_of_lists(@Term, -Rows, -Cols) is semidet
Recognise a list of lists of equal length.
  149is_list_of_lists(Term, Rows, Cols) :-
  150	is_list(Term), Term \== [],
  151	length(Term, Rows),
  152	maplist(is_list_row(Cols), Term),
  153	Cols > 0.
  154
  155is_list_row(Length, Term) :-
  156	is_list(Term),
  157	length(Term, Length)