Loading dbPedia data into a local Virtuoso installation


My next step within a semantic web project is to bring dbPedia data of the types Person, Organization and Place into a local Virtuoso installation.

dbPedia give us its data for downloading in many different sets and formats. In my case I’m working with the 3.7 version.

I started by the Person type where  I plan to make it possible for data entered by end journalists and reporters to be “automatically” linked to dbPedia data. For exemple, when the user says a news article talks about “Lula” I will execute a SPARQL query such as…

SELECT DISTINCT ?s ?label 
WHERE {
 ?s rdf:type <http://dbpedia.org/ontology/Person> .
 ?s rdfs:label ?label .
 FILTER (REGEX(STR(?label), "lula", "i"))
}
LIMIT 100

… in my local Virtuoso installation. The result of such query would be presented to the user for his/her decision about which “lula” the news article talks about. The result of the previous query is…

The 'lula' result SPARQL query

This way one responsible for writing the article will make the decision of whom the article is about. After that I will create a sameAs link between my local data and dbPedia data.

Well, before doing this I discovered it would be a challenge to load dbPedia‘s Person data into the Virtuoso installation in my 4GB RAM notebook. That’s because as stated in Setting up a local DBpedia mirror with Virtuoso loading all dbPedia in a 8 core machine with 32GB RAM it would take 7 hours!

Trying to not to figuring out how much time it would take to load Person data into my Virtuoso, I had another challenge which was how to load the dbPedia data into my Virtuoso.  The problem is that the Quad Store Upload of Virtuoso‘s Conductor seems not to be able to deal with files over than 51MB of triples in it. So… how to import the  531MB of triples in the persondata_en.nt file?

First of all I had to split the persondata_en.nt file into chunks files of 100.000 lines each. Since I couldn’t do it with neither Notepad++ nor Replace Pioneer, I had to resort to a the Linux’s split built in program. The command split -l 100000 persondata_en.nt solved my first problem.

The second one was how to load each 12MB chunck file into Virtuoso. I chosed  Virtuoso’s Bulk data loader. There are to very important things to pay attention to when following the instructions of this documentation.

The first one is that it seems to have an error in the load_grdf procedure of the loader script. I had to change the while condition from while (line <> 0) to while (line <> ”). The second is that it was difficuld to successfuly set of the folder where the chunk files should be placed. After executing the SQL select server_root (), virtuoso_ini_path (); I discovered that C:\virtuoso-opensource\database was my server root folder and that was the place where the chuck files should be placed.

I started the rdf_loader_run(); command at 7:41PM.

It’s 9:47PM now and there are 8 (out of 41) files remmaining. I’ll not wait another hour to write more in this post. See you in the next one!

Anúncios

SPARQL 1.1 and Openlink Virtuoso: First steps with federated queries


Learning Sparql
Learning Sparql

Last week I stared reading “Learning SPARQL” by Bob DuCharme (O’Reilly) and I’m very happy with it. The book is very didactic and explain every SPARQL aspect with the help of useful practical examples.

The tool I decided to use SPARQL with was the OpenLink’s Virtuoso Open Source edition. Although I’ve created an Amazon Linux machine and installed a Virtuoso instance in it from souce code, I decided to install Virtuoso on Windows XP laptop. The reason was simple. I’d like to be able to use Virtuoso while in Saquarema (The “Maracanã” of surf in Rio de Janeiro) where I prefer not to have an internet connection.

By the way, when following the above link to install Virtuoso on Windows, the Windows service created to manage Virtuoso‘s startup seems not to work properly. As for this post my intention is to talk about SPARQL I’ll let to talk about such problem on a next post.

Back to SPARQL in Virtuoso, one interesting capability that really made me happy was the possibility to SELECT remote SPARQL endpoints when connected to my local SPARQL endpoint. For exemple, I connect to my local Virtuoso and SELECT DBpedia’s SPARQL endpoint. That’s  called Federated Query.

This is made possible by using the SERVICE keyword that is new on SPARQL 1.1. Thanks to Openlink by making SPARQL 1.1 possible on VIRTUOSO 🙂

The following is an example of such SPARQL 1.1 query:

SELECT ?p ?o
WHERE
{
 SERVICE <http://DBpedia.org/sparql >
 { SELECT ?p ?o
 WHERE { <http://dbpedia.org/resource/Saquarema > ?p ?o . }
 }
}

Before issuing this query I just had to remember that Virtuoso isql‘s interface (either command line of on Conductor) cannot be used to issue SPARQL commands. The isql interface, as its name stands for, is a SQL client and not a SPARQL client. Therefore, in order to issue SPARQL queries I had to log in at the Conductor interface (http://localhost:8890/conductor/) and the go to “Linked Data -> Sparql“.

When trying to execute the SPARQL query above, you’ll see an error message complaining about permission somewhere in Virtuoso’s database. You’ll have to issue two SQL GRANT commands in isql interface. Here they are:

grant select on "DB.DBA.SPARQL_SINV_2" to “SPARQL”;
grant execute on "DB.DBA.SPARQL_SINV_IMP" to "SPARQL";

After these two GRANTs you’ll be able to sucessfully execute a federated query in your Virtuoso installation. Here is a small of of the result of my SPARQL SELECT above about Saquarema.

Result of a "Saquarema" SPARQL query against DBpedia endpoint
Result of a “Saquarema” SPARQL query against DBpedia endpoint

That makes Linked Data really possible. I’ll explore and talk more about it later.

See you… bye!