/* 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(rdf_hierarchy_search,
[ rdf_hierarchy_search/4 % +KeyWord, +TargetCond, -State, +Options
]).
:- use_module(library(semweb/rdf_db)).
:- use_module(library(semweb/rdfs)).
:- use_module(rdf_search).
/** Direct metadata and hierarchy search on RDF graph
@author Michiel Hildebrand, on top of search facilities from rdf_search.pl
*/
:- meta_predicate
rdf_hierarchy_search(+, 1, -, +).
%% rdf_hierarchy_search(+Keyword, :TargetCond, -State, +Options)
%
% Initiate a graph search by traversing only direct links
% and narrower relations.
%
% Options: see rdf_search/4
rdf_hierarchy_search(Keyword, TargetCond, State, Options) :-
Expand = rdf_hierarchy_search:edge(TargetCond),
rdf_keyword_search(Keyword, TargetCond, State,
[expand_node(Expand),target_expand(false)|Options]),
steps(State).
steps(State) :-
rdf_extend_search(State), !,
steps(State).
steps(_).
%% edge(+Cond, +Object, -Link) is nondet.
%
% Default predicate to generate edges.
edge(Cond, O, i(S,P,W)) :-
edge_i(O, S, P),
predicate_weight(P, W),
hierarchy_search_edge(S, P, O, W, Cond).
hierarchy_search_edge(_, _P, literal(_), _, _) :-
%rdfs_subproperty_of(P, rdfs:label),
!.
hierarchy_search_edge(_, _, _, 1, _) :- !.
hierarchy_search_edge(S, _, _, _, Cond) :-
call(Cond, S).
edge_i(O, S, P) :-
rdf(S, P, O).
edge_i(O, S, P) :-
rdf(O, P0, S),
rdf_inverse_property(P, P0).
predicate_weight(P, 1) :-
rdfs_subproperty_of(P, rdfs:label), !.
predicate_weight(P, 1) :-
rdf_equal(P, owl:sameAs), !.
predicate_weight(P, 1) :-
rdfs_subproperty_of(P, skos:exactMatch), !.
predicate_weight(P, 1) :-
rdf_equal(P, rdf:value), !.
predicate_weight(P, 1) :-
rdfs_subproperty_of(P, iface:broader), !.
predicate_weight(_, 0.5).