[rdfweb-dev] [jena-dev] novice Jena foaf parsing question

Graham Klyne GK at ninebynine.org
Tue Jul 8 10:00:23 UTC 2003


At 18:50 07/07/03 -0400, Dan Brickley wrote:
>Could someone with some Jena-knowhow perhaps offer some help here? If so
>we can slap it in the wiki and link from FAQ at same time... --danbri

(QUESTION TO ALL: see *** below)

(I also just noticed that Andy Seaborne has given some more details in 
response to this on the Jena-users list.)

It's a while since I used the Jena API, so I can't remember the 
details.  Also, it's not exactly clear from the question what is required 
to be achieved.  I see two possibilities:
(a) given a foaf property+value about some person, such as 
<foaf:mbox_sha1sum>, to find other information about that person, or
(b) given a collection of foaf descriptions, to extract information about 
all of them.

Dealing with case (a), using the Jena 'Model' interface, you need to do a 
two-step process:

1. search for statements of the form:

     (anything) foaf:mbox_sha1sum (sha-1 value)

there's a specific method of Model to do this, but I forget it's exact name 
... something like findStatements, I think.  In normal use, you should get 
just one statement returned, but more are possible if the same mailbox 
owner appears multiple times in your RDF data.

2. extract the subject from the statement returned, and use that to 
retrieve from the Jena Model statements of the form:

     (subject) (any) (any)

which should get you all known properties of the given subject.  For 
complex properties you may need to chase properties of the objects thus 
obtained.

All this can get rather tedious to do at this level, and you may do better 
to fire up Jena's query language interface which should let you do most of 
this in a single hit.  I've never used that, so I can't really help further.

Case (b) above uses the same basic ideas, but is a bit more complex because 
you don't have any kind of definite key to locate the foaf data.

*** QUESTION TO ALL: is there a foaf property that SHOULD (MUST?) be 
present in any well-formed FOAF description?  Without this, it may be 
difficult to separate FOAF subjects from other resources in an RDF database.

ANyway, for starters, I'd suggest doing something like finding all 
statements of the form:

     (any) foaf:name (any)

and use the subjects of these as a pool opf foaf subjects.  If you get this 
far, I'm sure you can figure any further details.

#g
--

At 18:50 07/07/03 -0400, Dan Brickley wrote:
>Could someone with some Jena-knowhow perhaps offer some help here? If so
>we can slap it in the wiki and link from FAQ at same time... --danbri
>(still in catchup mode...)
>
>----- Forwarded message from James Nachlin <jnachlin at nachlin.com> -----
>
>From: James Nachlin <jnachlin at nachlin.com>
>Date: Mon, 7 Jul 2003 17:39:03 -0400 (EDT)
>To: jena-dev at yahoogroups.com
>Subject: [jena-dev] novice Jena foaf parsing question
>Message-ID: <Pine.LNX.4.44.0307071723560.19906-100000 at www.brettsinger.com>
>Reply-To: jena-dev at yahoogroups.com
>
>Hi,
>
>I'm trying to parse FOAF graphs using jena, and getting hung up
>on what seems like it should be easy.  I have basic code to
>create a model and get a list of friends:
>
>import com.hp.hpl.jena.mem.*;
>import com.hp.hpl.jena.rdf.model.*;
>import com.hp.hpl.jena.vocabulary.*;
>//created from the foaf schema using the schemagen tool:
>import foaf.FOAF;
>
>public class friends {
>     public static void main(String[] arrrgh){
>         String foafURL = "http://www.nachlin.com/foaf.rdf";
>         Model model = new ModelMem();
>         model.read(foafURL);
>         Property knows = model.getProperty(FOAF.getURI(), "knows");
>         Property nID = model.getProperty(RDF.getURI(), "nodeID");
>         NodeIterator niter = model.listObjectsOfProperty(knows);
>         while(niter.hasNext()){
>             RDFNode node = niter.nextNode();
>             //just to prove something's happening
>             System.out.println("friend> " + node.toString());
>         }
>     }
>}
>
>
>That's great, but the next step is to access each one of these
>friends and get information from that part of the graph.  Jena
>is seeing these "friends" in the graph as rdf:Descriptions, like
>so:
>
><rdf:Description rdf:nodeID="A1">
>     <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
>     <foaf:name>Lucas Gonze</foaf:name>
> 
><foaf:mbox_sha1sum>a5bac82a92eadb58f027754cb2d64231602d218c</foaf:mbox_sha1sum>
>     <rdfs:seeAlso rdf:resource="http://www.gonze.com/foaf.rdf"/>
></rdf:Description>
>
>I haven't been able to get this simple task accomplished, trying
>every approach I can think of and pouring over the tutorials and
>docs.  I would like, for instance, to be able to just print the
>value of each foaf:name (and more beyone that, of course)
>
>Sorry to be so dense.  Thanks for your help.
>
>Jim Nachlin
>
>
>------------------------ Yahoo! Groups Sponsor ---------------------~-->
>Save on Coral Calcium. Get Better Health and
>Stronger Bones. Seen on TV
>http://www.challengerone.com/t/l.asp?cid-2805&lp=calcium2.asp
>http://us.click.yahoo.com/9gf46B/EfUGAA/ySSFAA/NhFolB/TM
>---------------------------------------------------------------------~->
>
>To unsubscribe from this group, send an email to:
>jena-dev-unsubscribe at yahoogroups.com
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>----- End forwarded message -----
>
>_______________________________________________
>rdfweb-dev mailing list
>rdfweb-dev at vapours.rdfweb.org
>wiki: http://rdfweb.org/topic/FoafProject
>http://rdfweb.org/mailman/listinfo/rdfweb-dev

-------------------
Graham Klyne
<GK at NineByNine.org>
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E




More information about the foaf-dev mailing list