<commit_before>/*  $Id$

    Author:        <NAME>
    E-mail:        <EMAIL>
    WWW:           http://www.few.vu.nl/~wrvhage
    Copyright (C): 2009, Vrije Universiteit Amsterdam

    This program 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.

    This program 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 Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    As a special exception, if you link this library with other files,
    compiled with a Free Software compiler, to produce an executable, this
    library does not by itself cause the resulting executable to be covered
    by the GNU General Public License. This exception does not however
    invalidate any other reasons why the executable file might be covered by
    the GNU General Public License.
*/

:- module(web_loader,
          [ load_url/1,
	    load_url/2,
            unload_url/1,
            unload_url/2
	  ]).

:- use_module(library(space/space)).
:- use_module(library(semweb/rdf_db)).
:- use_module(library(semweb/rdf_turtle)).
:- use_module(library(semweb/rdf_http_plugin)).

%%	load_url(+URL) is det.
%
%	Retrieve RDF over HTTP from a URL, load it in the rdf_db and
%	index all URI-Shape pairs that can be found in it into the
%	default index.

load_url(URL) :-
	rdf_load(URL),
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_assert(URI, Shape),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	space:rtree_default_index(IndexName),
	format('% Added ~w URI-Shape pairs to ~w\n',[C, IndexName]).

%%	load_url(+URL,+IndexName) is det.
%
%	Load using load_url/1, but index the URI-Shape pairs into
%	index named IndexName.

load_url(URL, IndexName) :-
	rdf_load(URL),
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_assert(URI, Shape, IndexName),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	format('% Added ~w URI-Shape pairs to ~w\n',[C, IndexName]).

%%	unload_url(+URL) is det.
%
%	Unload the RDF that was fetched from URL and remove all
%	URI-Shape pairs that are contained in it from the default index.

unload_url(URL) :-
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_retract(URI, Shape),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	space:rtree_default_index(IndexName),
	format('% Removed ~w URI-Shape pairs from ~w\n',[C, IndexName]),
	rdf_unload(URL).

%%	unload_url(+URL,+IndexName) is det.
%
%	Unload the RDF that was fetched from URL and remove all
%	URI-Shape pairs that are contained in it from the index named
%	IndexName.

unload_url(URL, IndexName) :-
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_retract(URI, Shape, IndexName),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	format('% Removed ~w URI-Shape pairs from ~w\n',[C, IndexName]),
	rdf_unload(URL).







<commit_msg>Minor estherics.<commit_after>/*  $Id$

    Author:        <NAME>
    E-mail:        <EMAIL>
    WWW:           http://www.few.vu.nl/~wrvhage
    Copyright (C): 2009, Vrije Universiteit Amsterdam

    This program 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.

    This program 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 Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    As a special exception, if you link this library with other files,
    compiled with a Free Software compiler, to produce an executable, this
    library does not by itself cause the resulting executable to be covered
    by the GNU General Public License. This exception does not however
    invalidate any other reasons why the executable file might be covered by
    the GNU General Public License.
*/

:- module(web_loader,
          [ load_url/1,
	    load_url/2,
            unload_url/1,
            unload_url/2
	  ]).

:- use_module(library(space/space)).
:- use_module(library(semweb/rdf_db)).
:- use_module(library(semweb/rdf_turtle)).
:- use_module(library(semweb/rdf_http_plugin)).

%%	load_url(+URL) is det.
%
%	Retrieve RDF over HTTP from a URL, load it in the rdf_db and
%	index all URI-Shape pairs that can be found in it into the
%	default index.

load_url(URL) :-
	rdf_load(URL),
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_assert(URI, Shape),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	space:rtree_default_index(IndexName),
	plural(C,P),
	format('% Added ~w URI-Shape ~w to ~w\n',[C, P, IndexName]).

%%	load_url(+URL,+IndexName) is det.
%
%	Load using load_url/1, but index the URI-Shape pairs into
%	index named IndexName.

load_url(URL, IndexName) :-
	rdf_load(URL),
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_assert(URI, Shape, IndexName),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	plural(C,P),
	format('% Added ~w URI-Shape ~w to ~w\n',[C, P, IndexName]).

%%	unload_url(+URL) is det.
%
%	Unload the RDF that was fetched from URL and remove all
%	URI-Shape pairs that are contained in it from the default index.

unload_url(URL) :-
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_retract(URI, Shape),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	space:rtree_default_index(IndexName),
	plural(C,P),
	format('% Removed ~w URI-Shape ~w from ~w\n',[C, P, IndexName]),
	rdf_unload(URL).

%%	unload_url(+URL,+IndexName) is det.
%
%	Unload the RDF that was fetched from URL and remove all
%	URI-Shape pairs that are contained in it from the index named
%	IndexName.

unload_url(URL, IndexName) :-
	Counter = counter(0),
	forall(uri_shape(URI, Shape, URL),
	       (   space_retract(URI, Shape, IndexName),
		   arg(1, Counter, N0),
		   N is N0 + 1,
		   nb_setarg(1, Counter, N)
	       )),
	arg(1, Counter, C),
	plural(C,P),
	format('% Removed ~w URI-Shape ~w from ~w\n',[C, P, IndexName]),
	rdf_unload(URL).


plural(1,pair) :- !.
plural(_,pairs).






{'fraction_non_alphanumeric': 0.11112635478117712, 'fraction_numerical': 0.014405268212374811, 'mean_word_length': 3.1752577319587627, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4066399', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2422, 'n_words': 855}