On Tue, Apr 15, 2014 at 7:08 PM, wk <[email protected]> wrote:
>
> ok, i think i got it. funny thing is, i found your stackoverflow answer to a 
> similar question.
> so i basically did the following:
>
>         model = ModelFactory.createDefaultModel();
>         File dir = new File(directory);
>         File[] directoryListing = dir.listFiles();
>         if (directoryListing != null) {
>             for (File child : directoryListing) {
>                 if(child.toString().endsWith("rdf") || 
> child.toString().endsWith("RDF")) {
>                     Model m = 
> ModelFactory.createDefaultModel().read(child.toString());
>                     model.add( m );
>                 }
>             }
>         }
>
> then without saving i use the model to perform my queries at. this should be 
> it, shouldn't it?

I don't know that

>                 if(child.toString().endsWith("rdf") || 
> child.toString().endsWith("RDF")) {

is quite as robust as it could be;  there are other common extensions
for files that have RDF content.  In RDF/XML serialization, you'll
typically see .rdf or .owl (when it's an RDF/XML serialization of an
OWL ontology), but there's also N3/Turtle (.n3, .ttl), and N-Triples
(.nt).  Even if you only want things ending with .rdf, it'd probably
be more sensible to the getName() method, and you consider normalizing
the case and checking against that:

child.getName().toLowerCase().endsWith("rdf");
otherwise, you'd miss things like .RdF, .rDF, etc.  Also, you don't
need to create a new model for each file, since the model.add( m )
call is just taking the triples from m and adding them to model.  You
can just do

for ( File child : directoryListing ) {
  if ( child.getName().toLowerCase().endsWith("rdf") ) {
    model.read( child.getAbsolutePath() );
  }
}

//JT

>
> On 04/15/2014 10:22 PM, wk wrote:
>
> sorry, i forgot to reply to the full list.
>
>
> -------- Original Message --------
> Subject: Re: jena api - typos and TDB
> Date: Tue, 15 Apr 2014 22:20:02 +0200
> From: wk <[email protected]>
> To: [email protected]
>
>
> hello Joshua,
>
> thx for reply. i really need some help here.
> the context is the following. i need to build a RESTful service where
> someone can upload RDF files and then query the information. the upload
> is already implemented, now i need to be able to query those RDF files
> (all in one folder) programatically through the jena api. i already
> managed to query one specific RDF file successfully, however i need to
> implement the case where i don't know exactly the number and the name of
> these RDF files which should all be in one folder. is this information
> helpful?
>
> best regards,
> Walt
>
> On 04/15/2014 10:11 PM, Joshua TAYLOR wrote:
> > On Tue, Apr 15, 2014 at 3:53 PM, wk <[email protected]> wrote:
> >> however, im trying to use TDB, is this the appropriate tool to combine
> >> several rdf files to be able to query them all at the same time?
> >
> > This is a rather broad question, and I think you'll need to provide a
> > bit more context.  In one sense, the easiest way to combine a bunch of
> > RDF graphs and execute SPARQL queries over them would be to use Jena's
> > rdfcat command line utility to combine them, and Jena's sparql command
> > line utility to execute the queries.  Some more context will help to
> > determine what's a good fit for your situation, though.
> >
>
>
>
>



-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Reply via email to