view jamendo/sparql-archived/p2r_entailment.pl @ 27:d95e683fbd35 tip

Enable CORS on urispace redirects as well
author Chris Cannam
date Tue, 20 Feb 2018 14:52:02 +0000
parents df9685986338
children
line wrap: on
line source
:- module(p2r_entailment,[
	]).

:- use_module(library('semweb/rdf_db'),
              [ rdf_global_id/2,
                rdf_reachable/3,
                rdf_has/3,
                rdf_subject/1,
                rdf_equal/2,
		rdf_global_term/2
	      ]).

:- use_module(match).


term_expansion((rdf(S0, P0, O0) :- Body),
               (rdf(S,  P,  O)  :- Body)) :-
        rdf_global_id(S0, S),
        rdf_global_id(P0, P),
        rdf_global_id(O0, O).


rdf(Subject,Predicate,Object) :-
	match:eq(Pred,Triples),
	expand_t(Triples,TriplesX),
	rdf_global_id(Subject,SubjectX),rdf_global_id(Predicate,PredicateX),rdf_global_id(Object,ObjectX),
	member_m(rdf(SubjectX,PredicateX,ObjectX),TriplesX,rdf(SM,_,OM)),
	Pred,
	(SM=pattern(ListA)->concat_atom(ListA,SubjectX);true),
	(OM=pattern(ListB)->concat_atom(ListB,ObjectX);true).

member_m(_,[],_) :- fail.
member_m(rdf(S,P,O),[rdf(SM,PM,OM)|_],rdf(SM,PM,OM)) :-
	pattern_match(SM,S),pattern_match(PM,P),pattern_match(OM,O).
member_m(rdf(S,P,O),[_|T],rdf(SM,PM,OM)) :-
	member_m(rdf(S,P,O),T,rdf(SM,PM,OM)).

pattern_match(P,A) :- var(A),\+var(P), P=pattern(_),!.
pattern_match(P,A) :- atomic(A),\+var(P), P=pattern(_),!, pattern_match_p(P,A).
pattern_match(A,A).
pattern_match_p(pattern([]),'').
pattern_match_p(pattern([H|T]),Atom) :- atomic(Atom),
	atom_concat(H,Atomtail,Atom),
	pattern_match(pattern(T),Atomtail).

expand_t([],[]).
expand_t([rdf(A,B,C)|T],[rdf(AX,BX,CX)|TX]) :-
	rdf_global_id(A,AX),rdf_global_id(B,BX),rdf_global_id(C,CX),
	expand_t(T,TX).

                 /*******************************
                 *             REGISTER         *
                 *******************************/

:- multifile
        serql:entailment/2.

serql:entailment(p2r, p2r_entailment).