/* Part of ClioPatria SeRQL and SPARQL server Author: Jan Wielemaker E-mail: J.Wielemaker@vu.nl WWW: http://www.swi-prolog.org Copyright (c) 2010-2018, University of Amsterdam, VU University Amsterdam All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ :- 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(Type, Value), 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 [