34
35:- module(space_web_loader,
36 [ space_load_url/1, 37 space_load_url/2, 38 space_unload_url/1, 39 space_unload_url/2, 40 space_crawl_url/1, 41 space_crawl_url/2, 42 space_uncrawl_url/1, 43 space_uncrawl_url/2 44 ]). 45
46:- use_module(library(space/space)). 47:- use_module(library(semweb/rdf_db)). 48:- use_module(library(semweb/rdf_turtle)). 49:- use_module(library(semweb/rdf_http_plugin)).
57space_load_url(URL) :- space_load_url(URL,[]).
70space_load_url(URL, Options) :-
71 space_setting(rtree_default_index(DefaultIndex)),
72 option(index(IndexName), Options, DefaultIndex),
73 ( option(graph(Graph), Options)
74 -> rdf_load(URL,Graph)
75 ; rdf_load(URL)
76 ),
77 Counter = counter(0),
78 forall(uri_shape(URI, Shape, URL),
79 ( space_assert(URI, Shape, IndexName),
80 arg(1, Counter, N0),
81 N is N0 + 1,
82 nb_setarg(1, Counter, N)
83 )),
84 arg(1, Counter, C),
85 print_message(informational,space_load_url(C,IndexName)).
92space_unload_url(URL) :- space_unload_url(URL,[]).
105space_unload_url(URL, Options) :-
106 space_setting(rtree_default_index(DefaultIndex)),
107 option(index(IndexName), Options, DefaultIndex),
108 option(graph(Graph), Options, URL),
109 Counter = counter(0),
110 forall(uri_shape(URI, Shape, URL),
111 ( space_retract(URI, Shape, IndexName),
112 arg(1, Counter, N0),
113 N is N0 + 1,
114 nb_setarg(1, Counter, N)
115 )),
116 arg(1, Counter, C),
117 print_message(informational,space_unload_url(C,IndexName)),
118 rdf_unload(Graph).
119
120:- multifile prolog:message//1. 121
122prolog:message(space_load_url(0,_)) --> [], !.
123prolog:message(space_load_url(C,IndexName)) -->
124 [ 'Added ~w URI-Shape ~w to ~w'-[C, P, IndexName] ],
125 { plural(C,P) }.
126
127prolog:message(space_unload_url(0,_)) --> [], !.
128prolog:message(space_unload_url(C,IndexName)) -->
129 [ 'Removed ~w URI-Shape ~w from ~w'-[C, P, IndexName] ],
130 { plural(C,P) }.
131
132plural(1,pair) :- !.
133plural(_,pairs).
134
135prolog:message(space_crawl_url(C)) -->
136 [ 'Crawling ~w'-[C] ].
137
138prolog:message(space_uncrawl_url(C)) -->
139 [ 'Uncrawling ~w'-[C] ].
149:- dynamic link_property/1. 150link_property('http://www.w3.org/2002/07/owl#sameAs').
151link_property('http://www.w3.org/2004/02/skos/core#exactMatch').
152link_property('http://www.w3.org/2004/02/skos/core#closeMatch').
165space_crawl_url(URL) :- space_crawl_url(URL,[]).
178space_crawl_url(URL,Options) :-
179 with_mutex(message,print_message(informational,space_crawl_url(URL))),
180 space_load_url(URL,Options),
181 findall( NewLink, new_link(URL:_,NewLink,_Type), NewLinks ),
182 forall( member(NL, NewLinks),
183 thread_create(space_crawl_url(NL,Options),_,[])
184 ).
193space_uncrawl_url(URL) :- space_uncrawl_url(URL,[]).
206space_uncrawl_url(URL,Options) :-
207 with_mutex(message,print_message(informational,space_uncrawl_url(URL))),
208 findall( Link, old_link(URL:_,Link,_Type), Links ),
209 space_unload_url(URL,Options),
210 forall( member(L, Links),
211 space_uncrawl_url(L,Options)
212 ).
213
214new_link(FromSource,NewLink,P) :-
215 link_property(P),
216 rdf(_,P,NewLink,FromSource),
217 \+once(rdf(_,_,_,NewLink:_)).
218
219old_link(FromSource,Link,P) :-
220 link_property(P),
221 rdf(_,P,Link,FromSource),
222 once(rdf(_,_,_,Link:_))