You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by AL-Hanoof AL-Thnian <a....@gmail.com> on 2011/03/07 15:26:13 UTC

Help!!

Hi!
I hope this email finds you well. My name is Alhanoof and I am a graduate
student in the field of computer science in the US.  I am writing to you to
ask you a question about using Jena with a project I have this semester.  My
project is about improving RDF data navigation and visualization. The main
goal is to develop a generic application which enables navigation of RDF
data based on user input. The result set of navigation would then be
clustered based on their attributes and/or various concepts to provide
aggregate information or highlight high level information. The obtained
aggregate information would then be presented to the user in the form of
graphs or maps or other visualization techniques using Google Visualization
API.
I am new to semantic web projects, and I just started implementing this
project using java eclipse. I downloaded Jena, ARQ,and TDB.  I was able to
attach Jar files of each to my Java project.  However, I tried so hardly to
retrieve data from my RDF data file, but the result was always blank!!
I dont know if I am doing the correct thing. I have many questions in my
head, I'll try to list them in here:
1- How can I store RDF data? I have my data in rdf file but I dont know
where to put this file, and whether I need to put the ontology in the same
place. here what I did:
String directory = "MyDB/rdf" ;   //here I put my rdf data file.
Model model= TDBFactory.createModel(directory) ;
2- How can I query the data using sparql? I saw that there are two ways to
do this, and I dont know what the difference:
@first way:
String sparqlQueryString = "SELECT * WHERE { ?s ?p ?o } ";
Query query = QueryFactory.create(sparqlQueryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(System.
out, results, query) ;
qexec.close() ;
model.close();
@Second way:
use some functions instead of writing sparql query such as:
ResIterator iter = model.listResourcesWithProperty(null);
and in the first way, how can I write the prefexs in the query??

Here is my whole code:

public static void main(String[] args) {
String directory = "MyDB/rdf" ;   //here I put my rdf data file.
Model model= TDBFactory.createModel(directory) ;
String sparqlQueryString =
"SELECT * WHERE { ?s ?p ?o } ";
Query query = QueryFactory.create(sparqlQueryString) ;
QueryExecution qexec = QueryExecutionFactory.create(query, model) ;
ResultSet results = qexec.execSelect() ;
ResultSetFormatter.out(System.
out, results, query) ;
qexec.close() ;
model.close();}

I was hoping that this code would retrieve all subjects, predicates, and
objects in my rdf file., but unfortunately the result was always blank!!
would you please tell me what I did wrong. Please I need your help! I want
to start working on the algorithm so badly!!
Please help me!
I am looking forward to your help.
Alhanoof.

Re: Help!!

Posted by Damian Steer <d....@bristol.ac.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/03/11 14:26, AL-Hanoof AL-Thnian wrote:
> Hi!

> 1- How can I store RDF data? I have my data in rdf file but I dont know
> where to put this file, and whether I need to put the ontology in the same
> place. here what I did:
> String directory = "MyDB/rdf" ;   //here I put my rdf data file.
> Model model= TDBFactory.createModel(directory) ;

Here is your problem. TDB is a database that stores data and indexes on
disk, but in a form optimised for searching and size. It doesn't use rdf
files.

Try:

import com.hp.hpl.jena.util.FileManager;
...

Model model = FileManager.get().loadModel("path/to/file.rdf");

instead.

> I am looking forward to your help.
> Alhanoof.

Hope this helps.

Damian
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk11CcwACgkQAyLCB+mTtylwmQCgmHLP8bsrvrUy2JiTyXEdStGi
PoUAoKiAJ6SX/VNixb850pSC1sB/OWnk
=+h0m
-----END PGP SIGNATURE-----