How do I parse and save all the classes with their properties from an RDF file using Jena API in Java? -


i have project need parse rdf file , record data on have search specific data afterwards. searched web , find how query said rdf file want parse , save classes in objects.

this how class looks in file:

<bfo rdf:about="bfo:0000007">     <rdfs:label>process</rdfs:label>       <definition>           <rdf:description>               <def>a process entity exists in time occurring or happening, has temporal parts , involves , depends on entity during time occurs.</def>           </rdf:description>       </definition>       <is_a rdf:resource="efo:0000001"/>   </bfo>   

update:

yea u said worked, thank 1 last question:) namespaces have are:

<?xml version='1.0' encoding='utf-8'?> <rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns="http://www.ebi.ac.uk/efo/"> </rdf> 

my question

        <definition>         <rdf:description>         <def>smth here</def>         </rdf:description>     </definition>     couldn't find way def tag, idea how can access it? sry bother again:)   

jena uses model object store rdf has been parsed external source, such file or web url. depending on project's needs, , size of data, have basic choice of whether read file memory model, or persistent model. memory faster access, of course once program exits contents of memory model lost (well, unless write them file again).

you should read jena tutorials better understanding of processes involved, reading file jena memory model easy:

string source = ".. file location .."; model m = filemanager.get().loadmodel( source, "rdf/xml" ); 

if persistent model better suit project, best choice is jena tdb. again, it's easy model can begin querying.

you asked:

and save classes in objects

i'm not quite sure mean here. possibly you're thinking of sort of orm tool, similar activerecord? there's nothing built-in jena that, though there have been various other projects have looked @ doing orm layer. i'm not sure of them active though. don't need orm access properties of resources, can use jena api:

string namespace = ".. namespace here .."; resource bfo = m.getresource( namespace + "bfo:0000007" ); property definition = m.getproperty( namespace + "definition" ); rdfnode def = bfo.getproperty( definition ).getobject(); 

updated

ok, in response comments: if don't know properties expect on resource, can list them:

string namespace = ".. namespace here .."; resource bfo = m.getresource( namespace + "bfo:0000007" ); (stmtiterator = bfo.listproperties(); i.hasnext(); ) {   statement smt = i.next();   system.out.println( "resource " + stmt.getsubject().geturi() +                        " has property " + stmt.getpredicate().geturi() +                       " value " + stmt.getobject() ); } 

this simple loop, want more useful, shows you can still process resources in model without knowing properties in advance. of course, @ point in code have connect particular property whatever application wants particular value of resource. somewhere code have have knowledge of properties expect.

re-reading comment, notice refer "concepts in ontology" (even though there no classes in rdf fragment quoted in question). might find capabilities of jena ontology api useful, can list ontology classes in model, properties have been defined, etc.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -