Re: Problem inferencing from Jena TDB API

2013-10-23 Thread Dibyanshu Jaiswal
Thanks Dave!!
Just tell me what i can understand from your reply is correct or not.

By the solution provided by you, you mean to:
Firstly create a model reading it from file with inferencing enabled.
Second store the inferred model in the dataset while during the creation of
the dataset.

At last then read the model back from the dataset in OWL_MEM mode, which
results in OntModel with inferences, but without inferencing mode enabled.
Right?

If this is so! then Yes this can be useful to me. But I guess you missed a
point in my question that, I directly want to query the dataset (Eg.:
QueryExecution qexec = QueryExecutionFactory.create(**query, dataset); )
and not the OntModel read from the dataset.

Thanks once again!!


On Thu, Oct 17, 2013 at 1:18 PM, Dave Reynolds dave.e.reyno...@gmail.comwrote:

 For largely static data then the best way to mix inference and persistent
 storage in Jena is to load your data into memory, do the inference and
 store the results to the TDB store. Then when you want to use it open the
 TDB store as a plain OntModel (or Model) with no inference.

 A brute force version of this would be something like:

 OntModel om = ModelFactory.**createOntologyModel(**
 OntModelSpec.OWL_MEM_MICRO_**RULE_INF);
 FileManager.get().readModel( om, myfile);

 Dataset dataset = TDBFactory.createDataset(**mydir) ;
 dataset.begin( ReadWrite.WRITE );
 try {
 dataset.getDefaultModel().add( om );
 } finally {
 dataset.end();
 }

 Then when a future program wants to access the data:

 OntModel om = ModelFactory.**createOntologyModel(
  OntModelSpec.OWL_MEM, tdbdataset.getDefaultModel() );

 In some applications you only need to support a limited range of query
 patterns, in which case you can replace the add(om) stage by a more
 selective add of just the results you are going to be interested in.

 Dave



 On 17/10/13 08:24, Dibyanshu Jaiswal wrote:

 Hi!
 Yes you are right! Its true that the inferencing is done by the OntModel
 and not the database. I tried to set the default model of the dataset by
 using dataset.setDefaultModel(om), where om is a OntModel with
 OntModelSpec.OWL_MEM_RULE_INF. But in this case the programme undergoes an
 error.

 Can you please elaborate a bit on the solution which you say about writing
 the whole OntModel to a Graph? The TDB I use is initialized (create) using
 an owl file read locally, which stands to be the conceptual model for our
 application and i dont want to modify that file, but at the same time want
 to use inferencing.




 On Fri, Oct 11, 2013 at 6:22 PM, Andy Seaborne a...@apache.org wrote:

  Hi there,

 If you query the dataset directly, do you see any triples?  You will see
 different results if you query via the inference model.  The inference is
 not done in the database but in the inference engine associate with the
 OntModel.  The dtabase does not contain the deductions.

 You can store the inferred results to a database by writing the whole
 OntModel to a graph in the database.

  Andy


 On 10/10/13 13:21, Dibyanshu Jaiswal wrote:

  Here is a sample code of the above stated problem.

 public class ReadTDB {

   public static void main(String[] args){

   // open TDB dataset
   String directory = ./MyDatabases/OntologyTDB; // My TDB created
 beforehand
   Dataset dataset = TDBFactory.createDataset(directory);

   //Read Model from the tdb
   Model tdb = dataset.getDefaultModel();

   // read the OntModel from the Model
   OntModel m = ModelFactory.createOntologyModel(

 OntModelSpec.OWL_MEM,
 tdb );

   String sparqlQueryString=null;

sparqlQueryString = SELECT ?s WHERE { ?s 
 http://www.w3.org/2000/01/rdf-schema#subClassOfhttp://www.w3.org/2000/01/rdf-**schema#subClassOf
 http://**www.w3.org/2000/01/rdf-schema#**subClassOfhttp://www.w3.org/2000/01/rdf-schema#subClassOf
 
 
 http://www.owl-ontologies.com/unnamed.owl#ABCDhttp://www.owl-ontologies.com/**unnamed.owl#ABCD
 http://www.**owl-ontologies.com/unnamed.**owl#ABCDhttp://www.owl-ontologies.com/unnamed.owl#ABCD
 
 };


   Query query = QueryFactory.create(sparqlQueryString) ;
   QueryExecution qexec = QueryExecutionFactory.create(query,
 m) ;

   //LINE
 OF CONSIDERATION
   ResultSet results = qexec.execSelect() ;

   ResultSetFormatter.out(results) ;


   tdb.close();
   dataset.close();

   }

 }




 As per the above code snippet given, and the line marked as LINE OF
 CONSIDERATION, when i pass the OntModel m as the parameter the results
 are
 in accordence to the inference mechanisms (such as Transitive relations)
 but if I change the parameter to dataset i.e.
 QueryExecution qexec = QueryExecutionFactory.create(query,
 dataset) ;

 and hence execute the query, the results are not the same.
 As per my observation the a Query made to the Dataset/TDB directly is
 unable to provide 

Adding Individuals of a given OntClass with ObjectProperty

2013-10-23 Thread Dibyanshu Jaiswal
I am facing problem in adding Individuals of a given class using jena.

Say for example we have a give hierarchy of classes:
Class Customer
 ObjectProperties:hasName   Range: Class Name
  hasAddressRange:
Class Address

Class Name
 ObjectProperties:hasFirstNameRange: Class FirstName
  hasLastNameRange: Class
LastName


Class FirstName
 DatatypeProperties:FirstName_IsRange: String
datatype


Class LastName
 DatatypeProperties:LastName_IsRange: String
datatype

Class Address
 ObjectProperties:hasBuildingInfoRange: Class
BuildingInfo
  hasStreetInfoRange: Class
StreetName

Class BuildingInfo
 DatatypeProperties:BuildingNo_IsRange: int datatype
  FlooNo_Is Range:
int datatype


Class StreetInfo
 DatatypeProperties:StreetNameRange: String datatype
  CityCodeRange:
String datatype



Now I want to add an individual of Customer Is there any easy way to do
that, instead of driiling down to the range classes and creating
individuals of FirstName, LastName, BuildinInfo, StrretInfo, and then
adding these individuals as values to Name and Address and hence add these
Name and Address individuals to Customer??

This is just an example where the object property hierarchy goes only two
level deep, but in my web application the hierarchies are much deeper and
hence i am in a search of some generic method to deal with this problem.
Can Jena API deal/help me with this??

-- 
*Dibyanshu Jaiswal*
Mb: +91 9038304989
Mb: +91 9674272265


Re: Problem inferencing from Jena TDB API

2013-10-23 Thread Ian Dickinson
On Wed, Oct 23, 2013 at 7:03 AM, Dibyanshu Jaiswal djthequ...@gmail.com wrote:
 Just tell me what i can understand from your reply is correct or not.
Dave's not around at the moment, but I'll try to answer your question.

 By the solution provided by you, you mean to:
 Firstly create a model reading it from file with inferencing enabled.
 Second store the inferred model in the dataset while during the creation of
 the dataset.

 At last then read the model back from the dataset in OWL_MEM mode, which
 results in OntModel with inferences, but without inferencing mode enabled.
 Right?

I'm slightly confused by your description, but one of these steps is
not necessary.

To explain: inference in RDF models means using an algorithm to derive
additional
triples beyond those that are asserted in the original ('base') model.
For example,

C rdfs:subClassOf B
B rdfs:subClassOf A

allows an algorithm to infer the additional triple:

C rdfs:subClassOf A

We call those additional triples the inference closure. Depending on
the model, there
can be quite a lot of them. When you construct an inference model, the inference
closure is computed dynamically (basically; there is some caching but
we'll leave that
to one side) in response to a query. So if you ask, via the API or SPARQL, is
C rdfs:subClassOf A?, the inference algorithm will do work -
including pulling triples
from the base model - to answer that question.  The upside of this is
that (i) the
inference algorithm only has to do work in response to questions that
are asked (if
no-one cares about C's relationship to A, that inferred triple need
never be calculated),
and (ii) the results will adapt to updates to the model. The downside
is that every
time a question is asked, the algorithm typically has to make a lot of
queries into the
base model to test for the presence or absence of asserted triples.
That's OK for
memory models, which are efficient to access, but any model that is
stored on disk
makes that process very slow. There are two basic ways to get around
this problem:

1. When your application starts, make a copy of the model that's
stored on disk in
memory, and then query that via the inference engine. Pros: can be
more responsive
to updates, does not require the entire inference closure to be
calculated. Cons: the
model may be too large to fit in memory, persisting updates needs care.

2. Before your application starts, load the model from disk into an
inference memory
model, then save the entire inference closure to a new disk-based model. Then,
when your application runs, run queries directly against that new
model. Pros: you'll
get results from the inference closure as well as the base model
without having to
run inference algorithms when queries are asked, and you can cope with larger
models. Cons: needs more disk space, updating the model is much harder.

 If this is so! then Yes this can be useful to me. But I guess you missed a
 point in my question that, I directly want to query the dataset (Eg.:
 QueryExecution qexec = QueryExecutionFactory.create(**query, dataset); )
 and not the OntModel read from the dataset.
See above. You have to make choices among different trade-offs, and
those choices
will depend on the needs of your application and your users.

Ian


Re: Adding Individuals of a given OntClass with ObjectProperty

2013-10-23 Thread Ian Dickinson
On Wed, Oct 23, 2013 at 7:28 AM, Dibyanshu Jaiswal djthequ...@gmail.com wrote:
 I am facing problem in adding Individuals of a given class using jena.

 Say for example we have a give hierarchy of classes:
As an aside, this would have been easier to read as Turtle than as a
table whose formatting didn't really survive being transmitted in
email.

 Now I want to add an individual of Customer Is there any easy way to do
 that, instead of driiling down to the range classes and creating
 individuals of FirstName, LastName, BuildinInfo, StrretInfo, and then
 adding these individuals as values to Name and Address and hence add these
 Name and Address individuals to Customer??
To create an individual of class Customer takes only one triple:

yourNamespace:customer1234 rdf:type :Customer.

That's it. This may sound flippant, but in RDF you're not required to
add any information to create a valid resource, because of the open
world assumption. It's not like creating a row in a database, which
will fail your data integrity checks if some columns are missing.
Missing triples in RDF are perfectly OK. One upshot of which is that
no, there's no generic mechanism in Jena for creating individuals with
a certain collection of properties, because which properties those
would be is basically an application decision.

 This is just an example where the object property hierarchy goes only two
 level deep, but in my web application the hierarchies are much deeper and
 hence i am in a search of some generic method to deal with this problem.
 Can Jena API deal/help me with this??

You may find this helpful:
http://jena.apache.org/documentation/notes/rdf-frames.html

Ian


Re: Re: Jena Text Lucene Assembler file questions

2013-10-23 Thread Chris Dollin
On Tuesday, October 22, 2013 05:57:21 PM huey...@aol.com wrote:
 Seems it does not like the file extension. Renaming it now. Sorry for the 
 amount of mails.

When Jena reads a file it uses the file suffix to guess what language
the file is in. If it doesn't know the suffix it defaults to RDF/XML. So
if you have Turtle text in, say, myturtle.txt and try to read it in without
telling Jena that it's Turtle, the RDF/XML parser will object. (I got
content is not allowed in prolog; that's the RDF/XML parser assuming
the non-XML text its seeing is Just Stuff that would be skipped over,
but that is Not Allowed.)

Chris

-- 
The wizard seemed quite willing when I talked to him.  /Howl's Moving Castle/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)



Re: How can I implement pagination for ResultSet

2013-10-23 Thread Claus Stadler

Hi,

For the pagination issue combined with client side caching (and adding 
delay for not overloading the endpoint), I have written this utility lib 
some time ago:


https://github.com/AKSW/jena-sparql-api

Its currently for the prior Jena 2.10.0, but will be upgraded soon.

As for

 2) Get the size of ResultSet. but there are no way to get the total 
number that ResultSet contains.


A cheap way of getting the count is doing a query for it with Select 
(Count(*) As ?c) { { your original query here} }. Although I prefer 
modifying the projection in Jena's Query object as I dislike string hacks.



Best,
Claus


On 22.10.2013 19:21, Wang Dongsheng wrote:

By the way, I want to ask you two questions accordingly,

For 1), Can I get the total number first? cause it's better to
calculate how much pages there are in advance.
For 2), If the resultSet is very Large, will the transferring to List
being broken up easily?

On Tue, Oct 22, 2013 at 6:31 PM, Wang Dongsheng dswang2...@gmail.com wrote:

Hi Samuel,
  Thanks a lot, It's very cool~ :)

Sincere~
Wang



On Tue, Oct 22, 2013 at 4:22 PM, Samuel Croset samuel.cro...@gmail.com wrote:

Hi,

For 1) you can use the OFFSET and LIMIT constructs
For 2) You can use:  ResultSetFormatter.toList()

See this answer
http://answers.semanticweb.com/questions/9456/jena-pagination-for-sparql for
more details.

Cheers,

Samuel


On Tue, Oct 22, 2013 at 8:24 AM, Wang Dongsheng dswang2...@gmail.comwrote:


Hi, all
I want to implement pagination for ResultSet of Sparql.
I guess there are generally two ways:

1, Through a specified SPARQL format, but I dont know how to write the
query,
2. Get the size of ResultSet. but there are no way to get the total
number that ResultSet contains.

I prefer to implement the second way, But Doc of API seems unavailable.

Any one tried this kind of effort? Or it was not suitable to paginate
the result?

Thank in advance~




--
Dipl. Inf. Claus Stadler
Department of Computer Science, University of Leipzig
Research Group: http://aksw.org/
Workpage  WebID: http://aksw.org/ClausStadler
Phone: +49 341 97-32260



Re: Jena Text Lucene Assembler file questions

2013-10-23 Thread hueyl16
The file is called jena_assembler.ttl on my machine. I had to rename it to 
.txt so the mailing list attachment filter wouldn't remove it. I am getting the 
error that I attached earlier when executing this from the command line:

java -cp %FUSEKI_HOME%\fuseki-server.jar jena.textindexer 
--desc=C:\Development\Ontology\jena_assembler.ttl

-Wolfgang

 

 



 

 

-Original Message-
From: Chris Dollin chris.dol...@epimorphics.com
To: users users@jena.apache.org
Sent: Wed, Oct 23, 2013 1:33 pm
Subject: Re: Re: Jena Text Lucene Assembler file questions


On Tuesday, October 22, 2013 05:57:21 PM huey...@aol.com wrote:
 Seems it does not like the file extension. Renaming it now. Sorry for the 
amount of mails.

When Jena reads a file it uses the file suffix to guess what language
the file is in. If it doesn't know the suffix it defaults to RDF/XML. So
if you have Turtle text in, say, myturtle.txt and try to read it in without
telling Jena that it's Turtle, the RDF/XML parser will object. (I got
content is not allowed in prolog; that's the RDF/XML parser assuming
the non-XML text its seeing is Just Stuff that would be skipped over,
but that is Not Allowed.)

Chris

-- 
The wizard seemed quite willing when I talked to him.  /Howl's Moving Castle/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)


 


Re: Re: Jena Text Lucene Assembler file questions

2013-10-23 Thread Chris Dollin
On Wednesday, October 23, 2013 07:53:26 AM huey...@aol.com wrote:
 The file is called jena_assembler.ttl on my machine. I had to rename it to 
 .txt so the mailing list attachment filter wouldn't remove it. I am getting 
 the error that I attached earlier when executing this from the command line:
 
 java -cp %FUSEKI_HOME%\fuseki-server.jar jena.textindexer 
 --desc=C:\Development\Ontology\jena_assembler.ttl

I can read jena_assembler.ttl without problems (using jena.rdfcat).
Are you sure that's the right file?

Chris

-- 
It is seldom good news.  ~Crystal Ball~, /The Tough Guide to Fantasyland/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)



Re: Jena Text Lucene Assembler file questions

2013-10-23 Thread hueyl16
I just compared the file I sent with the local one that I am using and they are 
identical. I also just ran rdfcat and it reads the file just fine. Tried 
jena.textindexer again and that still fails.

 

 -Wolfgang



 

 

-Original Message-
From: Chris Dollin chris.dol...@epimorphics.com
To: users users@jena.apache.org
Sent: Wed, Oct 23, 2013 3:32 pm
Subject: Re: Re: Jena Text Lucene Assembler file questions


On Wednesday, October 23, 2013 07:53:26 AM huey...@aol.com wrote:
 The file is called jena_assembler.ttl on my machine. I had to rename it to 
.txt so the mailing list attachment filter wouldn't remove it. I am getting the 
error that I attached earlier when executing this from the command line:
 
 java -cp %FUSEKI_HOME%\fuseki-server.jar jena.textindexer 
 --desc=C:\Development\Ontology\jena_assembler.ttl

I can read jena_assembler.ttl without problems (using jena.rdfcat).
Are you sure that's the right file?

Chris

-- 
It is seldom good news.  ~Crystal Ball~, /The Tough Guide to Fantasyland/

Epimorphics Ltd, http://www.epimorphics.com
Registered address: Court Lodge, 105 High Street, Portishead, Bristol BS20 6PT
Epimorphics Ltd. is a limited company registered in England (number 7016688)


 


Re: Jena Text Lucene Assembler file questions

2013-10-23 Thread Dave Reynolds

On 23/10/13 17:04, huey...@aol.com wrote:

I just compared the file I sent with the local one that I am using and they are 
identical. I also just ran rdfcat and it reads the file just fine. Tried 
jena.textindexer again and that still fails.


You are using relative URIs and those are what the parser seems to be 
complaining about. For some reason, judging from your error messages, 
the base URI is being taken as the windows directory path instead of 
being a legal (file:) URI.


I don't know why that's happening but a suggested work round would be to 
avoid relative URIs - replace your uses of #dataset, #indexLucene 
and #entMap with :dataset, :indexLucene and :entMap.


Dave



-Original Message-
From: Chris Dollin chris.dol...@epimorphics.com
To: users users@jena.apache.org
Sent: Wed, Oct 23, 2013 3:32 pm
Subject: Re: Re: Jena Text Lucene Assembler file questions


On Wednesday, October 23, 2013 07:53:26 AM huey...@aol.com wrote:

The file is called jena_assembler.ttl on my machine. I had to rename it to

.txt so the mailing list attachment filter wouldn't remove it. I am getting the
error that I attached earlier when executing this from the command line:


java -cp %FUSEKI_HOME%\fuseki-server.jar jena.textindexer 
--desc=C:\Development\Ontology\jena_assembler.ttl


I can read jena_assembler.ttl without problems (using jena.rdfcat).
Are you sure that's the right file?

Chris