/* This file is part of ClioPatria. Author: HTTP: http://e-culture.multimedian.nl/ GITWEB: http://gollem.science.uva.nl/git/ClioPatria.git GIT: git://gollem.science.uva.nl/home/git/ClioPatria.git GIT: http://gollem.science.uva.nl/home/git/ClioPatria.git Copyright: 2007, E-Culture/MultimediaN ClioPatria 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. ClioPatria 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 ClioPatria. If not, see . */ :- module(iface_util, [ iface_resource_values/3, % +URI, +Properties, -Values iface_resource_values/5, % +EMap, +QMap, +URI, +Properties, -Values iface_resource_properties/3, % +URI, +Properties, -Pairs iface_resource_properties/4, % +URI, +Properties, -Pairs, +Options iface_key_resource_graph/4, % +URIList, +Pairs, -Graph, +Options iface_subject_graph/3, % +URI, -Graph, +Options iface_object_graph/3, % +Resource, -Graph, +Options iface_predicate_graph/3, % +URI, -Graph, +Options iface_graph_extend/5, % +URIs, +Ps, +GraphIn, -GraphOut, +Options iface_graph_add_properties/6, % +URIs, +Ps, +GraphIn, +ExtMap, +QueryMap, -GraphOut iface_language_filter/3, % +GraphIn, +LanguageList, -GraphOut iface_used_namespaces/2, % +Graph, -Namespace iface_has/3, % ?Subject, ?Predicate, ?Object iface_has/6, % +ExtMap, +QueryMap, ?Subject, ?Predicate, ?Object, -RealP iface_pref_value/3, % ?Subject, -Predicate, -Object iface_pref_value/6, % +ExtMap, +QueryMap, ?Subject, ?Predicate, ?Object, -RealP iface_literal_value/3, % ?Subject, -Predicate, -Literal iface_literal_value/6, % +ExtMap, +QueryMap, ?Subject, ?Predicate, ?Literal, -RealP iface_pref_literal_value/3, % ?Subject, -Predicate, -Literal iface_pref_literal_value/6, % +ExtMap, +QueryMap, ?Subject, ?Predicate, ?Literal, -RealP iface_label/2, % +Resource, -Label iface_label/4, % +ExtMap, +QueryMap, +Resource, -Label iface_match_label/3, % +Resource, +Match, -Label iface_match_label/5, % +ExtMap, +QueryMap, +Resource, +Match, -Label iface_class_of/2, % +Resource, -Class iface_class_of/4, % +ExtMap, +QueryMap, +Resource, -Class iface_symbol_of/2, % +URI, -Symbol iface_thumbnail/2, % +Resource, -ThumbnailURL iface_image/2, % +Resource, -ImageURL iface_video/2, % +Resource, -VideoURL iface_description/2, % +Resource, -Txt iface_abbreviation/2, % +Resource, -Txt iface_table_property/2, % +Class, -Property iface_pref_property/2, % +Property, -Preferred iface_abstract_predicate/2, % +Predicate, -Abstract iface_abstract_class/2, % +Class, -Abstract iface_concept/1 % ?Resource ]). :- use_module(library(semweb/rdf_db)). :- use_module(library(semweb/rdfs)). :- use_module(library(semweb/rdf_label)). :- use_module(library(http/http_dispatch)). :- use_module(library(error)). :- use_module(library(count)). :- use_module(library(settings)). :- use_module(rdfs_plus_skos). :- use_module(api(media_caching)). :- rdf_register_prefix(iface, 'http://e-culture.multimedian.nl/ns/interface/'). :- rdf_meta iface_subject_graph(r, -, +), iface_object_graph(r, -, +), iface_predicate_graph(r, -, +), iface_has(r,r,o), iface_has(+,+,r,r,o,-), iface_pref_value(r,r,-), iface_pref_value(+,+,r,r,-,_), iface_literal_value(r,r,o), iface_literal_value(+,+,r,r,o,-), iface_pref_literal_value(r,r,o), iface_pref_literal_value(+,+,r,r,o,-), iface_resource_values(r,t,-), iface_resource_values(+,+,r,t,-), iface_class_of(r,-), iface_pref_property(r,r). :- discontiguous term_expansion/2. :- multifile english_language_tag/1. :- if(current_setting(user:lang)). % do nothing :- else. :- setting(user:lang, atom, en, 'Preferred language'). :- endif. /****************************** * value lists * ******************************/ %% iface_resource_values(+URI, +Ps, -Values). %% iface_resource_values(+URI, +Ps, -Values, +Options). % % Values contains the values of all properties in Ps for URI. % By default rdf_has is used unless options are specified: iface_resource_values(URI, Ps0, Vs) :- rdf_global_term(Ps0, Ps), iface_resource_values_(Ps, 0, 0, URI, Vs). iface_resource_values(EMap, QMap, URI, Ps0, Vs) :- rdf_global_term(Ps0, Ps), iface_resource_values_(Ps, EMap, QMap, URI, Vs). iface_resource_values_([], _, _, _, []) :- !. iface_resource_values_([P|Ps], EMap, QMap, URI, [V|Vs]) :- iface_has(EMap, QMap, URI, P, V, _), !, iface_resource_values_(Ps, EMap, QMap, URI, Vs). iface_resource_values_([_|Ps], EMap, QMap, URI, Vs) :- iface_resource_values_(Ps, EMap, QMap, URI, Vs). %% iface_resource_properties(+URI, +Ps, -Pairs). %% iface_resource_properties(+URI, +Ps, -Pairs, +Options). % % Pairs contains a key=value pair for each element from Ps. % Ps is either a list of properties in which case key is a property, % or Ps is a list of property-key pairs in which case property is used % to get the value and key is returned with the value. % % @see iface_resource_values iface_resource_properties(R, Ps0, Pairs) :- rdf_global_term(Ps0, Ps), iface_resource_properties_(Ps, 0, 0, R, Pairs). iface_resource_properties(R, Ps0, Pairs, Options) :- rdf_global_term(Ps0, Ps), resource_ext_map(Options, EMap), query_ext_map(Options, QMap), iface_resource_properties_(Ps, EMap, QMap, R, Pairs). iface_resource_properties_([], _, _, _, []). iface_resource_properties_([P0|Ps], EMap, QMap, R, [Key=V|Pairs]) :- ( P0 = P-Key -> iface_has(EMap, QMap, R, P, O, _) ; iface_has(EMap, QMap, R, P0, O, _), Key = P0 ), !, object_value(O, V), iface_resource_properties_(Ps, EMap, QMap, R, Pairs). iface_resource_properties_([_|Ps], EMap, QMap, R, Pairs) :- iface_resource_properties_(Ps, EMap, QMap, R, Pairs). iface_key_resource_graph(Rs, Ps0, Graph, Options) :- rdf_global_term(Ps0, Ps), resource_ext_map(Options, EMap), query_ext_map(Options, QMap), findall(rdf(R,Key,V), ( member(R, Rs), member(P-Key, Ps), iface_has(EMap, QMap, R,P,V, _) ), Graph ). object_value(literal(L), Txt) :- !, literal_text(L, Txt). object_value(L, L) :- is_list(L), !. object_value(R, Txt) :- rdf_subject(R), !, iface_label(R, Txt). object_value(R, R). /****************************** * graphs * ******************************/ %% iface_subject_graph(+URIs, -Graph, +Options) % % The "description graph" contains all triples/quads % with URI as the subject. % % Options is a list of: % % * predicate(+Predicate) % restrict to objects of Predicate (no subPropertyOf) % % * lens(+Lens) % restrict to properties of Lens. % if Lens==true a lens matching the resource type chosen. % if Lens is an RDF lens this is used directly. % % * max(+Number) % Maximum number of triples per property % % * src(+Boolean) % Include src of the triples % If true, Graph will contain quads % % * bnode_expand(+Boolean) % Include triples of blank nodes % % * rdfs_plus_skos(+List) % @see rdfs_plus_skos/6 iface_subject_graph(R, Graph, Options) :- option(predicate(P), Options), P \== [], ( is_list(P) -> Ps = P ; nonvar(P) -> Ps = [P] ), !, iface_subject_graph(R, Ps, Graph, Options). iface_subject_graph(R, Graph, Options) :- option(lens(Lens0), Options), ( Lens0 == true -> iface_resource_lens(R, Lens) ; rdfs_individual_of(Lens0, iface:'Lens') -> Lens = Lens0 ), iface_lens_properties(Lens, Ps), !, iface_lens_options(Lens, Options, Options1), iface_subject_graph(R, Ps, Graph, Options1). iface_subject_graph(R, Graph, Options) :- ( is_list(R) -> Rs = R ; Rs = [R] ), findall(P, (member(U,Rs),rdf(U,P,_)), Ps0), sort(Ps0, Ps), iface_subject_graph(R, Ps, Graph, Options). iface_subject_graph(R, Ps, Graph, Options) :- ( is_list(R) -> Rs = R ; Rs = [R] ), option(rdfs_plus_skos(Reasoning), Options, []), resource_ext_map(Reasoning, EMap), query_ext_map(Reasoning, QMap), option(src(Src), Options, false), option(max(Max), Options, inf), findall(Edge, ( member(S,Rs), member(P, Ps), edges(EMap, QMap, Src, P, S, _, Max, Edges), member(Edge0, Edges), iface_edge_object_expand(EMap, Edge0, Edge) ), Graph0), ( option(bnode_expand(true), Options) -> expand_bnodes(Graph0, Graph, Options) ; Graph = Graph0 ). expand_bnodes(Graph, ExpandedGraph, Options) :- findall(Bnode, (member(rdf(_S,_P,Bnode,_G), Graph), rdf_is_bnode(Bnode) ), Bnodes), (Bnodes = [] -> ExpandedGraph = Graph ; iface_subject_graph(Bnodes, Graph0, Options), expand_bnodes(Graph0, ExpandedBnodes, Options), append(Graph, ExpandedBnodes,ExpandedGraph) ), true. %% iface_object_graph(+URIs, -Graph, +Options) % % Graph contains all triples with URI as an object. % % Options see iface_subject_graph/3. iface_object_graph(R, Graph, Options) :- option(predicate(P), Options, _), P \== [], ( is_list(P) -> Ps = P ; nonvar(P) -> Ps = [P] ), iface_object_graph(R, Ps, Graph, Options). iface_object_graph(R, Graph, Options) :- ( is_list(R) -> Rs = R ; Rs = [R] ), findall(P, (member(U,Rs),rdf(_,P,U)), Ps0), sort(Ps0, Ps), iface_object_graph(R, Ps, Graph, Options). iface_object_graph(R, Ps, Graph, Options) :- resource_ext_map(Options, EMap), query_ext_map(Options, QMap), option(max(Max), Options, inf), option(src(Src), Options, false), findall(Edge, ( member(P, Ps), edges(EMap, QMap, Src, P, _, R, Max, Edges), member(Edge, Edges) ), Graph). %% iface_predicate_graph(+URI, -Graph, +Options) % % Graph contains all triples with URI as an object. % % Options see iface_subject_graph/4. iface_predicate_graph(P, Graph, Options) :- resource_ext_map(Options, EMap), query_ext_map(Options, QMap), option(max(Max), Options, inf), option(src(Src), Options, false), edges(EMap, QMap, Src, P, _, _, Max, Graph). %% iface_graph_add_properties(+GraphIn, +Rs, +Ps, -GraphOut, +Options) % % Extend graph with new triples about Rs according to Ps. iface_graph_extend(GraphIn, Rs, Ps, GraphOut, Options) :- resource_ext_map(Options, EMap), query_ext_map(Options, QMap), iface_graph_add_properties(Rs, Ps, GraphIn, EMap, QMap, GraphOut). iface_graph_add_properties([], _, Graph, _, _, Graph) :- !. iface_graph_add_properties([S|Ss], Ps, Graph0, EMap, QMap, Graph) :- atom(S), !, iface_add_properties(Ps, S, Graph0, EMap, QMap, Graph1), iface_graph_add_properties(Ss, Ps, Graph1, EMap, QMap, Graph). iface_graph_add_properties([_|Ss], Ps, Graph0, EMap, QMap, Graph) :- iface_graph_add_properties(Ss, Ps, Graph0, EMap, QMap, Graph). iface_add_properties([], _, Graph, _, _, Graph) :- !. iface_add_properties([P|Ps], S, Graph0, EMap, QMap, Graph) :- iface_has(EMap, QMap, S, P, V, RealP), !, iface_add_properties(Ps, S, [rdf(S,RealP,V)|Graph0], EMap, QMap, Graph). iface_add_properties([_|Ps], S, Graph0, EMap, QMap, Graph) :- iface_add_properties(Ps, S, Graph0, EMap, QMap, Graph). /****************************** * edges * ******************************/ %% edges(+EMap, +QMap, +GetSrc, +P, ?S, ?O, +Max,-Edges) % % Edges contains all edges over P with a maximum of % Max. edges(EMap, QMap, Src, P, S, O, Max, Edges) :- answer_set(Edge, iface_edge(EMap,QMap,Src,P,S,O,Edge), Max, Edges). %% iface_edge(+EMap, +QMap, +SrcBool, +P, ?S, ?O, -Edge) % % Edge is a triple or quad unifying S,P,O with a triple in the graph. % % * EMap and QMap indicate the rdfs_plus_skos reasoning @see % rdfs_plus_skos/5 iface_edge(EMap, QMap, SrcBool, P, S, O, Edge) :- rdfs_plus_skos(EMap, QMap, S, P, O, _,RealP,_), ( SrcBool, rdf(S,RealP,O,Src) -> Edge = rdf(S,P,O,Src) ; Edge = rdf(S,P,O) ). %% iface_edge_object_expand(+ExtMap, +EdgeIn, -EdgeOut) % % Edge is rdf(S,P,O) or an expandsion thereof. % % Currently we only expand if there is no triple source. iface_edge_object_expand(EMap, rdf(S,P,O0), rdf(S,P,O)) :- !, representative(EMap, O0, O1), ( % @TBD test for rdf_value rdf_has(O1,rdf:value,O) -> true ; O = O1 ). iface_edge_object_expand(_, Edge, Edge). /****************************** * rdf graph operations * ******************************/ %% iface_language_filter(+GraphIn, +LanguageList, -GraphOut) % % GraphOut contains all triples except those with a % language not in LanguageList. % % Do we want to filter out literals without a language tag ? iface_language_filter([], _, []). iface_language_filter([Triple|Ts], LangList, Rest) :- literal_language(Triple, L), \+ memberchk(L, LangList), !, iface_language_filter(Ts, LangList, Rest). iface_language_filter([Triple|Ts], LangList, [Triple|Rest]) :- iface_language_filter(Ts, LangList, Rest). literal_language(rdf(_,_,literal(lang(L0, _))), L) :- sub_atom(L0,0,2,_,L). literal_language(rdf(_,_,literal(lang(L0, _)),_), L) :- sub_atom(L0,0,2,_,L). %% iface_used_namespaces(+Graph, -Namespaces) % % Namespaces is a list of unique namespaces used in Graph. iface_used_namespaces(Graph, List) :- findall(Ns, ( rdf_triple(Graph, S,P,O), triple_ns(S,P,O, Ns) ), List0), sort(List0, List). triple_ns(R,_,_,Ns) :- \+ rdf_is_bnode(R), rdf_url_namespace(R, Ns). triple_ns(_,R,_,Ns) :- \+ rdf_is_bnode(R), rdf_url_namespace(R, Ns). triple_ns(_,_,R,Ns) :- atom(R), \+ rdf_is_bnode(R), rdf_url_namespace(R, Ns). rdf_triple(Graph, S,P,O) :- member(rdf(S, P, O), Graph). rdf_triple(Graph, S,P,O) :- member(rdf(S, P, O,_), Graph). /****************************** * rdf_has variants * ******************************/ %% iface_has(?S, ?P, ?O). %% iface_has(+EMap, QMap, ?S, ?P, ?O, ?RealP). % % As rdfs_plus_skos/5, but also try interface:edge/5 iface_has(S,P,O) :- iface_has(0, 0, S, P, O, _). iface_has(EMap, QMap, S, P, O, RealP) :- ( var(P) -> true; atom(P) ), rdfs_plus_skos(EMap, QMap, S, P, O, _, RealP, _). iface_has(EMap, QMap, S, P, O, P) :- interface:edge(P, EMap, QMap, S, O). %% iface_pref_value(?S, ?P, ?O). %% iface_pref_value(+EMap, +QMap, ?S, ?P, ?O, -RealP) % % As rdfs_plus_skos/5, but first tries a preferred subproperty. % % @TBD exlcude preferred property values in second clause iface_pref_value(S, P, V) :- iface_pref_value(0, 0, S, P, V, _). iface_pref_value(EMap, QMap, S, P, O, RealP) :- iface_pref_property(P, PrefP), rdfs_plus_skos(EMap, QMap, S, PrefP, O, _,RealP,_). iface_pref_value(EMap, QMap, S, P, O, RealP) :- rdfs_plus_skos(EMap, QMap, S, P, O, _,RealP,_). %% iface_literal_value(?S, ?P, ?Literal). %% iface_literal_value(+EMap, +QMap, ?S, ?P, ?Literal, ?RealP). % % Succeeds if the triple Subject,Predicate,Literal exists, % but first tries % % 1. literals in user language % 2. literals in english % 3. any language iface_literal_value(S, P, L) :- iface_literal_value(0, 0, S, P, L, _). iface_literal_value(EMap, QMap, S, P, literal(lang(Lang, L)), RealP) :- setting(user:lang, Lang), rdfs_plus_skos(EMap, QMap, S, P, literal(lang(Lang, L)), _,RealP,_). iface_literal_value(EMap, QMap, S, P, literal(lang(En, L)), RealP) :- english_language_tag(En), rdfs_plus_skos(EMap, QMap, S, P, literal(lang(En, L)), _,RealP,_). iface_literal_value(EMap, QMap, S, P, literal(L), RealP) :- rdfs_plus_skos(EMap, QMap, S, P, literal(L), _,RealP,_). %% iface_pref_literal_value(?S, ?P, ?Literal). %% iface_pref_literal_value(+EMap, +QMap, ?Subject, ?Predicate, ?Literal, ?RealP). % % Succeeds if the triple Subject,Predicate,Literal exists, % but first tries % % preferred property with user language % any property with user language % preferred property with english % any property with english % preferred property with any language % any property with any language iface_pref_literal_value(S, P, L) :- setting(user:lang, Lang), iface_pref_literal_value(0, 0, Lang, S, P, L, _). iface_pref_literal_value(EMap, QMap, S, P, L, RealP) :- setting(user:lang, Lang), iface_pref_literal_value(EMap, QMap, Lang, S, P, L, RealP). iface_pref_literal_value(EMap, QMap, Lang, S, P, literal(lang(Lang, L)), RealP) :- iface_pref_property(P, PrefP), rdfs_plus_skos(EMap, QMap, S, PrefP, literal(lang(Lang, L)), _,RealP,_). iface_pref_literal_value(EMap, QMap, Lang, S, P, literal(lang(Lang, L)), RealP) :- rdfs_plus_skos(EMap, QMap, S, P, literal(lang(Lang, L)), _,RealP,_). iface_pref_literal_value(EMap, QMap, Lang, S, P, literal(lang(En, L)), RealP) :- english_language_tag(En), Lang \== En, ( iface_pref_property(P, PrefP), rdfs_plus_skos(EMap, QMap, S, PrefP, literal(lang(En, L)), _,RealP,_) ; rdfs_plus_skos(EMap, QMap, S, P, literal(lang(En, L)), _,RealP,_) ). iface_pref_literal_value(EMap, QMap, _Lang, S, P, literal(L), RealP) :- iface_pref_property(P, PrefP), rdfs_plus_skos(EMap, QMap, S, PrefP, literal(L), _,RealP,_). iface_pref_literal_value(EMap, QMap, _Lang, S, P, literal(L), RealP) :- rdfs_plus_skos(EMap, QMap, S, P, literal(L), _,RealP,_). /****************************** * interface properties * ******************************/ %% iface_resource_lens(+R, ?Lens) % % Lens applies to R. iface_resource_lens(R, Lens) :- rdfs_individual_of(R, Class), rdf(Lens, iface:lensType, Class). %% iface_lens_properties(+Lens, -Properties) % % Properties is a list of lensProperties accociated with Lens. iface_lens_properties(Lens, Ps) :- rdf(Lens, iface:lensProperty, List), rdfs_list_to_prolog_list(List, Ps), !. iface_lens_properties(Lens, Ps) :- findall(P, rdf(Lens, iface:lensProperty, P), Ps), Ps \== []. %% iface_lens_options(Lens, Options0, Options) iface_lens_options(Lens, Options0, Options) :- findall(Q, rdf(Lens, iface:reasoning, literal(Q)), QL), QL \== [], !, ( select_option(rdfs_plus_skos(Q0), Options0, Options1) -> union(QL, Q0, Q), Options = [rdfs_plus_skos(Q)|Options1] ; Options = [rdfs_plus_skos(QL)|Options0] ). iface_lens_options(_, Options, Options). %% iface_label(+Resource, -Label). %% iface_label(+EMap, +QMap, +Resource, -Label) % % Label is the the prefered display label of Resource iface_label(R, Label) :- iface_label(0, 0, R, L), literal_text(L, Label). iface_label(_, _, literal(L), literal(L)) :- !. iface_label(EMap, QMap, R, Label) :- setting(user:lang, Lang), iface_pref_lang_label(EMap, QMap, R, Lang, Label), !. iface_label(EMap, QMap, R, Label) :- english_language_tag(En), iface_pref_lang_label(EMap, QMap, R, En, Label), !. iface_label(EMap, QMap, R, Label) :- ( rdfs_plus_skos(EMap, QMap, R, iface:prefLabel, O) -> true ; rdfs_plus_skos(EMap, QMap, R, rdfs:label, O) ), iface_label(EMap, QMap, O, Label), !. iface_label(EMap, QMap, R, Label) :- rdf(R, rdf:value, Value), iface_label(EMap, QMap, Value, Label), !. iface_label(_, _, R, Label) :- atom(R), rdf_split_url(_, Label1, R), ( Label1 = '' -> Label=R ; Label=Label1 ). iface_pref_lang_label(EMap, QMap, R, Lang, L) :- ( rdfs_plus_skos(EMap, QMap, R, iface:prefLabel, literal(lang(Lang,L))) -> true ; rdfs_plus_skos(EMap, QMap, R, rdfs:label, literal(lang(Lang,L))) ). %% iface_match_label(+R, +Match, -Label). %% iface_match_label(+EMap, +QMap, +R, +Match, -Label). % % Label is a label of R and matches with Kwd. iface_match_label(R, Match, Label) :- iface_match_label(0, 0, R, Match, Label). iface_match_label(EMap, QMap, R, Match, Label) :- concat_atom(['*',Match,'*'], RegExp), label_property(P), iface_has(EMap, QMap, R, P, literal(like(RegExp), Lit), _), !, literal_text(Lit, Label). iface_match_label(EMap, QMap, R, _Query, Label) :- iface_label(EMap, QMap, R, Label). %% iface_match_literal(+R, +Match, -Txt). %% iface_match_literal(+EMap, +QMap, +R, +Match, -Txt). % % Txt is a literal metadata property of R and matches with Kwd. iface_match_literal(R, Match, Label) :- iface_match_literal(0, 0, R, Match, Label). iface_match_literal(EMap, QMap, R, Match, Label) :- concat_atom(['*',Match,'*'], RegExp), iface_has(EMap, QMap, R, _, literal(like(RegExp), Lit), _), literal_text(Lit, Label). rdf_label:label_property(P) :- rdf_equal(iface:prefLabel, P). rdf_label:label_property(P) :- rdf_equal(rdfs:label, P). %% iface_class_of(+Resource, ?Class). %% iface_class_of(+Type, +Resource, -Class). % % Class is the interface class of Resource. iface_class_of(Resource, Class) :- iface_class_of(0, 0, Resource, Class). iface_class_of(_, _, Resource, _) :- var(Resource), !, instantiation_error(Resource). iface_class_of(_, _, literal(_), C) :- rdf_equal(C, rdfs:'Literal'), !. iface_class_of(EMap, QMap, Resource, Class) :- rdfs_plus_skos(EMap, QMap, Resource, rdf:type, Class0), rdf_reachable(Class0, rdfs:subClassOf, Class), rdf(Class, rdf:type, iface:'Class'), !. iface_class_of(_, _, _Resource, RestClass) :- rdf_equal(iface:'RestClass', RestClass). %% iface_symbol_of(+Resource, -Symbol). %% iface_symbol_of(+EMap, +QMap, +Resource, -Symbol). % % Symbol is the URI of an image that depicts Resource. % Uses iface:depictedBy or the inverse iface:depicts. % Add Mappings to these relations to add more properties. iface_symbol_of(Resource, Symbol) :- iface_symbol_of(0, 0, Resource, Symbol). iface_symbol_of(EMap, QMap, Resource, Symbol) :- rdfs_plus_skos(EMap, QMap, Resource, iface:prefDepictedBy, Symbol). iface_symbol_of(EMap, QMap, Resource, Symbol) :- rdfs_plus_skos(EMap, QMap, Symbol, iface:prefDepicts, Resource). iface_symbol_of(EMap, QMap, Resource, Symbol) :- rdfs_plus_skos(EMap, QMap, Resource, iface:depictedBy, Symbol). iface_symbol_of(EMap, QMap, Resource, Symbol) :- rdfs_plus_skos(EMap, QMap, Symbol, iface:depicts, Resource). %% is_image(+Resource) % % Resource is of type Image. is_image(Resource) :- rdfs_individual_of(Resource, iface:'Image'), !. %% is_video(+Resource) % % Resource is of type Video. is_video(Resource) :- rdfs_individual_of(Resource, iface:'Video'), !. %% iface_image(+Resource, -Image) % % Same as iface_thumbnail with Image at full size iface_image(R, Image) :- iface_image(0, 0, R, Image). iface_image(_, _, Resource, Image) :- is_image(Resource), !, image_url(Resource, Image). iface_image(EMap, QMap, Resource, Image) :- iface_symbol_of(EMap, QMap, Resource, Symbol), \+ is_video(Symbol), image_url(Symbol, Image). %% iface_thumbnail(+Resource, -Thumbnail) % % Thumbnail is the url of an image depicting Resource. iface_thumbnail(R, Thumbnail) :- iface_thumbnail(0, 0, R, Thumbnail). iface_thumbnail(_, _, Resource, Thumbnail) :- is_image(Resource), !, thumbnail_url(Resource, Thumbnail). iface_thumbnail(EMap, QMap, Resource, Thumbnail) :- iface_symbol_of(EMap, QMap, Resource, Symbol), \+ is_video(Symbol), thumbnail_url(Symbol, Thumbnail). %% iface_video(+Resource, -Video) % % Video is about Resource. iface_video(R, Video) :- iface_video(0, 0, R, Video). iface_video(_, _, Video, Video) :- is_video(Video), !. iface_video(EMap, QMap, Resource, Video) :- iface_symbol_of(EMap, QMap, Resource, Video), is_video(Video). %% iface_description(+Resource, -Description) % % Description is a literal description of Resource % Uses iface:description Add Mappings to this relation to use % domain specific property. iface_description(R, Description) :- iface_description(0, 0, R, Description). iface_description(EMap, QMap, Resource, Description) :- iface_pref_literal_value(EMap, QMap, Resource, iface:description, Description, _). %% iface_abbreviation(+Resource, -Txt) % % Show short label of Resource. iface_abbreviation(Resource, Abbreviation) :- iface_abbreviation(0, 0, Resource, Abbreviation). iface_abbreviation(EMap, QMap, Resource, Abbreviation) :- iface_pref_literal_value(EMap, QMap, Resource, iface:abbreviation, Abbreviation, _). %% iface_pref_property(+Property, -Preferred) % % Succeeds if Preferred is defined as a preferred property of % Property. iface_pref_property(P, Preferred) :- rdf(P, iface:hasPreferred, Preferred), !. iface_pref_property(P, Preferred) :- rdf(Preferred, iface:preferredOf, P). %% iface_table_property(+Class, -Property) % % Property is defined as iface:tableProperty for Class. iface_table_property(Class, Property) :- rdfs_subclass_of(SC, Class), rdf(SC, iface:tableProperty, Property). %% iface_abstract_property(+Property, -Abstract) is det. % % True if Abstract is a high-level property for Property. iface_abstract_predicate(P, AP) :- atom(P), rdf_reachable(P, rdfs:subPropertyOf, AP), iface_predicate(AP), !. iface_abstract_predicate(P, P). %iface_predicate(P) :- % catch(cliopatria:iface_predicate(P), _, fail), !. iface_predicate(P) :- rdfs_individual_of(P, iface:'Property'). %% iface_abstract_class(+Class, -Abstract) is det. % % True if Abstract is a high-level class for Class. iface_abstract_class(Resource, Class) :- class_of(Resource, Class0), abstract_class(Class0, Class). abstract_class(Class, AClass) :- rdfs_subclass_of(Class, AClass), iface_class(AClass), Class \== AClass. abstract_class(Class, Class). %% class_of(+ResourceOrLiteral, -Class:atom) is det. % % Class is the class of ResourceOrLiteral. Returns rdfs:Literal if % ResourceOrLiteral is a literal and rdfs:Resource if % ResourceOrLiteral has no explicit class. % % Added by MH % The preferred class is an interface class (iface:Class) class_of(literal(_), C) :- !, rdf_equal(C, rdfs:'Literal'). class_of(Resource, Class) :- rdf(Resource, rdf:type, Class0), rdf_reachable(Class0, rdfs:subClassOf, Class), rdf(Class, rdf:type, iface:'Class'), !. class_of(O, C) :- rdf_has(O, rdf:type, C), !. class_of(_, Resource) :- rdf_equal(Resource, rdfs:'Resource'). %iface_class(Class) :- % catch(cliopatria:iface_class(Class), _, fail), !. iface_class(Class) :- rdfs_individual_of(Class, iface:'Class'). %% iface_concept(+Resource) is semidet. % % True if Resource is a concept from some thesaurus. If the % meta-modelling is correct, using skos:Concept should suffice % here. This is used by concept_of/2. iface_concept(Resource) :- atom(Resource), rdfs_individual_of(Resource, skos:'Concept'), %cliopatria:is_concept(Resource), !. /****************************** * predefined edges * ******************************/ :- setting(result:sublabel, uri, dc:creator, 'RDF property used for sublabel'). :- setting(result:format, oneof([thumbnail,snippet]), thumbnail, 'Format of result'). :- multifile interface:edge/5. :- rdf_meta edge(r,+,o), edge(+,+,r,+,o). interface:edge(S, P, O) :- interface:edge(0, 0, S, P, O). interface:edge(label, EMap, QMap, S, O) :- iface_label(EMap, QMap, S, O). interface:edge(matchLabel(Kwd), EMap, QMap, S, O) :- iface_match_label(EMap, QMap, S, Kwd, O). interface:edge(matchLiteral(Kwd), EMap, QMap, S, O) :- iface_match_literal(EMap, QMap, S, Kwd, O). interface:edge(sublabel, EMap, QMap, S, O) :- setting(result:sublabel, Property), rdfs_plus_skos(EMap, QMap, S, Property, R), interface:edge(label, EMap, QMap, R, O). interface:edge(labels, EMap, QMap, S, Os) :- findall(O, rdfs_plus_skos(EMap, QMap, S, rdfs:label, O), Os). interface:edge(prefLabel, EMap, QMap, S, O) :- iface_literal_value(EMap, QMap, S, iface:prefLabel, O, _). interface:edge(altLabel, EMap, QMap, S, O) :- iface_literal_value(EMap, QMap, S, iface:altLabel, O, _). interface:edge(altLabels, EMap, QMap, S, Os) :- findall(O, rdfs_plus_skos(EMap, QMap, S, iface:altLabel, O), Os). interface:edge(description, EMap, QMap, S, O) :- iface_pref_literal_value(EMap, QMap, S, iface:description, O, _). interface:edge(abbreviation, EMap, QMap, S, O) :- rdfs_plus_skos(EMap, QMap, S, iface:abbreviation, O). interface:edge(alias, _, _, S, literal(Alias)) :- rdf_global_id(Alias:_Local, S). interface:edge(ns, _, _, URI, literal(Ns)) :- rdf_url_namespace(URI, Ns). interface:edge(registered_ns, _, _, URI, literal(Ns)) :- atom(URI), rdf_db:ns(_,Ns), sub_atom(URI, _,_,_, Ns),!. interface:edge(image, EMap, QMap, S, Image) :- iface_image(EMap, QMap, S, Image). interface:edge(images, EMap, QMap, S, Images) :- findall(I, iface_image(EMap, QMap, S, I), Images). interface:edge(thumbnail, EMap, QMap, S, Image) :- iface_thumbnail(EMap, QMap, S, Image). interface:edge(thumbnails, EMap, QMap, S, Images) :- findall(I, iface_thumbnail(EMap, QMap, S, I), Images). interface:edge(video, EMap, QMap, S, Video) :- iface_video(EMap, QMap, S, Video). interface:edge(videos, EMap, QMap, S, Videos) :- findall(V, iface_video(EMap, QMap, S, V), Videos). interface:edge(iclass, EMap, QMap, S, Class) :- iface_class_of(EMap, QMap, S, Class). interface:edge(lat, EMap, QMap, S, O) :- rdfs_plus_skos(EMap, QMap, S, iface:latitude, O). interface:edge(lng, EMap, QMap, S, O) :- rdfs_plus_skos(EMap, QMap, S, iface:longitude, O). interface:edge(date, EMap, QMap, S, Date) :- ( rdfs_plus_skos(EMap, QMap, S, iface:startDate, Start) -> ( rdfs_plus_skos(EMap, QMap, S, iface:endDate, End) -> Date = date(Start, End) ; Date = date(Start) ) ; rdfs_plus_skos(EMap, QMap, S, iface:date, Date) ). interface:edge(broader, EMap, QMap, S, O) :- rdfs_plus_skos(EMap, QMap, S, iface:broader, O). interface:edge(root, EMap, QMap, S, O) :- rdfs_plus_skos(EMap, QMap, S, iface:broader, Parent), rdf_reachable(Parent, iface:broader, O), \+ rdf_has(O, iface:broader, _). interface:edge(inlink, _, _, S, Score) :- rdf_estimate_complexity(_,_,S,CO), Score is 1/(1+CO). interface:edge(outlink, _, _, S, Score) :- rdf_estimate_complexity(S,_,_,CS), Score is 1/(1+CS). interface:edge(links, _, _, S, Score) :- rdf_estimate_complexity(_,_,S,CO), rdf_estimate_complexity(S,_,_,CS), Score is 1/(1+CO+CS). interface:edge(example_thumbs, EMap, QMap, S, Thumbs) :- answer_count(Thumb, ( rdf(Resource, _, S), iface_thumbnail(EMap, QMap, Resource, Thumb) ), 5, Thumbs ). %% thumbnail_url(+Image, -Thumbnail) % % Thumbnail is the URI of a Thumbnail % that depicts Resource. thumbnail_url(Image, Thumbnail) :- http_link_to_id(http_thumbnail, [uri(Image)], Thumbnail). image_url(Image, Thumbnail) :- http_link_to_id(http_mediumscale, [uri(Image)], Thumbnail).