Re: Jena TDB OOME GC overhead limit exceeded

2016-07-27 Thread Dick Murray
The MWE in the previous email will work with any even line text file and
will produce the odd [B values. I can't see anywhere obvious where the non
Jena code is creating them, just odd that there's so many of them!

OK, that knocks the DBB idea on the head!

I'll set the mapped symbol and play with batch sizes. Can the map location
be configured or will it go after the TDB location?

Is "TDB2" what we discussed some time back? I'm happy to provide some
testing on that as I've ~2000 files to ETL via an automated process each
producing 3-4M quads...

Thanks Dick.

On 27 Jul 2016 20:10, "Andy Seaborne"  wrote:
>
> On 27/07/16 13:19, Dick Murray wrote:
>>
>> ;-) Yes I did. But then I switched to the actual files I need to import
and
>> they produce ~3.5M triples...
>>
>> Using normal Jena 3.1 (i.e. no special context symbols set) the commit
>> after 100k triples works to import the file 10 times with the [B varying
>> between ~2Mb and ~4Mb. I'm currently testing a 20 instance pass.
>>
>> A batched commit works for this bulk load because if it fails after a
batch
>> commit I can remove the graph.
>>
>> For my understanding... TDB is holding the triples/block/journal in heap
>> until commit is called? But this doesn't account for the [B not being
>> cleared after a commit of 3.5M triples. It takes another pass plus ~2M
>> uncommited triples before I get an OOME.
>
>
> And the [B have a strange average size.  A block is 8K.
>
>> Digging around and there are some references made to the
DirectByteBuffers
>> causing issues. IBM
>>
https://www.ibm.com/developerworks/community/blogs/kevgrig/entry/excessive_native_memory_usage_by_directbytebuffers?lang=en
>> links the problem to;
>>
>> Essentially the problem boils down to either:
>>
>>1. There are too many DBBs being allocated (or they are too large),
>>and/or
>>2. The DBBs are not being cleared up quickly enough.
>>
>
> TDB does not use DirectByteBuffers unless you ask it to.  They are not [B.
>
> .hasArray is false.
> .array() throws UnsupportedOperationException.
>
> (Grep the code for "allocateDirect" and trace back the use of single use
of BufferAllocatorDirect to the journal in "direct" mode.)
>
> I can believe that if activated, that the GC recycling would be slow. The
code ought to recycle them (beause yuo can't explicitly free them for some
weird reason - they little more than malloc).
>
> But they are not being used unless you ask for them.
>
> Journal entries are 8K unless they are commit records which are about 20
bytes (I think).
>
>
>
>>
>> and recommends using -XX:MaxDirectMemorySize=1024m to poke the GC via
>> System.gc(). Not sure if GC1C helps because of it's new heap model...
>>
>> Would it be possible to get Jena to write it's uncommitted triples to
disk
>> and then commit them to the TDB?
>
>
> Set TDB.transactionJournalWriteBlockMode to "mapped". That uses a disk
file.
>
>
>> Ok it's slower than RAM but until they are
>> committed only one thread has visibility anyway? Could direct that at a
>> different disk as well...
>>
>> Just before hitting send I'm at pass 13 and the [B maxed at just over 4Gb
>> before dropping back to 2Gb.
>
>
> Or use TDB2 :-)
>
> It has no problem loading 100m+ triples in a single transaction (the
space per transaction is fixed at about 80 bytes of transaction - disk
writes happen during the transaction not to a roll-forward journal). And it
should be a bit faster because writes happen once.
>
> Just need to find time to clean it up ...
>
> Andy
>
>
>>
>> Dick.
>>
>>
>>
>> On 27 July 2016 at 11:47, Andy Seaborne  wrote:
>>
>>> On 27/07/16 11:22, Dick Murray wrote:
>>>
 Hello.

 Something doesn't add up here... I've run repeated tests with the
 following
 MWE on a 16GB machine with -Xms8g -Xmx8g and the I always get an OOME.

 What I don't understand is the size of [B increases with each pass
until
 the OOME is thrown. The exact same process is run 5 times with a new
graph
 for each set of triples.

 There are ~3.5M triples added within the transaction from a file which
is
 a
 "simple" text based file (30Mb) which is read in line pairs.

>>>
>>> Err - you said 200k quads earlier!
>>>
>>> Set
>>>
>>> TransactionManager.QueueBatchSize=0 ;
>>>
>>> and break the load into small units for now and see if that helps.
>>>
>>> One experiment would be to write the output to disk and load from a
>>> program that only does the TDB part.
>>>
>>> Andy
>>>
>>>
>>>
 I've tested sequential loads of other text files (i.e. file x *5) and
 other
 text files loaded sequentally (i.e. file x, file y, file ...) and the
same
 result is exhibited.

 If I reduce -Xmx to 6g it will fail earlier.

 Changing the GC using -XX:+UseGC1C doesn't alter the outcome.

 I'm running on Ubuntu 16.04 with Java 1.8 and I can replicate this on
 Centos 7 with Java 1.8.

 Any ideas?

 Regards 

Re: Jena TDB OOME GC overhead limit exceeded

2016-07-27 Thread Andy Seaborne

On 27/07/16 13:19, Dick Murray wrote:

;-) Yes I did. But then I switched to the actual files I need to import and
they produce ~3.5M triples...

Using normal Jena 3.1 (i.e. no special context symbols set) the commit
after 100k triples works to import the file 10 times with the [B varying
between ~2Mb and ~4Mb. I'm currently testing a 20 instance pass.

A batched commit works for this bulk load because if it fails after a batch
commit I can remove the graph.

For my understanding... TDB is holding the triples/block/journal in heap
until commit is called? But this doesn't account for the [B not being
cleared after a commit of 3.5M triples. It takes another pass plus ~2M
uncommited triples before I get an OOME.


And the [B have a strange average size.  A block is 8K.


Digging around and there are some references made to the DirectByteBuffers
causing issues. IBM
https://www.ibm.com/developerworks/community/blogs/kevgrig/entry/excessive_native_memory_usage_by_directbytebuffers?lang=en
links the problem to;

Essentially the problem boils down to either:

   1. There are too many DBBs being allocated (or they are too large),
   and/or
   2. The DBBs are not being cleared up quickly enough.



TDB does not use DirectByteBuffers unless you ask it to.  They are not [B.

.hasArray is false.
.array() throws UnsupportedOperationException.

(Grep the code for "allocateDirect" and trace back the use of single use 
of BufferAllocatorDirect to the journal in "direct" mode.)


I can believe that if activated, that the GC recycling would be slow. 
The code ought to recycle them (beause yuo can't explicitly free them 
for some weird reason - they little more than malloc).


But they are not being used unless you ask for them.

Journal entries are 8K unless they are commit records which are about 20 
bytes (I think).





and recommends using -XX:MaxDirectMemorySize=1024m to poke the GC via
System.gc(). Not sure if GC1C helps because of it's new heap model...

Would it be possible to get Jena to write it's uncommitted triples to disk
and then commit them to the TDB?


Set TDB.transactionJournalWriteBlockMode to "mapped". That uses a disk file.


Ok it's slower than RAM but until they are
committed only one thread has visibility anyway? Could direct that at a
different disk as well...

Just before hitting send I'm at pass 13 and the [B maxed at just over 4Gb
before dropping back to 2Gb.


Or use TDB2 :-)

It has no problem loading 100m+ triples in a single transaction (the 
space per transaction is fixed at about 80 bytes of transaction - disk 
writes happen during the transaction not to a roll-forward journal). 
And it should be a bit faster because writes happen once.


Just need to find time to clean it up ...

Andy



Dick.



On 27 July 2016 at 11:47, Andy Seaborne  wrote:


On 27/07/16 11:22, Dick Murray wrote:


Hello.

Something doesn't add up here... I've run repeated tests with the
following
MWE on a 16GB machine with -Xms8g -Xmx8g and the I always get an OOME.

What I don't understand is the size of [B increases with each pass until
the OOME is thrown. The exact same process is run 5 times with a new graph
for each set of triples.

There are ~3.5M triples added within the transaction from a file which is
a
"simple" text based file (30Mb) which is read in line pairs.



Err - you said 200k quads earlier!

Set

TransactionManager.QueueBatchSize=0 ;

and break the load into small units for now and see if that helps.

One experiment would be to write the output to disk and load from a
program that only does the TDB part.

Andy




I've tested sequential loads of other text files (i.e. file x *5) and
other
text files loaded sequentally (i.e. file x, file y, file ...) and the same
result is exhibited.

If I reduce -Xmx to 6g it will fail earlier.

Changing the GC using -XX:+UseGC1C doesn't alter the outcome.

I'm running on Ubuntu 16.04 with Java 1.8 and I can replicate this on
Centos 7 with Java 1.8.

Any ideas?

Regards Dick.











Query normalization for detection of interchangeable queries

2016-07-27 Thread Jindřich Mynarz
Hi,

I want to be able to tell if SPARQL queries are interchangeable: their
semantics is the same and they lead to the same results. I'd appreciate any
tips on detecting interchangeable queries using Jena.

Here's what I tried so far. I start with computationally cheaper
comparisons and continue with more expensive ones if the compared queries
aren't detected as interchangeable. First, I compare the queries as strings
to check easy verbatim matches.

If the compared queries don't match, I parse them to instances of
org.apache.jena.query.Query and compare them
using org.apache.jena.sparql.core.QueryCompare. This detects
interchangeable queries that have minor syntax differences, such as
different character case of SPARQL clauses (e.g., "SELECT" vs. "select").
However, for example queries using the same IRI as absolute IRI vs. compact
IRI are treated as different by QueryCompare.

Therefore, If queries aren't detected as interchangeable in this step, I
convert them to SPARQL algebra using the compile() method of
org.apache.jena.sparql.algebra.Algebra and compare them as the resulting
algebra objects. In this way queries with absolute/compact forms of the
same IRI are treated as equal. However, there other interchangeable queries
that produce unequal algebra. For example (the queries I mentioned in
https://mail-archives.apache.org/mod_mbox/jena-users/201607.mbox/browser):

# Query 1
PREFIX skos: 

SELECT *
WHERE {
  ?concept skos:broader [ skos:prefLabel ?broaderLabel ] .
}

# Query 2
PREFIX skos: 

SELECT *
WHERE {
  ?concept skos:broader/skos:prefLabel ?broaderLabel .
}

This is why I try another step to detect interchangeable queries, which is
to perform algebra optimization. However, simply calling Algebra.optimize()
on the example queries doesn't make their algebra equal. However, there's a
work-around using a custom NodeIsomorphismMap (see
https://mail-archives.apache.org/mod_mbox/jena-users/201607.mbox/browser)
that compares the queries as equal.

Nevertheless, even with these provisions, there are other kinds of
interchangeable queries that are treated as distinct. For example:

- Queries using blank nodes or unprojected variables
- Queries with different order of UNION clauses
- Queries expressing the same disjunction using UNION, VALUES, or property
path with alternatives

I suspect there is a way to make the algebra optimization more
"aggressive", so that it produces equal algebra for the above kinds of
interchangeable queries. I read Rob Vesse's excellent slides on query
optimization in Jena (
http://events.linuxfoundation.org/sites/events/files/slides/SPARQL%20Optimisation%20101%20Tutorial.pdf)
and it seems to me that much of what I need is already possible in Jena. I
see there are many algebra transformers (
https://github.com/apache/jena/tree/master/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize)
that can be enabled in the org.apache.jena.sparql.util.Context passed to
the Algebra.optimize() method. Would you recommend enabling some
optimizations that are not enabled in the default Context (i.e.
ARQ.getContext())? I also found some unreachable code
in org.apache.jena.sparql.algebra.optimize.Optimize (
https://github.com/apache/jena/blob/master/jena-arq/src/main/java/org/apache/jena/sparql/algebra/optimize/Optimize.java#L136-L142).
Was it left in the code for documentation?

Overall, would you say that the approach to detecting interchangeable
queries via algebra optimizations is a good one? Would you suggest a
different approach?

- Jindřich

-- 
Jindřich Mynarz
http://mynarz.net/#jindrich


Re: Unequal SPARQL algebras

2016-07-27 Thread Jindřich Mynarz
On Wed, Jul 27, 2016 at 12:36 PM, Andy Seaborne  wrote:
>
> ARQ does have some isomorphism support:
>>>
>>>Op.isEqualTo(Op other, NodeIsomorphismMap labelMap)
>>>
>>>
>> I found only Op.equalTo (
>>
>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/sparql/algebra/Op.html#equalTo-org.apache.jena.sparql.algebra.Op-org.apache.jena.sparql.util.NodeIsomorphismMap-
>> ).
>>
>
> yes - that's it.  (I copied the declaration - it has argument names)


OK. I was only confused by seeing Op.isEqualTo in your example, while I
found Op.equalTo.

Why is a subclass of NodeIsomorphismMap needed instead of using
>> NodeIsomorphismMap directly? Do I need to override some methods of
>> NodeIsomorphismMap?
>>
>
> makeIsomorphic(Node n1, Node n2) says:
>
>if ( n1.isBlank() && n2.isBlank() )
>
> and ??0 is not a blank node - it's a variable.
>
> To work round the private methods (get() and put() - I'll change that),
> you'll need to rewrite the whole thing: I tried:
>
> NodeIsomorphismMap m2 = new NodeIsomorphismMap() {
> private Map map = new HashMap<>() ;
>
> protected Node get(Node key)
> { return map.get(key) ; }
>
> protected void put(Node key, Node value)
> { map.put(key, value) ; }
>
> @Override
> public boolean makeIsomorphic(Node n1, Node n2)
> {
> if ( (Var.isBlankNodeVar(n1) || n1.isBlank() ) &&
>  ( Var.isBlankNodeVar(n2) || n2.isBlank() ) )
> {
> Node other = get(n1) ;
> if ( other == null )
> {
> put(n1, n2) ;
> return true ;
> }
> return other.equals(n2) ;
> }
> return n1.equals(n2) ;
> }
> } ;
>

Thanks! I replicated it (in Clojure) and I can confirm that it works for my
example.

- Jindřich


Re: Jena TDB OOME GC overhead limit exceeded

2016-07-27 Thread Dick Murray
;-) Yes I did. But then I switched to the actual files I need to import and
they produce ~3.5M triples...

Using normal Jena 3.1 (i.e. no special context symbols set) the commit
after 100k triples works to import the file 10 times with the [B varying
between ~2Mb and ~4Mb. I'm currently testing a 20 instance pass.

A batched commit works for this bulk load because if it fails after a batch
commit I can remove the graph.

For my understanding... TDB is holding the triples/block/journal in heap
until commit is called? But this doesn't account for the [B not being
cleared after a commit of 3.5M triples. It takes another pass plus ~2M
uncommited triples before I get an OOME.

Digging around and there are some references made to the DirectByteBuffers
causing issues. IBM
https://www.ibm.com/developerworks/community/blogs/kevgrig/entry/excessive_native_memory_usage_by_directbytebuffers?lang=en
links the problem to;

Essentially the problem boils down to either:

   1. There are too many DBBs being allocated (or they are too large),
   and/or
   2. The DBBs are not being cleared up quickly enough.


and recommends using -XX:MaxDirectMemorySize=1024m to poke the GC via
System.gc(). Not sure if GC1C helps because of it's new heap model...

Would it be possible to get Jena to write it's uncommitted triples to disk
and then commit them to the TDB? Ok it's slower than RAM but until they are
committed only one thread has visibility anyway? Could direct that at a
different disk as well...

Just before hitting send I'm at pass 13 and the [B maxed at just over 4Gb
before dropping back to 2Gb.

Dick.



On 27 July 2016 at 11:47, Andy Seaborne  wrote:

> On 27/07/16 11:22, Dick Murray wrote:
>
>> Hello.
>>
>> Something doesn't add up here... I've run repeated tests with the
>> following
>> MWE on a 16GB machine with -Xms8g -Xmx8g and the I always get an OOME.
>>
>> What I don't understand is the size of [B increases with each pass until
>> the OOME is thrown. The exact same process is run 5 times with a new graph
>> for each set of triples.
>>
>> There are ~3.5M triples added within the transaction from a file which is
>> a
>> "simple" text based file (30Mb) which is read in line pairs.
>>
>
> Err - you said 200k quads earlier!
>
> Set
>
> TransactionManager.QueueBatchSize=0 ;
>
> and break the load into small units for now and see if that helps.
>
> One experiment would be to write the output to disk and load from a
> program that only does the TDB part.
>
> Andy
>
>
>
>> I've tested sequential loads of other text files (i.e. file x *5) and
>> other
>> text files loaded sequentally (i.e. file x, file y, file ...) and the same
>> result is exhibited.
>>
>> If I reduce -Xmx to 6g it will fail earlier.
>>
>> Changing the GC using -XX:+UseGC1C doesn't alter the outcome.
>>
>> I'm running on Ubuntu 16.04 with Java 1.8 and I can replicate this on
>> Centos 7 with Java 1.8.
>>
>> Any ideas?
>>
>> Regards Dick.
>>
>>
>
>


Re: Setting error handler for WriterGraph/DatasetRIOT

2016-07-27 Thread Andy Seaborne

On 27/07/16 00:08, Martynas Jusevičius wrote:

On 3.0.1

  RDFWriter w = model.getWriter("RDF/XML");
  w.setProperty("allowBadURIs", true);

does not work -- calls RDFWriterRIOT.setProperty() instead of
BaseXMLWriter.setProperty(), so "allowBadURIs" has no effect.

Any workaround ideas?


It works in 3.1.0 - JENA-1168.

I don't see a way to make it work in 3.0.1 but you could create the 
implementation and use the old interface. 
org.apache.jena.rdfxml.xmloutput.impl.Basic


SPIN probably works with 3.1.0 - try it, or download SPIN and compile 
with 3.1.0 or ask Holger.


Andy




On Tue, Jul 26, 2016 at 11:23 AM, Martynas Jusevičius
 wrote:

Andy,

"allowBadURIs" was my next move, I will try that later today and report back.

Any reason why this cannot be exposed uniformly on the WriterRIOT
level? Like it is on ReaderRIOT.

On Tue, Jul 26, 2016 at 11:15 AM, Andy Seaborne  wrote:

Turtle-class syntaxes print bad URIs.

For RDF/XML, does setting "allowBadURIs" work?

https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output

Andy


On 26/07/16 09:34, Martynas Jusevičius wrote:


RDF/XML (plain) in this case. I would of course prefer a
format-agnostic solution.

On Tue, Jul 26, 2016 at 10:21 AM, Andy Seaborne  wrote:


Which serialization format are you working with?

Andy


On 25/07/16 22:44, Martynas Jusevičius wrote:



Hey,

I was planning to set an ErrorHandler on WriterGraphRIOT instance, but
it turns such setter does not exist.

My ErrorHandler allows invalid URIs to be read without throwing
exceptions. However model.write() throws BadURIException when writing
them. So round-tripping such Model currently does not work. How do I
handler writer errors?

I think it would make sense to reuse the error handler between RIOT
readers and writers.
For example, if it is set to strict, both throw exceptions on invalid
URIs.
If it is set to lax, invalid URIs are allowed during both during
parsing and writing.
That would make round-tripping easy.

Martynas
atomgraph.com









Re: Setting error handler for WriterGraph/DatasetRIOT

2016-07-27 Thread Andy Seaborne

On 27/07/16 10:18, Martynas Jusevičius wrote:

Our use case is round-tripping, so after I solved reading I moved on
to writing (and started a new thread).

What I probably haven't made clear is that there is no intermediate
data structure holding the form data. It is being read directly into a
Model just like any other RDF format, using
application/x-www-form-urlencoded media type and RDF/POST encoding:
http://www.lsrn.org/semweb/rdfpost.html

Could you give an example of how you see ParserProfile being used here?



Surely RDFPostReader.java calls the parser profile to create Nodes some how?

If need be, you write your own for your specific policies.  it's an 
interface.


Andy





Re: Jena TDB OOME GC overhead limit exceeded

2016-07-27 Thread Andy Seaborne

On 27/07/16 11:22, Dick Murray wrote:

Hello.

Something doesn't add up here... I've run repeated tests with the following
MWE on a 16GB machine with -Xms8g -Xmx8g and the I always get an OOME.

What I don't understand is the size of [B increases with each pass until
the OOME is thrown. The exact same process is run 5 times with a new graph
for each set of triples.

There are ~3.5M triples added within the transaction from a file which is a
"simple" text based file (30Mb) which is read in line pairs.


Err - you said 200k quads earlier!

Set

TransactionManager.QueueBatchSize=0 ;

and break the load into small units for now and see if that helps.

One experiment would be to write the output to disk and load from a 
program that only does the TDB part.


Andy



I've tested sequential loads of other text files (i.e. file x *5) and other
text files loaded sequentally (i.e. file x, file y, file ...) and the same
result is exhibited.

If I reduce -Xmx to 6g it will fail earlier.

Changing the GC using -XX:+UseGC1C doesn't alter the outcome.

I'm running on Ubuntu 16.04 with Java 1.8 and I can replicate this on
Centos 7 with Java 1.8.

Any ideas?

Regards Dick.






Re: Unequal SPARQL algebras

2016-07-27 Thread Andy Seaborne

On 27/07/16 11:13, Jindřich Mynarz wrote:

Hi Andy,

On Wed, Jul 27, 2016 at 11:56 AM, Andy Seaborne  wrote:


Two algebra expressions are equal if they are the same structures,
including variable names.

ARQ does have some isomorphism support:

   Op.isEqualTo(Op other, NodeIsomorphismMap labelMap)



I found only Op.equalTo (
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/sparql/algebra/Op.html#equalTo-org.apache.jena.sparql.algebra.Op-org.apache.jena.sparql.util.NodeIsomorphismMap-
).


yes - that's it.  (I copied the declaration - it has argument names)



but those bnodes are concrete ones, not query generated ones.


See Iso.nodeIso which has some provision but
NodeIsomorphismMap.makeIsomorphic only covers concrete (data) bnodes.

A subclass of NodeIsomorphismMap and isEqualTo could so generate variable
isomorphism (I checked on your example).



Why is a subclass of NodeIsomorphismMap needed instead of using
NodeIsomorphismMap directly? Do I need to override some methods of
NodeIsomorphismMap?


makeIsomorphic(Node n1, Node n2) says:

   if ( n1.isBlank() && n2.isBlank() )

and ??0 is not a blank node - it's a variable.

To work round the private methods (get() and put() - I'll change that), 
you'll need to rewrite the whole thing: I tried:


NodeIsomorphismMap m2 = new NodeIsomorphismMap() {
private Map map = new HashMap<>() ;

protected Node get(Node key)
{ return map.get(key) ; }

protected void put(Node key, Node value)
{ map.put(key, value) ; }

@Override
public boolean makeIsomorphic(Node n1, Node n2)
{
if ( (Var.isBlankNodeVar(n1) || n1.isBlank() ) &&
 ( Var.isBlankNodeVar(n2) || n2.isBlank() ) )
{
Node other = get(n1) ;
if ( other == null )
{
put(n1, n2) ;
return true ;
}
return other.equals(n2) ;
}
return n1.equals(n2) ;
}
} ;

Caution: I only tried this on your example.

We can't make this change generally - we need the more specific 
data-only bnodes for the tests.


Andy





- Jindřich





Re: Jena TDB OOME GC overhead limit exceeded

2016-07-27 Thread Dick Murray
Hello.

Something doesn't add up here... I've run repeated tests with the following
MWE on a 16GB machine with -Xms8g -Xmx8g and the I always get an OOME.

What I don't understand is the size of [B increases with each pass until
the OOME is thrown. The exact same process is run 5 times with a new graph
for each set of triples.

There are ~3.5M triples added within the transaction from a file which is a
"simple" text based file (30Mb) which is read in line pairs.

I've tested sequential loads of other text files (i.e. file x *5) and other
text files loaded sequentally (i.e. file x, file y, file ...) and the same
result is exhibited.

If I reduce -Xmx to 6g it will fail earlier.

Changing the GC using -XX:+UseGC1C doesn't alter the outcome.

I'm running on Ubuntu 16.04 with Java 1.8 and I can replicate this on
Centos 7 with Java 1.8.

Any ideas?

Regards Dick.


dick@Dick-M3800:~$ uname -a
Linux Dick-M3800 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC
2016 x86_64 x86_64 x86_64 GNU/Linux
dick@Dick-M3800:~$ java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
dick@Dick-M3800:~$


Complete code example below which shows this error, followed by output of
said program. This will attempt to exec jps and jmap...

package org.iungo.dxf;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

import org.apache.jena.graph.Node;
import org.apache.jena.graph.NodeFactory;
import org.apache.jena.query.ReadWrite;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.tdb.TDBFactory;

public class DXFStream {
static String pid = pid();
public static void main(final String[] args) {

Objects.requireNonNull(pid);
final String dg =
"/home/dick/eclipse-jee-neon/git/iungo-core/iungo-core/tdb-dataset-node";
final String dxf =
"file:///home/dick/eclipse-jee-neon/git/iungo-ssl/iungo-ssl/test/resources/0005_-SSL-XXX-XX-DR-U-0200.dxf";
try {
mem();
log("open");
final DatasetGraph datasetGraph = TDBFactory.createDatasetGraph(dg);
for (int i = 1; i <= 5; i++) {
log("Pass " + String.valueOf(i));
try {
mem();
log("begin WRITE");
datasetGraph.begin(ReadWrite.WRITE);
Node g = NodeFactory.createURI(UUID.randomUUID().toString());
Node pk = NodeFactory.createURI("k");
Node pv = NodeFactory.createURI("v");
final BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(new URL(dxf).openStream(), StandardCharsets.UTF_8));
String key = null;
String value = null;
Integer count = 0;
while ((key = bufferedReader.readLine()) != null) {
key = key.trim();
if ((value = bufferedReader.readLine()) == null) {
throw new UnsupportedOperationException();
}
count++;
datasetGraph.add(g, NodeFactory.createURI(count.toString()), pk,
NodeFactory.createLiteral(key));
datasetGraph.add(g, NodeFactory.createURI(count.toString()), pv,
NodeFactory.createLiteral(value));
}
bufferedReader.close();
mem();
log(count * 2 + " commit");
datasetGraph.commit();
} catch (final Throwable throwable) {
System.err.println(throwable);
mem();
log("abort");
datasetGraph.abort();
} finally {
mem();
log("end");
datasetGraph.end();
}
}
mem();
log("close");
datasetGraph.close();
} catch (final Throwable throwable) {
System.err.println(throwable);
}
log("exit");
}
public static String pid() {
log("pid");
try {
String pid = null;
final Process p = Runtime.getRuntime().exec(new String[]{"jps", "-m"});
final BufferedReader pbr = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line = null;
while ((line = pbr.readLine()) != null) {
final String name = line.substring(line.indexOf(" ")).trim();
if (name.equals("DXFStream")) {
pid = line.substring(0, line.indexOf(" "));
log(line);
break;
}
}
p.waitFor();
pbr.close();
log(pid);
return pid;
} catch (final Throwable throwable) {
System.err.println(throwable);
return null;
}
}
public static void jmap() {
log("jmap");
try {
// JVM doesn't like | so use a list then stream and limit to 13...
final Process p = Runtime.getRuntime().exec(new String[]{"jmap", "-histo",
pid});
List lines = new LinkedList<>();
String line = null;
final BufferedReader pbr = new BufferedReader(new
InputStreamReader(p.getInputStream()));
while ((line = pbr.readLine()) != null) {
lines.add(line);
}
p.waitFor();
pbr.close();
lines
.stream()
.limit(13)
.forEach(text -> System.out.println(text));
} catch (final Throwable throwable) {
System.err.println(throwable);
}
}
public static void mem() {
log(Runtime.getRuntime().freeMemory() + " " +
Runtime.getRuntime().totalMemory() + " " +
Runtime.getRuntime().maxMemory());
jmap();
}
public static void log(final String text) {
System.out.println(Instant.now() + " " + text);
}
}


Output;

2016-07-27T09:47:28.013Z pid
2016-07-27T09:47:28.265Z 24777 DXFStream

Re: Jena generic rules

2016-07-27 Thread javed khan
Thanks Dave and Lorenz for your time, I finally fixed it.

I passed "model" as second orgument to QueryExecutionFactory , which should
be InfModel rather..

QueryExecution qe=QueryExecutionFactory.create(query, inf);

regards

On Wed, Jul 27, 2016 at 2:10 AM, Dave Reynolds 
wrote:

> On 27/07/16 09:54, javed khan wrote:
>
>> Sorry but still not working.
>>
>> When I query instances of Expert, it shows "Tim" which is fine. When I
>> query instance of Student, it shows "Khan", which is also fine.
>> Even when I query both in one, it shows "Khan" which is also ok because
>> Khan is also Expert and Student, but when I try to assign it(Khan) to
>> another class, it does not work.
>>
>
> That's too imprecise to comment on.
>
> If you can show exactly your data and your rules then we might be able to
> spot the problem.
>
> I am afraid if Jena generic rules does not work on classes and only it
>> supports properties like transitive property and inverse property.
>>
>
> Generic rules just work in terms of triples. They can be used on instances
> or classes equally well. You just need to be clear on what you rules need
> to do and write the patterns accordingly.
>
> Dave
>
>
>
> On Wed, Jul 27, 2016 at 1:39 AM, javed khan  wrote:
>>
>>   
>>>
>>> are wrong. Either use the correct URI:
>>>
>>> 
>>>
>>> or use the prefix form:
>>>
>>> rdf:type
>>>
>>>
>>> I am sorry due to too many threads, I did not read this reply.
>>>
>>> Thanks Dave, let me try.
>>>
>>> On Wed, Jul 27, 2016 at 1:35 AM, Dave Reynolds <
>>> dave.e.reyno...@gmail.com>
>>> wrote:
>>>
>>> See my earlier reply, you had an error in the URLs in your rules.

 Dave


 On 27/07/16 09:33, javed khan wrote:

 If my email (code) is not understandable, I am just explaining in plain
> text.
>
> I have class Expert which have some researches i-e "Tim hasResearch
> Ontologies". I have another class Student (subclasses Master Phd). Khan
> is
> instance of Phd class (ultimately of Student class also). Phd student
> can
> also have some researches as Expert class and have type both : Student
> and
> Expert in Protege.
>
> I want instances which are both in Student and Expert i-e Khan in this
> case.
>
> If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
> std:StudentExpert (a new class in the ontology).
>
> my query is : select * where { ?x rdf:type std:StudentExpert}
>
> On Wed, Jul 27, 2016 at 1:20 AM, javed khan 
> wrote:
>
> I am sorry that is just the mistake when I copy code from my IDE to
>
>> email.
>> In the original code, its written just once.
>>
>> On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
>> buehm...@informatik.uni-leipzig.de> wrote:
>>
>> I'm not an expert, but why do you have each URI twice in the rule?
>>
>>>
>>> I have rule body:I want instance x which are in both classes to
>>> assign
>>>

 to
>>>
>>> another class "StudentExpert" which have no other instances. But does

 not
>>>
>>> work.
 (My Owl inverse property and transitive property rule works but this
 generic rule does not work)

 String rule = "*[rule1:(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
 
 http://www.semanticweb.org/141#Student
 ) " +*
 *  "(?x
 http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
 
 http://www.semanticweb.org/141#Expert
  )" + *

"->(?x
 http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
 http://www.semanticweb.org/141#StudentExpert )]";

 After prefixes, my query is:

 "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";

 My Reasoner and InfModel classes are:

 Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

 InfModel inf = ModelFactory.createInfModel(reasoner2, model);

 Then query is executed as usual in jena.




 On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <

 dave.e.reyno...@gmail.com>
>>>
>>> wrote:

 On 25/07/16 19:33, javed khan wrote:

>
> I have a Student class (Phd students) and Teacher class, having
>
>>
>> instances.
>

>>> There are some students which are also Teacher (teaching to junior


Re: Unequal SPARQL algebras

2016-07-27 Thread Jindřich Mynarz
Hi Andy,

On Wed, Jul 27, 2016 at 11:56 AM, Andy Seaborne  wrote:
>
> Two algebra expressions are equal if they are the same structures,
> including variable names.
>
> ARQ does have some isomorphism support:
>
>Op.isEqualTo(Op other, NodeIsomorphismMap labelMap)
>

I found only Op.equalTo (
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/sparql/algebra/Op.html#equalTo-org.apache.jena.sparql.algebra.Op-org.apache.jena.sparql.util.NodeIsomorphismMap-
).

but those bnodes are concrete ones, not query generated ones.
>
> See Iso.nodeIso which has some provision but
> NodeIsomorphismMap.makeIsomorphic only covers concrete (data) bnodes.
>
> A subclass of NodeIsomorphismMap and isEqualTo could so generate variable
> isomorphism (I checked on your example).
>

Why is a subclass of NodeIsomorphismMap needed instead of using
NodeIsomorphismMap directly? Do I need to override some methods of
NodeIsomorphismMap?

- Jindřich


Re: Unequal SPARQL algebras

2016-07-27 Thread Andy Seaborne

On 27/07/16 09:25, Jindřich Mynarz wrote:

Hi,

I'm wondering why Jena thinks the optimized SPARQL algebras of the
following queries are different:

# Query 1
PREFIX skos: 

SELECT *
WHERE {
  ?concept skos:broader [ skos:prefLabel ?broaderLabel ] .
}

# Query 1 algebra
(bgp
  (triple ?concept  ??0)
  (triple ??0  ?broaderLabel)
)

# Query 2
PREFIX skos: 

SELECT *
WHERE {
  ?concept skos:broader/skos:prefLabel ?broaderLabel .
}

# Query 2 algebra
(bgp
  (triple ?concept  ??P4)
  (triple ??P4 
?broaderLabel)
)

When I compare if the query 1 algebra is equal to the query 2 algebra,
false is returned. However, the only difference I can spot between the
algebras is in the names of the non-distinguished variables ??0 and ??P4.
Why are the query algebras treated as different?


Two algebra expressions are equal if they are the same structures, 
including variable names.


ARQ does have some isomorphism support:

   Op.isEqualTo(Op other, NodeIsomorphismMap labelMap)

but those bnodes are concrete ones, not query generated ones.

See Iso.nodeIso which has some provision but 
NodeIsomorphismMap.makeIsomorphic only covers concrete (data) bnodes.


A subclass of NodeIsomorphismMap and isEqualTo could so generate 
variable isomorphism (I checked on your example).



There are cases where subqueries have different scope variables (they 
don't make the final results so changing their name does not change the 
outcome). But that does not fit the structural isomorphism code in ARQ 
so it would need a new algorithm.


Names matter: the two are different:

   (bgp (?X ?Y ?O))

   (bgp (?s ?p ?o))

BTW The queries are different are higher levels of entailment.  Paths 
don't play a part of entailment matching.


Andy



- Jindřich





Re: Jena generic rules

2016-07-27 Thread Lorenz B.
Please provide  a minimal running example that does not work

1) minimal data - in Turtle format
2) the rule that you use
3) the code that performs the rule loading + querying

> Sorry but still not working.
>
> When I query instances of Expert, it shows "Tim" which is fine. When I
> query instance of Student, it shows "Khan", which is also fine.
> Even when I query both in one, it shows "Khan" which is also ok because
> Khan is also Expert and Student, but when I try to assign it(Khan) to
> another class, it does not work.
>
> I am afraid if Jena generic rules does not work on classes and only it
> supports properties like transitive property and inverse property.
>
> On Wed, Jul 27, 2016 at 1:39 AM, javed khan  wrote:
>
>>  
>>
>> are wrong. Either use the correct URI:
>>
>>
>>
>> or use the prefix form:
>>
>>rdf:type
>>
>>
>> I am sorry due to too many threads, I did not read this reply.
>>
>> Thanks Dave, let me try.
>>
>> On Wed, Jul 27, 2016 at 1:35 AM, Dave Reynolds 
>> wrote:
>>
>>> See my earlier reply, you had an error in the URLs in your rules.
>>>
>>> Dave
>>>
>>>
>>> On 27/07/16 09:33, javed khan wrote:
>>>
 If my email (code) is not understandable, I am just explaining in plain
 text.

 I have class Expert which have some researches i-e "Tim hasResearch
 Ontologies". I have another class Student (subclasses Master Phd). Khan
 is
 instance of Phd class (ultimately of Student class also). Phd student can
 also have some researches as Expert class and have type both : Student
 and
 Expert in Protege.

 I want instances which are both in Student and Expert i-e Khan in this
 case.

 If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
 std:StudentExpert (a new class in the ontology).

 my query is : select * where { ?x rdf:type std:StudentExpert}

 On Wed, Jul 27, 2016 at 1:20 AM, javed khan 
 wrote:

 I am sorry that is just the mistake when I copy code from my IDE to
> email.
> In the original code, its written just once.
>
> On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
> buehm...@informatik.uni-leipzig.de> wrote:
>
> I'm not an expert, but why do you have each URI twice in the rule?
>> I have rule body:I want instance x which are in both classes to assign
>> to
>>
>>> another class "StudentExpert" which have no other instances. But does
>>>
>> not
>>
>>> work.
>>> (My Owl inverse property and transitive property rule works but this
>>> generic rule does not work)
>>>
>>> String rule = "*[rule1:(?x
>>>   http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>>> 
>>> http://www.semanticweb.org/141#Student
>>> ) " +*
>>> *  "(?x
>>> http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>>> 
>>> http://www.semanticweb.org/141#Expert
>>>  )" + *
>>>
>>>   "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>>> http://www.semanticweb.org/141#StudentExpert )]";
>>>
>>> After prefixes, my query is:
>>>
>>> "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";
>>>
>>> My Reasoner and InfModel classes are:
>>>
>>> Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
>>>
>>> InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>>>
>>> Then query is executed as usual in jena.
>>>
>>>
>>>
>>>
>>> On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <
>>>
>> dave.e.reyno...@gmail.com>
>>
>>> wrote:
>>>
>>> On 25/07/16 19:33, javed khan wrote:
 I have a Student class (Phd students) and Teacher class, having
 instances.
>>> There are some students which are also Teacher (teaching to junior
> classes).
> ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
> This will give us Students and teachers instances.
>
> I want Jena generic rule(Forward chaining) which filters those who
> are
> both
> Teachers and Students. Is there any way to do so?
>
> Yes. You are nearly there but you want the rule body to be more
 like:

 (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...

 the rule consequent could assert a new type or some other property to
 indicate that ?x is in both classes.

 Dave


 --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: 

Re: Setting error handler for WriterGraph/DatasetRIOT

2016-07-27 Thread Martynas Jusevičius
Our use case is round-tripping, so after I solved reading I moved on
to writing (and started a new thread).

What I probably haven't made clear is that there is no intermediate
data structure holding the form data. It is being read directly into a
Model just like any other RDF format, using
application/x-www-form-urlencoded media type and RDF/POST encoding:
http://www.lsrn.org/semweb/rdfpost.html

Could you give an example of how you see ParserProfile being used here?

On Wed, Jul 27, 2016 at 9:49 AM, Andy Seaborne  wrote:
> On 26/07/16 22:06, Martynas Jusevičius wrote:
>>
>> OK. But how do you handle invalid URI input without turning the checking
>> off?
>
>
> That's what ParserProfile is for.  It provides the policy for string from
> the token in parsing to IRI.
>
>> And without reading and then writing the Model? Where the user
>> provides URIs manually, e.g. as a form input for SPARQL endpoint URI.
>
>
> Until now, this has been about reading now writing RDF.
>
> You could use a ParserProfile for the form input or at least whatever code
> is used for makeIRI.
>
> Andy
>
>
>>
>> On Tue, 26 Jul 2016 at 20:27, Andy Seaborne  wrote:
>>
>>> On 26/07/16 16:14, Martynas Jusevičius wrote:

 But the assumption obviously doesn't hold? Illegal Models exist
 because they can be parsed.
>>>
>>>
>>> No - because someone turned the checking off or created them them with
>>> code, not a parser.
>>>
 Wouldn't it make sense for the Writers check URIs just like the
 Readers do? URI validity does not depend on syntax, does it?
>>>
>>>
>>> Checking URIs is expensive. Sometimes it matters (NTriples, NQuads).
>>>
>>> To check them, process the model first which is something possible for
>>> writers and not for readers.
>>>
>>> The rules for different syntaxes are different anyway - RDF/XMl has
>>> special rules for properties.
>>>
>>>  > What do you mean with "keep the original user input"?
>>> You said:
>>> [[
>>> If the user provided invalid
>>> URI values, they need to be presented back to the user with an error
>>> message, giving him/her a chance to correct the errors.
>>> ]]
>>>
>>> Andy
>>>

 On Tue, Jul 26, 2016 at 11:32 AM, Andy Seaborne  wrote:
>
> On 26/07/16 10:23, Martynas Jusevičius wrote:
>>
>>
>> Andy,
>>
>> "allowBadURIs" was my next move, I will try that later today and
>> report
>> back.
>>
>> Any reason why this cannot be exposed uniformly on the WriterRIOT
>> level? Like it is on ReaderRIOT.
>
>
>
> RDF/XML is the only case that checks IIRC.
>
> Writers output what they can.  They assume the model is legal RDF and
> do
> their best.  There is a myriad of "illegal RDF" cases and what they can
>>>
>>> and
>
> can't write depends on the syntax.
>
> If you want to round trip user input - why not keep the original user
>>>
>>> input?
>
>
> Andy
>
>
>>
>> On Tue, Jul 26, 2016 at 11:15 AM, Andy Seaborne 
>>>
>>> wrote:
>>>
>>>
>>> Turtle-class syntaxes print bad URIs.
>>>
>>> For RDF/XML, does setting "allowBadURIs" work?
>>>
>>>
>>>
>>>
>>> https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output
>>>
>>>
>>> Andy
>>>
>>>
>>> On 26/07/16 09:34, Martynas Jusevičius wrote:



 RDF/XML (plain) in this case. I would of course prefer a
 format-agnostic solution.

 On Tue, Jul 26, 2016 at 10:21 AM, Andy Seaborne 
>>>
>>> wrote:
>
>
>
> Which serialization format are you working with?
>
> Andy
>
>
> On 25/07/16 22:44, Martynas Jusevičius wrote:
>>
>>
>>
>>
>> Hey,
>>
>> I was planning to set an ErrorHandler on WriterGraphRIOT instance,
>>>
>>> but
>>
>> it turns such setter does not exist.
>>
>> My ErrorHandler allows invalid URIs to be read without throwing
>> exceptions. However model.write() throws BadURIException when
>>>
>>> writing
>>
>> them. So round-tripping such Model currently does not work. How do
>>>
>>> I
>>
>> handler writer errors?
>>
>> I think it would make sense to reuse the error handler between
>> RIOT
>> readers and writers.
>> For example, if it is set to strict, both throw exceptions on
>>>
>>> invalid
>>
>> URIs.
>> If it is set to lax, invalid URIs are allowed during both during
>> parsing and writing.
>> That would make round-tripping easy.
>>
>> Martynas
>> atomgraph.com
>>
>
>>>
>
>>>
>>>
>>
>


Re: Jena generic rules

2016-07-27 Thread Dave Reynolds

On 27/07/16 09:54, javed khan wrote:

Sorry but still not working.

When I query instances of Expert, it shows "Tim" which is fine. When I
query instance of Student, it shows "Khan", which is also fine.
Even when I query both in one, it shows "Khan" which is also ok because
Khan is also Expert and Student, but when I try to assign it(Khan) to
another class, it does not work.


That's too imprecise to comment on.

If you can show exactly your data and your rules then we might be able 
to spot the problem.



I am afraid if Jena generic rules does not work on classes and only it
supports properties like transitive property and inverse property.


Generic rules just work in terms of triples. They can be used on 
instances or classes equally well. You just need to be clear on what you 
rules need to do and write the patterns accordingly.


Dave



On Wed, Jul 27, 2016 at 1:39 AM, javed khan  wrote:


  

are wrong. Either use the correct URI:



or use the prefix form:

rdf:type


I am sorry due to too many threads, I did not read this reply.

Thanks Dave, let me try.

On Wed, Jul 27, 2016 at 1:35 AM, Dave Reynolds 
wrote:


See my earlier reply, you had an error in the URLs in your rules.

Dave


On 27/07/16 09:33, javed khan wrote:


If my email (code) is not understandable, I am just explaining in plain
text.

I have class Expert which have some researches i-e "Tim hasResearch
Ontologies". I have another class Student (subclasses Master Phd). Khan
is
instance of Phd class (ultimately of Student class also). Phd student can
also have some researches as Expert class and have type both : Student
and
Expert in Protege.

I want instances which are both in Student and Expert i-e Khan in this
case.

If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
std:StudentExpert (a new class in the ontology).

my query is : select * where { ?x rdf:type std:StudentExpert}

On Wed, Jul 27, 2016 at 1:20 AM, javed khan 
wrote:

I am sorry that is just the mistake when I copy code from my IDE to

email.
In the original code, its written just once.

On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

I'm not an expert, but why do you have each URI twice in the rule?


I have rule body:I want instance x which are in both classes to assign



to


another class "StudentExpert" which have no other instances. But does


not


work.
(My Owl inverse property and transitive property rule works but this
generic rule does not work)

String rule = "*[rule1:(?x
   http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Student
) " +*
*  "(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Expert
 )" + *

   "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
http://www.semanticweb.org/141#StudentExpert )]";

After prefixes, my query is:

"Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";

My Reasoner and InfModel classes are:

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

InfModel inf = ModelFactory.createInfModel(reasoner2, model);

Then query is executed as usual in jena.




On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <


dave.e.reyno...@gmail.com>


wrote:

On 25/07/16 19:33, javed khan wrote:


I have a Student class (Phd students) and Teacher class, having



instances.



There are some students which are also Teacher (teaching to junior

classes).
?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
This will give us Students and teachers instances.

I want Jena generic rule(Forward chaining) which filters those who
are
both
Teachers and Students. Is there any way to do so?

Yes. You are nearly there but you want the rule body to be more

like:

(?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...

the rule consequent could assert a new type or some other property to
indicate that ?x is in both classes.

Dave


--

Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center













Re: Jena generic rules

2016-07-27 Thread javed khan
Sorry but still not working.

When I query instances of Expert, it shows "Tim" which is fine. When I
query instance of Student, it shows "Khan", which is also fine.
Even when I query both in one, it shows "Khan" which is also ok because
Khan is also Expert and Student, but when I try to assign it(Khan) to
another class, it does not work.

I am afraid if Jena generic rules does not work on classes and only it
supports properties like transitive property and inverse property.

On Wed, Jul 27, 2016 at 1:39 AM, javed khan  wrote:

>  
>
> are wrong. Either use the correct URI:
>
>
>
> or use the prefix form:
>
>rdf:type
>
>
> I am sorry due to too many threads, I did not read this reply.
>
> Thanks Dave, let me try.
>
> On Wed, Jul 27, 2016 at 1:35 AM, Dave Reynolds 
> wrote:
>
>> See my earlier reply, you had an error in the URLs in your rules.
>>
>> Dave
>>
>>
>> On 27/07/16 09:33, javed khan wrote:
>>
>>> If my email (code) is not understandable, I am just explaining in plain
>>> text.
>>>
>>> I have class Expert which have some researches i-e "Tim hasResearch
>>> Ontologies". I have another class Student (subclasses Master Phd). Khan
>>> is
>>> instance of Phd class (ultimately of Student class also). Phd student can
>>> also have some researches as Expert class and have type both : Student
>>> and
>>> Expert in Protege.
>>>
>>> I want instances which are both in Student and Expert i-e Khan in this
>>> case.
>>>
>>> If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
>>> std:StudentExpert (a new class in the ontology).
>>>
>>> my query is : select * where { ?x rdf:type std:StudentExpert}
>>>
>>> On Wed, Jul 27, 2016 at 1:20 AM, javed khan 
>>> wrote:
>>>
>>> I am sorry that is just the mistake when I copy code from my IDE to
 email.
 In the original code, its written just once.

 On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
 buehm...@informatik.uni-leipzig.de> wrote:

 I'm not an expert, but why do you have each URI twice in the rule?
>
> I have rule body:I want instance x which are in both classes to assign
>>
> to
>
>> another class "StudentExpert" which have no other instances. But does
>>
> not
>
>> work.
>> (My Owl inverse property and transitive property rule works but this
>> generic rule does not work)
>>
>> String rule = "*[rule1:(?x
>>   http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>> 
>> http://www.semanticweb.org/141#Student
>> ) " +*
>> *  "(?x
>> http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>> 
>> http://www.semanticweb.org/141#Expert
>>  )" + *
>>
>>   "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>> http://www.semanticweb.org/141#StudentExpert )]";
>>
>> After prefixes, my query is:
>>
>> "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";
>>
>> My Reasoner and InfModel classes are:
>>
>> Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
>>
>> InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>>
>> Then query is executed as usual in jena.
>>
>>
>>
>>
>> On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <
>>
> dave.e.reyno...@gmail.com>
>
>> wrote:
>>
>> On 25/07/16 19:33, javed khan wrote:
>>>
>>> I have a Student class (Phd students) and Teacher class, having

>>> instances.
>
>> There are some students which are also Teacher (teaching to junior
 classes).
 ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
 This will give us Students and teachers instances.

 I want Jena generic rule(Forward chaining) which filters those who
 are
 both
 Teachers and Students. Is there any way to do so?

 Yes. You are nearly there but you want the rule body to be more
>>> like:
>>>
>>> (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...
>>>
>>> the rule consequent could assert a new type or some other property to
>>> indicate that ?x is in both classes.
>>>
>>> Dave
>>>
>>>
>>> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
>

>>>
>


Re: Jena generic rules

2016-07-27 Thread javed khan
 

are wrong. Either use the correct URI:

   

or use the prefix form:

   rdf:type


I am sorry due to too many threads, I did not read this reply.

Thanks Dave, let me try.

On Wed, Jul 27, 2016 at 1:35 AM, Dave Reynolds 
wrote:

> See my earlier reply, you had an error in the URLs in your rules.
>
> Dave
>
>
> On 27/07/16 09:33, javed khan wrote:
>
>> If my email (code) is not understandable, I am just explaining in plain
>> text.
>>
>> I have class Expert which have some researches i-e "Tim hasResearch
>> Ontologies". I have another class Student (subclasses Master Phd). Khan is
>> instance of Phd class (ultimately of Student class also). Phd student can
>> also have some researches as Expert class and have type both : Student and
>> Expert in Protege.
>>
>> I want instances which are both in Student and Expert i-e Khan in this
>> case.
>>
>> If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
>> std:StudentExpert (a new class in the ontology).
>>
>> my query is : select * where { ?x rdf:type std:StudentExpert}
>>
>> On Wed, Jul 27, 2016 at 1:20 AM, javed khan 
>> wrote:
>>
>> I am sorry that is just the mistake when I copy code from my IDE to email.
>>> In the original code, its written just once.
>>>
>>> On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
>>> buehm...@informatik.uni-leipzig.de> wrote:
>>>
>>> I'm not an expert, but why do you have each URI twice in the rule?

 I have rule body:I want instance x which are in both classes to assign
>
 to

> another class "StudentExpert" which have no other instances. But does
>
 not

> work.
> (My Owl inverse property and transitive property rule works but this
> generic rule does not work)
>
> String rule = "*[rule1:(?x
>   http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> 
> http://www.semanticweb.org/141#Student
> ) " +*
> *  "(?x
> http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> 
> http://www.semanticweb.org/141#Expert
>  )" + *
>
>   "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> http://www.semanticweb.org/141#StudentExpert )]";
>
> After prefixes, my query is:
>
> "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";
>
> My Reasoner and InfModel classes are:
>
> Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
>
> InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>
> Then query is executed as usual in jena.
>
>
>
>
> On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <
>
 dave.e.reyno...@gmail.com>

> wrote:
>
> On 25/07/16 19:33, javed khan wrote:
>>
>> I have a Student class (Phd students) and Teacher class, having
>>>
>> instances.

> There are some students which are also Teacher (teaching to junior
>>> classes).
>>> ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
>>> This will give us Students and teachers instances.
>>>
>>> I want Jena generic rule(Forward chaining) which filters those who
>>> are
>>> both
>>> Teachers and Students. Is there any way to do so?
>>>
>>> Yes. You are nearly there but you want the rule body to be more like:
>>
>> (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...
>>
>> the rule consequent could assert a new type or some other property to
>> indicate that ?x is in both classes.
>>
>> Dave
>>
>>
>> --
 Lorenz Bühmann
 AKSW group, University of Leipzig
 Group: http://aksw.org - semantic web research center



>>>
>>


Re: Jena generic rules

2016-07-27 Thread Dave Reynolds

See my earlier reply, you had an error in the URLs in your rules.

Dave

On 27/07/16 09:33, javed khan wrote:

If my email (code) is not understandable, I am just explaining in plain
text.

I have class Expert which have some researches i-e "Tim hasResearch
Ontologies". I have another class Student (subclasses Master Phd). Khan is
instance of Phd class (ultimately of Student class also). Phd student can
also have some researches as Expert class and have type both : Student and
Expert in Protege.

I want instances which are both in Student and Expert i-e Khan in this case.

If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
std:StudentExpert (a new class in the ontology).

my query is : select * where { ?x rdf:type std:StudentExpert}

On Wed, Jul 27, 2016 at 1:20 AM, javed khan  wrote:


I am sorry that is just the mistake when I copy code from my IDE to email.
In the original code, its written just once.

On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:


I'm not an expert, but why do you have each URI twice in the rule?


I have rule body:I want instance x which are in both classes to assign

to

another class "StudentExpert" which have no other instances. But does

not

work.
(My Owl inverse property and transitive property rule works but this
generic rule does not work)

String rule = "*[rule1:(?x
  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Student
) " +*
*  "(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Expert
 )" + *

  "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
http://www.semanticweb.org/141#StudentExpert )]";

After prefixes, my query is:

"Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";

My Reasoner and InfModel classes are:

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

InfModel inf = ModelFactory.createInfModel(reasoner2, model);

Then query is executed as usual in jena.




On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <

dave.e.reyno...@gmail.com>

wrote:


On 25/07/16 19:33, javed khan wrote:


I have a Student class (Phd students) and Teacher class, having

instances.

There are some students which are also Teacher (teaching to junior
classes).
?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
This will give us Students and teachers instances.

I want Jena generic rule(Forward chaining) which filters those who are
both
Teachers and Students. Is there any way to do so?


Yes. You are nearly there but you want the rule body to be more like:

(?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...

the rule consequent could assert a new type or some other property to
indicate that ?x is in both classes.

Dave



--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center








Re: Jena generic rules

2016-07-27 Thread javed khan
If my email (code) is not understandable, I am just explaining in plain
text.

I have class Expert which have some researches i-e "Tim hasResearch
Ontologies". I have another class Student (subclasses Master Phd). Khan is
instance of Phd class (ultimately of Student class also). Phd student can
also have some researches as Expert class and have type both : Student and
Expert in Protege.

I want instances which are both in Student and Expert i-e Khan in this case.

If ?x rdf:type std:Expert and ?x rdf:type std:Student -> ?x rdf:type
std:StudentExpert (a new class in the ontology).

my query is : select * where { ?x rdf:type std:StudentExpert}

On Wed, Jul 27, 2016 at 1:20 AM, javed khan  wrote:

> I am sorry that is just the mistake when I copy code from my IDE to email.
> In the original code, its written just once.
>
> On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
> buehm...@informatik.uni-leipzig.de> wrote:
>
>> I'm not an expert, but why do you have each URI twice in the rule?
>>
>> > I have rule body:I want instance x which are in both classes to assign
>> to
>> > another class "StudentExpert" which have no other instances. But does
>> not
>> > work.
>> > (My Owl inverse property and transitive property rule works but this
>> > generic rule does not work)
>> >
>> > String rule = "*[rule1:(?x
>> >  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>> > 
>> > http://www.semanticweb.org/141#Student
>> > ) " +*
>> > *  "(?x
>> > http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>> > 
>> > http://www.semanticweb.org/141#Expert
>> >  )" + *
>> >
>> >  "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
>> > http://www.semanticweb.org/141#StudentExpert )]";
>> >
>> > After prefixes, my query is:
>> >
>> > "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";
>> >
>> > My Reasoner and InfModel classes are:
>> >
>> > Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
>> >
>> > InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>> >
>> > Then query is executed as usual in jena.
>> >
>> >
>> >
>> >
>> > On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <
>> dave.e.reyno...@gmail.com>
>> > wrote:
>> >
>> >> On 25/07/16 19:33, javed khan wrote:
>> >>
>> >>> I have a Student class (Phd students) and Teacher class, having
>> instances.
>> >>> There are some students which are also Teacher (teaching to junior
>> >>> classes).
>> >>> ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
>> >>> This will give us Students and teachers instances.
>> >>>
>> >>> I want Jena generic rule(Forward chaining) which filters those who are
>> >>> both
>> >>> Teachers and Students. Is there any way to do so?
>> >>>
>> >> Yes. You are nearly there but you want the rule body to be more like:
>> >>
>> >> (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...
>> >>
>> >> the rule consequent could assert a new type or some other property to
>> >> indicate that ?x is in both classes.
>> >>
>> >> Dave
>> >>
>> >>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
>


Unequal SPARQL algebras

2016-07-27 Thread Jindřich Mynarz
Hi,

I'm wondering why Jena thinks the optimized SPARQL algebras of the
following queries are different:

# Query 1
PREFIX skos: 

SELECT *
WHERE {
  ?concept skos:broader [ skos:prefLabel ?broaderLabel ] .
}

# Query 1 algebra
(bgp
  (triple ?concept  ??0)
  (triple ??0  ?broaderLabel)
)

# Query 2
PREFIX skos: 

SELECT *
WHERE {
  ?concept skos:broader/skos:prefLabel ?broaderLabel .
}

# Query 2 algebra
(bgp
  (triple ?concept  ??P4)
  (triple ??P4 
?broaderLabel)
)

When I compare if the query 1 algebra is equal to the query 2 algebra,
false is returned. However, the only difference I can spot between the
algebras is in the names of the non-distinguished variables ??0 and ??P4.
Why are the query algebras treated as different?

- Jindřich

-- 
Jindřich Mynarz
http://mynarz.net/#jindrich


Re: Jena generic rules

2016-07-27 Thread javed khan
I am sorry that is just the mistake when I copy code from my IDE to email.
In the original code, its written just once.

On Wed, Jul 27, 2016 at 1:11 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

> I'm not an expert, but why do you have each URI twice in the rule?
>
> > I have rule body:I want instance x which are in both classes to assign to
> > another class "StudentExpert" which have no other instances. But does not
> > work.
> > (My Owl inverse property and transitive property rule works but this
> > generic rule does not work)
> >
> > String rule = "*[rule1:(?x
> >  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> > 
> > http://www.semanticweb.org/141#Student
> > ) " +*
> > *  "(?x
> > http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> > 
> > http://www.semanticweb.org/141#Expert
> >  )" + *
> >
> >  "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> > http://www.semanticweb.org/141#StudentExpert )]";
> >
> > After prefixes, my query is:
> >
> > "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";
> >
> > My Reasoner and InfModel classes are:
> >
> > Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
> >
> > InfModel inf = ModelFactory.createInfModel(reasoner2, model);
> >
> > Then query is executed as usual in jena.
> >
> >
> >
> >
> > On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds <
> dave.e.reyno...@gmail.com>
> > wrote:
> >
> >> On 25/07/16 19:33, javed khan wrote:
> >>
> >>> I have a Student class (Phd students) and Teacher class, having
> instances.
> >>> There are some students which are also Teacher (teaching to junior
> >>> classes).
> >>> ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
> >>> This will give us Students and teachers instances.
> >>>
> >>> I want Jena generic rule(Forward chaining) which filters those who are
> >>> both
> >>> Teachers and Students. Is there any way to do so?
> >>>
> >> Yes. You are nearly there but you want the rule body to be more like:
> >>
> >> (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...
> >>
> >> the rule consequent could assert a new type or some other property to
> >> indicate that ?x is in both classes.
> >>
> >> Dave
> >>
> >>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>


Re: Jena generic rules

2016-07-27 Thread Andy Seaborne

On 27/07/16 09:01, javed khan wrote:

This is what your email appear like to other people:

http://mail-archives.apache.org/mod_mbox/jena-users/201607.mbox/%3CCAJhui%2Bu9YjFjVQ%2BJ43O5zE2D4WxAvRzwpVKHXLbzHHhjum5h1w%40mail.gmail.com%3E

I suspect that your mailer has attempted to covert HTML (in which you 
used bold and links) to plain text.


Andy


I have rule body:I want instance x which are in both classes to assign to
another class "StudentExpert" which have no other instances. But does not
work.
(My Owl inverse property and transitive property rule works but this
generic rule does not work)

String rule = "*[rule1:(?x
 http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Student
) " +*
*  "(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Expert
 )" + *

 "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
http://www.semanticweb.org/141#StudentExpert )]";

After prefixes, my query is:

"Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";

My Reasoner and InfModel classes are:

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

InfModel inf = ModelFactory.createInfModel(reasoner2, model);

Then query is executed as usual in jena.




On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds 
wrote:


On 25/07/16 19:33, javed khan wrote:


I have a Student class (Phd students) and Teacher class, having instances.
There are some students which are also Teacher (teaching to junior
classes).
?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
This will give us Students and teachers instances.

I want Jena generic rule(Forward chaining) which filters those who are
both
Teachers and Students. Is there any way to do so?



Yes. You are nearly there but you want the rule body to be more like:

(?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...

the rule consequent could assert a new type or some other property to
indicate that ?x is in both classes.

Dave








Re: Jena generic rules

2016-07-27 Thread Dave Reynolds


On 27/07/16 09:01, javed khan wrote:

I have rule body:I want instance x which are in both classes to assign to
another class "StudentExpert" which have no other instances. But does not
work.
(My Owl inverse property and transitive property rule works but this
generic rule does not work)

String rule = "*[rule1:(?x
  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Student
) " +*
*  "(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Expert
 )" + *

  "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
http://www.semanticweb.org/141#StudentExpert )]";


As Lorenz says, your postings come through with all URLs duplicated so 
it's hard to be sure what's actually in your data. However, things like:


   

are wrong. Either use the correct URI:

   

or use the prefix form:

   rdf:type

Dave


Re: Jena generic rules

2016-07-27 Thread Dave Reynolds

On 27/07/16 09:11, Lorenz B. wrote:

I'm not an expert, but why do you have each URI twice in the rule?


I suspect it's an artefact of the mailer used not of the actual data, 
otherwise it wouldn't parse.


Dave


I have rule body:I want instance x which are in both classes to assign to
another class "StudentExpert" which have no other instances. But does not
work.
(My Owl inverse property and transitive property rule works but this
generic rule does not work)

String rule = "*[rule1:(?x
  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Student
) " +*
*  "(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Expert
 )" + *

  "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
http://www.semanticweb.org/141#StudentExpert )]";

After prefixes, my query is:

"Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";

My Reasoner and InfModel classes are:

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

InfModel inf = ModelFactory.createInfModel(reasoner2, model);

Then query is executed as usual in jena.




On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds 
wrote:


On 25/07/16 19:33, javed khan wrote:


I have a Student class (Phd students) and Teacher class, having instances.
There are some students which are also Teacher (teaching to junior
classes).
?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
This will give us Students and teachers instances.

I want Jena generic rule(Forward chaining) which filters those who are
both
Teachers and Students. Is there any way to do so?


Yes. You are nearly there but you want the rule body to be more like:

(?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...

the rule consequent could assert a new type or some other property to
indicate that ?x is in both classes.

Dave




Re: Jena generic rules

2016-07-27 Thread Lorenz B.
I'm not an expert, but why do you have each URI twice in the rule?

> I have rule body:I want instance x which are in both classes to assign to
> another class "StudentExpert" which have no other instances. But does not
> work.
> (My Owl inverse property and transitive property rule works but this
> generic rule does not work)
>
> String rule = "*[rule1:(?x
>  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> 
> http://www.semanticweb.org/141#Student
> ) " +*
> *  "(?x
> http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> 
> http://www.semanticweb.org/141#Expert
>  )" + *
>
>  "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
> http://www.semanticweb.org/141#StudentExpert )]";
>
> After prefixes, my query is:
>
> "Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";
>
> My Reasoner and InfModel classes are:
>
> Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
>
> InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>
> Then query is executed as usual in jena.
>
>
>
>
> On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds 
> wrote:
>
>> On 25/07/16 19:33, javed khan wrote:
>>
>>> I have a Student class (Phd students) and Teacher class, having instances.
>>> There are some students which are also Teacher (teaching to junior
>>> classes).
>>> ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
>>> This will give us Students and teachers instances.
>>>
>>> I want Jena generic rule(Forward chaining) which filters those who are
>>> both
>>> Teachers and Students. Is there any way to do so?
>>>
>> Yes. You are nearly there but you want the rule body to be more like:
>>
>> (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...
>>
>> the rule consequent could assert a new type or some other property to
>> indicate that ?x is in both classes.
>>
>> Dave
>>
>>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center



Re: Jena generic rules

2016-07-27 Thread javed khan
I have rule body:I want instance x which are in both classes to assign to
another class "StudentExpert" which have no other instances. But does not
work.
(My Owl inverse property and transitive property rule works but this
generic rule does not work)

String rule = "*[rule1:(?x
 http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Student
) " +*
*  "(?x
http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#Expert
 )" + *

 "->(?x  http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type
http://www.semanticweb.org/141#StudentExpert )]";

After prefixes, my query is:

"Select * " + "where {  ?x  rdf:type std:StudentExpert.   }";

My Reasoner and InfModel classes are:

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

InfModel inf = ModelFactory.createInfModel(reasoner2, model);

Then query is executed as usual in jena.




On Mon, Jul 25, 2016 at 2:38 PM, Dave Reynolds 
wrote:

> On 25/07/16 19:33, javed khan wrote:
>
>> I have a Student class (Phd students) and Teacher class, having instances.
>> There are some students which are also Teacher (teaching to junior
>> classes).
>> ?x rdf:type ont:Student   ?y rdf:type ont:Teacher -->  ?
>> This will give us Students and teachers instances.
>>
>> I want Jena generic rule(Forward chaining) which filters those who are
>> both
>> Teachers and Students. Is there any way to do so?
>>
>
> Yes. You are nearly there but you want the rule body to be more like:
>
> (?x rdf:type ont:Student)  (?x rdf:type ont:Teacher) ->  ...
>
> the rule consequent could assert a new type or some other property to
> indicate that ?x is in both classes.
>
> Dave
>
>


Re: Setting error handler for WriterGraph/DatasetRIOT

2016-07-27 Thread Andy Seaborne

On 26/07/16 22:06, Martynas Jusevičius wrote:

OK. But how do you handle invalid URI input without turning the checking
off?


That's what ParserProfile is for.  It provides the policy for string 
from the token in parsing to IRI.



And without reading and then writing the Model? Where the user
provides URIs manually, e.g. as a form input for SPARQL endpoint URI.


Until now, this has been about reading now writing RDF.

You could use a ParserProfile for the form input or at least whatever 
code is used for makeIRI.


Andy



On Tue, 26 Jul 2016 at 20:27, Andy Seaborne  wrote:


On 26/07/16 16:14, Martynas Jusevičius wrote:

But the assumption obviously doesn't hold? Illegal Models exist
because they can be parsed.


No - because someone turned the checking off or created them them with
code, not a parser.


Wouldn't it make sense for the Writers check URIs just like the
Readers do? URI validity does not depend on syntax, does it?


Checking URIs is expensive. Sometimes it matters (NTriples, NQuads).

To check them, process the model first which is something possible for
writers and not for readers.

The rules for different syntaxes are different anyway - RDF/XMl has
special rules for properties.

 > What do you mean with "keep the original user input"?
You said:
[[
If the user provided invalid
URI values, they need to be presented back to the user with an error
message, giving him/her a chance to correct the errors.
]]

Andy



On Tue, Jul 26, 2016 at 11:32 AM, Andy Seaborne  wrote:

On 26/07/16 10:23, Martynas Jusevičius wrote:


Andy,

"allowBadURIs" was my next move, I will try that later today and report
back.

Any reason why this cannot be exposed uniformly on the WriterRIOT
level? Like it is on ReaderRIOT.



RDF/XML is the only case that checks IIRC.

Writers output what they can.  They assume the model is legal RDF and do
their best.  There is a myriad of "illegal RDF" cases and what they can

and

can't write depends on the syntax.

If you want to round trip user input - why not keep the original user

input?


Andy




On Tue, Jul 26, 2016 at 11:15 AM, Andy Seaborne 

wrote:


Turtle-class syntaxes print bad URIs.

For RDF/XML, does setting "allowBadURIs" work?




https://jena.apache.org/documentation/io/rdfxml_howto.html#advanced-rdfxml-output


Andy


On 26/07/16 09:34, Martynas Jusevičius wrote:



RDF/XML (plain) in this case. I would of course prefer a
format-agnostic solution.

On Tue, Jul 26, 2016 at 10:21 AM, Andy Seaborne 

wrote:



Which serialization format are you working with?

Andy


On 25/07/16 22:44, Martynas Jusevičius wrote:




Hey,

I was planning to set an ErrorHandler on WriterGraphRIOT instance,

but

it turns such setter does not exist.

My ErrorHandler allows invalid URIs to be read without throwing
exceptions. However model.write() throws BadURIException when

writing

them. So round-tripping such Model currently does not work. How do

I

handler writer errors?

I think it would make sense to reuse the error handler between RIOT
readers and writers.
For example, if it is set to strict, both throw exceptions on

invalid

URIs.
If it is set to lax, invalid URIs are allowed during both during
parsing and writing.
That would make round-tripping easy.

Martynas
atomgraph.com