/* Part of ClioPatria SeRQL and SPARQL server Author: Jan Wielemaker E-mail: J.Wielemaker@cs.vu.nl WWW: http://www.swi-prolog.org Copyright (C): 2010, University of Amsterdam, VU University Amsterdam This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA As a special exception, if you link this library with other files, compiled with a Free Software compiler, to produce an executable, this library does not by itself cause the resulting executable to be covered by the GNU General Public License. This exception does not however invalidate any other reasons why the executable file might be covered by the GNU General Public License. */ :- module(cp_label, [ turtle_label//1, % +Literal rdf_link//1, % +RDFTerm rdf_link//2, % +RDFTerm, +Options resource_link/2 % +URI, -URL ]). :- use_module(library(error)). :- use_module(library(option)). :- use_module(library(sgml)). :- use_module(library(sgml_write)). :- use_module(library(aggregate)). :- use_module(library(semweb/rdf_db)). :- use_module(library(semweb/rdf_label)). :- use_module(library(http/html_write)). :- use_module(library(http/http_dispatch)). :- if(exists_source(library(semweb/rdf11))). :- use_module(library(semweb/rdf11), [rdf_lexical_form/2]). :- endif. :- use_module(cliopatria(hooks)). /** Support for showing labels This module provides HTML components to display labels for resources. @see library(semweb/rdf_label) returns textual labels. */ %% turtle_label(+RDFTerm)// is det. % % HTML rule to emit an RDF term (resource or object) in % turtle-like notation with CSS classes. % % @tbd Implement possibility for a summary. turtle_label(R) --> turtle_label(R, []). turtle_label(R, _) --> { atom(R), rdf_global_id(NS:Local, R), ! }, html([span(class(prefix), NS), ':', span(class(local), Local)]). turtle_label(R, Options) --> { atom(R), rdf_display_label(R, Lang, LabelText), Lang \== url, LabelText \== '', truncate_text(LabelText, Show, Options) }, html(Show). turtle_label(R, Options) --> { rdf_is_bnode(R) }, bnode_label(R, Options), !. turtle_label(R, _) --> { atom(R) }, !, html(['<',R,'>']). turtle_label(literal(Lit), Options) --> !, literal_label(Lit, Options). turtle_label(@(String,Lang), Options) --> !, literal_label(lang(Lang, String), Options). :- if(current_predicate(rdf_lexical_form/2)). turtle_label(^^(Value,Type), Options) --> !, ( {rdf_equal(Type, xsd:string)} -> literal_label(type(Value, Type), Options) ; {rdf_lexical_form(^^(Value,Type), ^^(String,_))}, literal_label(type(Type, String), Options) ). :- endif. literal_label(type(Type, Value), Options) --> !, { truncate_text(Value, Show, Options) }, html(span(class(literal), [span(class(oquote), '"'), span(class(l_text), Show), span(class(cquote), '"'), span(class(l_type), '^^'), \turtle_label(Type)])). literal_label(lang(Lang, Value), Options) --> !, { truncate_text(Value, Show, Options) }, html(span(class(literal), [span(class(oquote), '"'), span(class(l_text), Show), span(class(cquote), '"'), span(class(l_lang), '@'), span(class(lang), Lang)])). literal_label(Value, Options) --> { truncate_text(Value, Show, Options) }, html(span(class(literal), [span(class(oquote), '"'), span(class(l_text), Show), span(class(cquote), '"')])). truncate_text(Text, Text, []) :- !. truncate_text(Text, Truncated, Options) :- option(max_length(Len), Options), !, truncate_atom(Text, Len, Truncated). truncate_text(Text, Text, _). %% bnode_label(+Resource, +Options)// is semidet. % % Display an HTML label for an RDF blank node. This DCG rules % first calls the hook cliopatria:bnode_label//1. On failure % performs its default task: % % * If the bnode has an rdf:value, display the label thereof % with [