Re: Jena rules not working

2016-09-21 Thread Andy Seaborne

Classes are identified by URIs, not by strings.

On 21/09/16 11:46, javed khan wrote:

Hello Andy, shouldn't there be the class name to which we assign new
individuals.?
inf.listResourcesWithProperty(RDF.type,
"GoodStudent")

Dave run this code and it works for him, but I do not know why, it does not
work for me.

On Wed, Sep 21, 2016 at 2:18 AM, Andy Seaborne  wrote:


The rules have some syntax problems:

"( ?x  http://www.semanticweb.org#GPA  ?score +   )"

as mentioned earlier in the thread then

"greaterThan(?score, userscore) "

but userscore is a java variable.

Also

inf.listResourcesWithProperty(RDF.type,
"GoodStudent")

uses a string not a URI so if not going to find anything.

Andy


On 21/09/16 09:21, Lorenz B. wrote:


Are you sure that this code compiles?

Property prop= model.getProperty(ns,"GPA");




ns is a String in your code, the method expects a Resource object is
first argument. You totally use the wrong method here, as it returns a
Statement.

Model::createProperty(String nameSpace, String localName)

would be the method to call, or even better as you use an OntModel

OntModel::getDatatypeProperty( String uri )







Re: Jena rules not working

2016-09-21 Thread javed khan
Hello Andy, shouldn't there be the class name to which we assign new
individuals.?
inf.listResourcesWithProperty(RDF.type,
"GoodStudent")

Dave run this code and it works for him, but I do not know why, it does not
work for me.

On Wed, Sep 21, 2016 at 2:18 AM, Andy Seaborne  wrote:

> The rules have some syntax problems:
>
> "( ?x  http://www.semanticweb.org#GPA  ?score +   )"
>
> as mentioned earlier in the thread then
>
> "greaterThan(?score, userscore) "
>
> but userscore is a java variable.
>
> Also
>
> inf.listResourcesWithProperty(RDF.type,
> "GoodStudent")
>
> uses a string not a URI so if not going to find anything.
>
> Andy
>
>
> On 21/09/16 09:21, Lorenz B. wrote:
>
>> Are you sure that this code compiles?
>>
>> Property prop= model.getProperty(ns,"GPA");
>>>
>>
>> ns is a String in your code, the method expects a Resource object is
>> first argument. You totally use the wrong method here, as it returns a
>> Statement.
>>
>> Model::createProperty(String nameSpace, String localName)
>>
>> would be the method to call, or even better as you use an OntModel
>>
>> OntModel::getDatatypeProperty( String uri )
>>
>>
>>


Re: Jena rules not working

2016-09-21 Thread javed khan
Hello Andy, I used this:

?x URI#GPA ?score + "greaterThan(?score, 3)

?score will return the scores/GPA of students and if it is greater than 3,
it will assign user to GoodStudent class.

On Wed, Sep 21, 2016 at 2:18 AM, Andy Seaborne  wrote:

> The rules have some syntax problems:
>
> "( ?x  http://www.semanticweb.org#GPA  ?score +   )"
>
> as mentioned earlier in the thread then
>
> "greaterThan(?score, userscore) "
>
> but userscore is a java variable.
>
> Also
>
> inf.listResourcesWithProperty(RDF.type,
> "GoodStudent")
>
> uses a string not a URI so if not going to find anything.
>
> Andy
>
>
> On 21/09/16 09:21, Lorenz B. wrote:
>
>> Are you sure that this code compiles?
>>
>> Property prop= model.getProperty(ns,"GPA");
>>>
>>
>> ns is a String in your code, the method expects a Resource object is
>> first argument. You totally use the wrong method here, as it returns a
>> Statement.
>>
>> Model::createProperty(String nameSpace, String localName)
>>
>> would be the method to call, or even better as you use an OntModel
>>
>> OntModel::getDatatypeProperty( String uri )
>>
>>
>>


Re: Jena rules not working

2016-09-21 Thread Lorenz B.


> model.getProperty(ns,"GPA"); I think this works for me and store the data
> property GPA in the file.
>
> Actually I do not need this: Model::createProperty(String nameSpace, String
> localName)
> as I have already created the property in my owl file and just needs
> getProperty() method.
>
> If I use this : OntModel::getDatatypeProperty( String uri ) which property
> (data property) will be returned ? Because the argument only contains the
> namespace and not the actual property.
The argument is the full URI, this is the same as you do to get the OntClass
>
> I tried this but it gives me error:
>
> DataProperty property=ontModel::getDatatypeProperty( String uri, "Score )
This is not Java syntax...

OntModel::getDatatypeProperty( String ur)

means to use the method on the an OntModel object, but indeed with a
dot, not two colons.

And as I said, it has only one argument.

As Andy Seaborne mentioned, your rule is still with illegal syntax,
that's what Dave also mentioned at least twice in previous answers...
>
> On Wed, Sep 21, 2016 at 1:21 AM, Lorenz B. <
> buehm...@informatik.uni-leipzig.de> wrote:
>
>> Are you sure that this code compiles?
>>
>>> Property prop= model.getProperty(ns,"GPA");
>> ns is a String in your code, the method expects a Resource object is
>> first argument. You totally use the wrong method here, as it returns a
>> Statement.
>>
>> Model::createProperty(String nameSpace, String localName)
>>
>> would be the method to call, or even better as you use an OntModel
>>
>> OntModel::getDatatypeProperty( String uri )
>>
>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center



Re: Jena rules not working

2016-09-21 Thread Andy Seaborne

The rules have some syntax problems:

"( ?x  http://www.semanticweb.org#GPA  ?score +   )"

as mentioned earlier in the thread then

"greaterThan(?score, userscore) "

but userscore is a java variable.

Also

inf.listResourcesWithProperty(RDF.type,
"GoodStudent")

uses a string not a URI so if not going to find anything.

Andy

On 21/09/16 09:21, Lorenz B. wrote:

Are you sure that this code compiles?


Property prop= model.getProperty(ns,"GPA");


ns is a String in your code, the method expects a Resource object is
first argument. You totally use the wrong method here, as it returns a
Statement.

Model::createProperty(String nameSpace, String localName)

would be the method to call, or even better as you use an OntModel

OntModel::getDatatypeProperty( String uri )




Re: Jena rules not working

2016-09-21 Thread javed khan
model.getProperty(ns,"GPA"); I think this works for me and store the data
property GPA in the file.

Actually I do not need this: Model::createProperty(String nameSpace, String
localName)
as I have already created the property in my owl file and just needs
getProperty() method.

If I use this : OntModel::getDatatypeProperty( String uri ) which property
(data property) will be returned ? Because the argument only contains the
namespace and not the actual property.

I tried this but it gives me error:

DataProperty property=ontModel::getDatatypeProperty( String uri, "Score )

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

> Are you sure that this code compiles?
>
> > Property prop= model.getProperty(ns,"GPA");
>
> ns is a String in your code, the method expects a Resource object is
> first argument. You totally use the wrong method here, as it returns a
> Statement.
>
> Model::createProperty(String nameSpace, String localName)
>
> would be the method to call, or even better as you use an OntModel
>
> OntModel::getDatatypeProperty( String uri )
>
>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>


Re: Jena rules not working

2016-09-21 Thread Lorenz B.
Are you sure that this code compiles?

> Property prop= model.getProperty(ns,"GPA");

ns is a String in your code, the method expects a Resource object is
first argument. You totally use the wrong method here, as it returns a
Statement.

Model::createProperty(String nameSpace, String localName) 

would be the method to call, or even better as you use an OntModel 

OntModel::getDatatypeProperty( String uri )


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


Re: Jena rules not working

2016-09-20 Thread javed khan
public class Student {



//here call from another class where name is student name and score is
GPA

static void use(String name, int score)

{

int userscore=score;

OntModel model=ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);



 InputStream in =FileManager.get().open("D://std.owl");

if (in==null) {

throw new IllegalArgumentException( "File: " +  " not
found");

}   model.read(in,"");

 String ns="http://www.semanticweb.org#;;

OntClass user1 = model.getOntClass(ns + "Student");



 // OntClass good=model.getOntClass(ns+ "GoodStudent");

//name is entered by user in text field

   Individual indiv = user1.createIndividual(ns + name);

Property prop= model.getProperty(ns,"GPA");



indiv.addLiteral(prop, userscore);



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

 "( ?x  http://www.semanticweb.org#GPA  ?score +   )"   +
"greaterThan(?score, userscore) "+

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



 String queryString= "PREFIX std:
"+

 "PREFIX rdfs: "  +

  "PREFIX rdf: "+

  "SELECT  * " +

" WHERE {  ?x rdf:type std:GoodStudent}";


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

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



 for (Iterator i = inf.listResourcesWithProperty(RDF.type,
"GoodStudent"); i.hasNext();) {



System.out.println("Good student: " + i.next());



}


//saving to file


 try (FileOutputStream writer = new
FileOutputStream("D://std.owl")) {

model.write(writer, "RDF/XML");

} catch (IOException ex) {

Logger.getLogger(mystdclass.class.getName()).log(Level.SEVERE,
null, ex);

}

model.write(System.out, "N3");







}

On Tue, Sep 20, 2016 at 12:35 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

> @Javed:
>
> It would be good if you show us the WHOLE CURRENT part of the code and
> some sample data, otherwise it's useless to continue the discussion here.
>
> > On 19/09/16 17:14, javed khan wrote:
> >> Hello Dave, though I have Student class in my owl and GoodStudent as the
> >> subclass of Student but this statement gives me error and does not
> >> recognize GoodStudent.
> >>
> >>  for (Iterator i = inf.listResourcesWithProperty(RDF.type,
> >> *GoodStudent*);
> >> i.hasNext();) {
> >> System.out.println("Good student: " + i.next());
> >
> > The code sample I provided worked. I suspect you have omitted some
> > lines such as the one that assigned a value for GoodStudent.
> >
> > Dave
> >
> >>
> >> On Sun, Sep 18, 2016 at 1:36 PM, javed khan 
> >> wrote:
> >>
> >>> Thanks a lot Dave, let me try it. I hope it will help.
> >>>
> >>> Regards
> >>>
> >>> On Sun, Sep 18, 2016 at 1:28 PM, Dave Reynolds
> >>> 
> >>> wrote:
> >>>
>  On 18/09/16 21:24, javed khan wrote:
> 
> > Thanks Lorenz and Dave, I have corrected the
> > http://www.semanticweb.org#
> > Student to ?x but it does not
> > work.Actually it does not save the updated marks/GPA of student
> > and when
> > I
> > remove the Jena rules part, it then updates and save the GPA.
> > I also try the SPARQL query inside Protege Query tab but it does
> > not give
> > me any instance of the GoodStudent class.
> >
> 
>  The example I showed does work. If you write inf to file or std out
>  you
>  can see the class, if you run your sparql query it lists s1.
> 
>  Dave
> 
> 
>  On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
> > buehm...@informatik.uni-leipzig.de> wrote:
> >
> > The second condition of your rule doesn't make any sense as the
> > subject
> >> is Student and it should be ?x.
> >>
> >>
> >> On 18.09.2016 17:41, javed khan wrote:
> >>
> >>> This code does not work. I want to save student marks/GPA in the
> >>> file
> >>> and
> >>> based on GPA assign students to GoodStudent or WorstStudents sub
> >>> classes
> >>>
> >> of
> >>
> >>> Student via Jena rules.
> >>>
> >>>
> >>>
> >>>
> >>> OntModel model=ModelFactory.createOntologyModel();
> >>>
> >>>  InputStream in =FileManager.get().open("C://std.owl");
> >>> if (in==null) {
> >>> throw new IllegalArgumentException( "File: " +
> >>> " not
> >>> found");
> >>> }   

Re: Jena rules not working

2016-09-20 Thread Lorenz B.
@Javed:

It would be good if you show us the WHOLE CURRENT part of the code and
some sample data, otherwise it's useless to continue the discussion here.

> On 19/09/16 17:14, javed khan wrote:
>> Hello Dave, though I have Student class in my owl and GoodStudent as the
>> subclass of Student but this statement gives me error and does not
>> recognize GoodStudent.
>>
>>  for (Iterator i = inf.listResourcesWithProperty(RDF.type,
>> *GoodStudent*);
>> i.hasNext();) {
>> System.out.println("Good student: " + i.next());
>
> The code sample I provided worked. I suspect you have omitted some
> lines such as the one that assigned a value for GoodStudent.
>
> Dave
>
>>
>> On Sun, Sep 18, 2016 at 1:36 PM, javed khan 
>> wrote:
>>
>>> Thanks a lot Dave, let me try it. I hope it will help.
>>>
>>> Regards
>>>
>>> On Sun, Sep 18, 2016 at 1:28 PM, Dave Reynolds
>>> 
>>> wrote:
>>>
 On 18/09/16 21:24, javed khan wrote:

> Thanks Lorenz and Dave, I have corrected the
> http://www.semanticweb.org#
> Student to ?x but it does not
> work.Actually it does not save the updated marks/GPA of student
> and when
> I
> remove the Jena rules part, it then updates and save the GPA.
> I also try the SPARQL query inside Protege Query tab but it does
> not give
> me any instance of the GoodStudent class.
>

 The example I showed does work. If you write inf to file or std out
 you
 can see the class, if you run your sparql query it lists s1.

 Dave


 On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
> buehm...@informatik.uni-leipzig.de> wrote:
>
> The second condition of your rule doesn't make any sense as the
> subject
>> is Student and it should be ?x.
>>
>>
>> On 18.09.2016 17:41, javed khan wrote:
>>
>>> This code does not work. I want to save student marks/GPA in the
>>> file
>>> and
>>> based on GPA assign students to GoodStudent or WorstStudents sub
>>> classes
>>>
>> of
>>
>>> Student via Jena rules.
>>>
>>>
>>>
>>>
>>> OntModel model=ModelFactory.createOntologyModel();
>>>
>>>  InputStream in =FileManager.get().open("C://std.owl");
>>> if (in==null) {
>>> throw new IllegalArgumentException( "File: " + 
>>> " not
>>> found");
>>> }   model.read(in,"");
>>>
>>>  String ns="http://www.semanticweb.org#;;
>>>
>>> OntClass user1 = model.getOntClass(ns + "Student");
>>>
>>>Individual indiv = user1.createIndividual(ns + name);
>>> //name
>>>
>> is
>>
>>> variable
>>>
>>> Property prop= model.getProperty(ns,"GPA");
>>>
>>> indiv.addLiteral(prop, marks); //marks also variable
>>> having
>>> some value i-e 3.0
>>>
>>>
>>>
>>>  String rule="[rule1:(?x   http://www.w3.org/1999/02/22-
>>>
>> rdf-syntax-ns#type
>>
>>> http://www.semanticweb.org#Student) " +
>>>  "( http://www.semanticweb.org#Student
>>> http://www.semanticweb.org#GPA  ?marks +   )"   +
>>> "greaterThan(?marks,
>>>
>> 2) "+
>>
>>>  " ->  (?x  
>>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type
>>> http://www.semanticweb.org#GoodStudent )]";
>>>
>>>  String queryString= "PREFIX
>>> std:>>
>> org#>
>>
>>> "+
>>>  "PREFIX rdfs: "  +
>>>   "PREFIX
>>> rdf: "+
>>>   "SELECT  * " +
>>> " WHERE {  ?x rdf:type std:GoodStudent}";
>>>
>>>  Reasoner reasoner2 = new
>>> GenericRuleReasoner(Rule.parseRules(rule));
>>>   InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>>>  Query query = QueryFactory.create(queryString);
>>>   QueryExecution qe = QueryExecutionFactory.create(query,
>>> inf);
>>>  ResultSet results = qe.execSelect();
>>>  ResultSetFormatter.out(System.out, results, query);
>>>  qe.close();
>>>
>>>
>>>
>>>  try (FileOutputStream writer = new
>>> FileOutputStream("C://std.owl")) {
>>> model.write(writer, "RDF/XML");
>>> } catch (IOException ex) {
>>> Logger.getLogger(stdinfo.class
>>> .getName()).log(Level.SEVERE,
>>> null, ex);
>>> }
>>> model.write(System.out, "N3");
>>>
>>> }
>>>
>>>
>>
>>
>

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



Re: Jena rules not working

2016-09-19 Thread Dave Reynolds

On 19/09/16 17:14, javed khan wrote:

Hello Dave, though I have Student class in my owl and GoodStudent as the
subclass of Student but this statement gives me error and does not
recognize GoodStudent.

 for (Iterator i = inf.listResourcesWithProperty(RDF.type, *GoodStudent*);
i.hasNext();) {
System.out.println("Good student: " + i.next());


The code sample I provided worked. I suspect you have omitted some lines 
such as the one that assigned a value for GoodStudent.


Dave



On Sun, Sep 18, 2016 at 1:36 PM, javed khan  wrote:


Thanks a lot Dave, let me try it. I hope it will help.

Regards

On Sun, Sep 18, 2016 at 1:28 PM, Dave Reynolds 
wrote:


On 18/09/16 21:24, javed khan wrote:


Thanks Lorenz and Dave, I have corrected the
http://www.semanticweb.org#
Student to ?x but it does not
work.Actually it does not save the updated marks/GPA of student and when
I
remove the Jena rules part, it then updates and save the GPA.
I also try the SPARQL query inside Protege Query tab but it does not give
me any instance of the GoodStudent class.



The example I showed does work. If you write inf to file or std out you
can see the class, if you run your sparql query it lists s1.

Dave


On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <

buehm...@informatik.uni-leipzig.de> wrote:

The second condition of your rule doesn't make any sense as the subject

is Student and it should be ?x.


On 18.09.2016 17:41, javed khan wrote:


This code does not work. I want to save student marks/GPA in the file
and
based on GPA assign students to GoodStudent or WorstStudents sub
classes


of


Student via Jena rules.




OntModel model=ModelFactory.createOntologyModel();

 InputStream in =FileManager.get().open("C://std.owl");
if (in==null) {
throw new IllegalArgumentException( "File: " +  " not
found");
}   model.read(in,"");

 String ns="http://www.semanticweb.org#;;

OntClass user1 = model.getOntClass(ns + "Student");

   Individual indiv = user1.createIndividual(ns + name); //name


is


variable

Property prop= model.getProperty(ns,"GPA");

indiv.addLiteral(prop, marks); //marks also variable having
some value i-e 3.0



 String rule="[rule1:(?x   http://www.w3.org/1999/02/22-


rdf-syntax-ns#type


http://www.semanticweb.org#Student) " +
 "( http://www.semanticweb.org#Student
http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks,


2) "+


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

 String queryString= "PREFIX std:


"+
 "PREFIX rdfs: "  +
  "PREFIX rdf: "+
  "SELECT  * " +
" WHERE {  ?x rdf:type std:GoodStudent}";

 Reasoner reasoner2 = new
GenericRuleReasoner(Rule.parseRules(rule));
  InfModel inf = ModelFactory.createInfModel(reasoner2, model);
 Query query = QueryFactory.create(queryString);
  QueryExecution qe = QueryExecutionFactory.create(query,
inf);
 ResultSet results = qe.execSelect();
 ResultSetFormatter.out(System.out, results, query);
 qe.close();



 try (FileOutputStream writer = new
FileOutputStream("C://std.owl")) {
model.write(writer, "RDF/XML");
} catch (IOException ex) {
Logger.getLogger(stdinfo.class
.getName()).log(Level.SEVERE,
null, ex);
}
model.write(System.out, "N3");

}

















Re: Jena rules not working

2016-09-19 Thread javed khan
It does not recognize the class name but only property names.

On Mon, Sep 19, 2016 at 9:14 AM, javed khan  wrote:

> Hello Dave, though I have Student class in my owl and GoodStudent as the
> subclass of Student but this statement gives me error and does not
> recognize GoodStudent.
>
>  for (Iterator i = inf.listResourcesWithProperty(RDF.type, *GoodStudent*);
> i.hasNext();) {
> System.out.println("Good student: " + i.next());
>
> On Sun, Sep 18, 2016 at 1:36 PM, javed khan  wrote:
>
>> Thanks a lot Dave, let me try it. I hope it will help.
>>
>> Regards
>>
>> On Sun, Sep 18, 2016 at 1:28 PM, Dave Reynolds > > wrote:
>>
>>> On 18/09/16 21:24, javed khan wrote:
>>>
 Thanks Lorenz and Dave, I have corrected the
 http://www.semanticweb.org#
 Student to ?x but it does not
 work.Actually it does not save the updated marks/GPA of student and
 when I
 remove the Jena rules part, it then updates and save the GPA.
 I also try the SPARQL query inside Protege Query tab but it does not
 give
 me any instance of the GoodStudent class.

>>>
>>> The example I showed does work. If you write inf to file or std out you
>>> can see the class, if you run your sparql query it lists s1.
>>>
>>> Dave
>>>
>>>
>>> On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
 buehm...@informatik.uni-leipzig.de> wrote:

 The second condition of your rule doesn't make any sense as the subject
> is Student and it should be ?x.
>
>
> On 18.09.2016 17:41, javed khan wrote:
>
>> This code does not work. I want to save student marks/GPA in the file
>> and
>> based on GPA assign students to GoodStudent or WorstStudents sub
>> classes
>>
> of
>
>> Student via Jena rules.
>>
>>
>>
>>
>> OntModel model=ModelFactory.createOntologyModel();
>>
>>  InputStream in =FileManager.get().open("C://std.owl");
>> if (in==null) {
>> throw new IllegalArgumentException( "File: " +  " not
>> found");
>> }   model.read(in,"");
>>
>>  String ns="http://www.semanticweb.org#;;
>>
>> OntClass user1 = model.getOntClass(ns + "Student");
>>
>>Individual indiv = user1.createIndividual(ns + name);
>> //name
>>
> is
>
>> variable
>>
>> Property prop= model.getProperty(ns,"GPA");
>>
>> indiv.addLiteral(prop, marks); //marks also variable
>> having
>> some value i-e 3.0
>>
>>
>>
>>  String rule="[rule1:(?x   http://www.w3.org/1999/02/22-
>>
> rdf-syntax-ns#type
>
>> http://www.semanticweb.org#Student) " +
>>  "( http://www.semanticweb.org#Student
>> http://www.semanticweb.org#GPA  ?marks +   )"   +
>> "greaterThan(?marks,
>>
> 2) "+
>
>>  " ->  (?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
>> http://www.semanticweb.org#GoodStudent )]";
>>
>>  String queryString= "PREFIX std:>
> org#>
>
>> "+
>>  "PREFIX rdfs: "  +
>>   "PREFIX rdf:
>> "+
>>   "SELECT  * " +
>> " WHERE {  ?x rdf:type std:GoodStudent}";
>>
>>  Reasoner reasoner2 = new
>> GenericRuleReasoner(Rule.parseRules(rule));
>>   InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>>  Query query = QueryFactory.create(queryString);
>>   QueryExecution qe = QueryExecutionFactory.create(query,
>> inf);
>>  ResultSet results = qe.execSelect();
>>  ResultSetFormatter.out(System.out, results, query);
>>  qe.close();
>>
>>
>>
>>  try (FileOutputStream writer = new
>> FileOutputStream("C://std.owl")) {
>> model.write(writer, "RDF/XML");
>> } catch (IOException ex) {
>> Logger.getLogger(stdinfo.class
>> .getName()).log(Level.SEVERE,
>> null, ex);
>> }
>> model.write(System.out, "N3");
>>
>> }
>>
>>
>
>

>>>
>>
>


Re: Jena rules not working

2016-09-19 Thread javed khan
Hello Dave, though I have Student class in my owl and GoodStudent as the
subclass of Student but this statement gives me error and does not
recognize GoodStudent.

 for (Iterator i = inf.listResourcesWithProperty(RDF.type, *GoodStudent*);
i.hasNext();) {
System.out.println("Good student: " + i.next());

On Sun, Sep 18, 2016 at 1:36 PM, javed khan  wrote:

> Thanks a lot Dave, let me try it. I hope it will help.
>
> Regards
>
> On Sun, Sep 18, 2016 at 1:28 PM, Dave Reynolds 
> wrote:
>
>> On 18/09/16 21:24, javed khan wrote:
>>
>>> Thanks Lorenz and Dave, I have corrected the
>>> http://www.semanticweb.org#
>>> Student to ?x but it does not
>>> work.Actually it does not save the updated marks/GPA of student and when
>>> I
>>> remove the Jena rules part, it then updates and save the GPA.
>>> I also try the SPARQL query inside Protege Query tab but it does not give
>>> me any instance of the GoodStudent class.
>>>
>>
>> The example I showed does work. If you write inf to file or std out you
>> can see the class, if you run your sparql query it lists s1.
>>
>> Dave
>>
>>
>> On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
>>> buehm...@informatik.uni-leipzig.de> wrote:
>>>
>>> The second condition of your rule doesn't make any sense as the subject
 is Student and it should be ?x.


 On 18.09.2016 17:41, javed khan wrote:

> This code does not work. I want to save student marks/GPA in the file
> and
> based on GPA assign students to GoodStudent or WorstStudents sub
> classes
>
 of

> Student via Jena rules.
>
>
>
>
> OntModel model=ModelFactory.createOntologyModel();
>
>  InputStream in =FileManager.get().open("C://std.owl");
> if (in==null) {
> throw new IllegalArgumentException( "File: " +  " not
> found");
> }   model.read(in,"");
>
>  String ns="http://www.semanticweb.org#;;
>
> OntClass user1 = model.getOntClass(ns + "Student");
>
>Individual indiv = user1.createIndividual(ns + name); //name
>
 is

> variable
>
> Property prop= model.getProperty(ns,"GPA");
>
> indiv.addLiteral(prop, marks); //marks also variable having
> some value i-e 3.0
>
>
>
>  String rule="[rule1:(?x   http://www.w3.org/1999/02/22-
>
 rdf-syntax-ns#type

> http://www.semanticweb.org#Student) " +
>  "( http://www.semanticweb.org#Student
> http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks,
>
 2) "+

>  " ->  (?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
> http://www.semanticweb.org#GoodStudent )]";
>
>  String queryString= "PREFIX std:
 org#>

> "+
>  "PREFIX rdfs: "  +
>   "PREFIX rdf: "+
>   "SELECT  * " +
> " WHERE {  ?x rdf:type std:GoodStudent}";
>
>  Reasoner reasoner2 = new
> GenericRuleReasoner(Rule.parseRules(rule));
>   InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>  Query query = QueryFactory.create(queryString);
>   QueryExecution qe = QueryExecutionFactory.create(query,
> inf);
>  ResultSet results = qe.execSelect();
>  ResultSetFormatter.out(System.out, results, query);
>  qe.close();
>
>
>
>  try (FileOutputStream writer = new
> FileOutputStream("C://std.owl")) {
> model.write(writer, "RDF/XML");
> } catch (IOException ex) {
> Logger.getLogger(stdinfo.class
> .getName()).log(Level.SEVERE,
> null, ex);
> }
> model.write(System.out, "N3");
>
> }
>
>


>>>
>>
>


Re: Jena rules not working

2016-09-18 Thread javed khan
Thanks a lot Dave, let me try it. I hope it will help.

Regards

On Sun, Sep 18, 2016 at 1:28 PM, Dave Reynolds 
wrote:

> On 18/09/16 21:24, javed khan wrote:
>
>> Thanks Lorenz and Dave, I have corrected the  http://www.semanticweb.org#
>> Student to ?x but it does not
>> work.Actually it does not save the updated marks/GPA of student and when I
>> remove the Jena rules part, it then updates and save the GPA.
>> I also try the SPARQL query inside Protege Query tab but it does not give
>> me any instance of the GoodStudent class.
>>
>
> The example I showed does work. If you write inf to file or std out you
> can see the class, if you run your sparql query it lists s1.
>
> Dave
>
>
> On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
>> buehm...@informatik.uni-leipzig.de> wrote:
>>
>> The second condition of your rule doesn't make any sense as the subject
>>> is Student and it should be ?x.
>>>
>>>
>>> On 18.09.2016 17:41, javed khan wrote:
>>>
 This code does not work. I want to save student marks/GPA in the file
 and
 based on GPA assign students to GoodStudent or WorstStudents sub classes

>>> of
>>>
 Student via Jena rules.




 OntModel model=ModelFactory.createOntologyModel();

  InputStream in =FileManager.get().open("C://std.owl");
 if (in==null) {
 throw new IllegalArgumentException( "File: " +  " not
 found");
 }   model.read(in,"");

  String ns="http://www.semanticweb.org#;;

 OntClass user1 = model.getOntClass(ns + "Student");

Individual indiv = user1.createIndividual(ns + name); //name

>>> is
>>>
 variable

 Property prop= model.getProperty(ns,"GPA");

 indiv.addLiteral(prop, marks); //marks also variable having
 some value i-e 3.0



  String rule="[rule1:(?x   http://www.w3.org/1999/02/22-

>>> rdf-syntax-ns#type
>>>
 http://www.semanticweb.org#Student) " +
  "( http://www.semanticweb.org#Student
 http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks,

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

  String queryString= "PREFIX std:>> org#>
>>>
 "+
  "PREFIX rdfs: "  +
   "PREFIX rdf: "+
   "SELECT  * " +
 " WHERE {  ?x rdf:type std:GoodStudent}";

  Reasoner reasoner2 = new
 GenericRuleReasoner(Rule.parseRules(rule));
   InfModel inf = ModelFactory.createInfModel(reasoner2, model);
  Query query = QueryFactory.create(queryString);
   QueryExecution qe = QueryExecutionFactory.create(query, inf);
  ResultSet results = qe.execSelect();
  ResultSetFormatter.out(System.out, results, query);
  qe.close();



  try (FileOutputStream writer = new
 FileOutputStream("C://std.owl")) {
 model.write(writer, "RDF/XML");
 } catch (IOException ex) {
 Logger.getLogger(stdinfo.class.getName()).log(Level.SEVERE,
 null, ex);
 }
 model.write(System.out, "N3");

 }


>>>
>>>
>>
>


Re: Jena rules not working

2016-09-18 Thread Dave Reynolds

On 18/09/16 21:24, javed khan wrote:

Thanks Lorenz and Dave, I have corrected the  http://www.semanticweb.org#
Student to ?x but it does not
work.Actually it does not save the updated marks/GPA of student and when I
remove the Jena rules part, it then updates and save the GPA.
I also try the SPARQL query inside Protege Query tab but it does not give
me any instance of the GoodStudent class.


The example I showed does work. If you write inf to file or std out you 
can see the class, if you run your sparql query it lists s1.


Dave


On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
buehm...@informatik.uni-leipzig.de> wrote:


The second condition of your rule doesn't make any sense as the subject
is Student and it should be ?x.


On 18.09.2016 17:41, javed khan wrote:

This code does not work. I want to save student marks/GPA in the file and
based on GPA assign students to GoodStudent or WorstStudents sub classes

of

Student via Jena rules.




OntModel model=ModelFactory.createOntologyModel();

 InputStream in =FileManager.get().open("C://std.owl");
if (in==null) {
throw new IllegalArgumentException( "File: " +  " not
found");
}   model.read(in,"");

 String ns="http://www.semanticweb.org#;;

OntClass user1 = model.getOntClass(ns + "Student");

   Individual indiv = user1.createIndividual(ns + name); //name

is

variable

Property prop= model.getProperty(ns,"GPA");

indiv.addLiteral(prop, marks); //marks also variable having
some value i-e 3.0



 String rule="[rule1:(?x   http://www.w3.org/1999/02/22-

rdf-syntax-ns#type

http://www.semanticweb.org#Student) " +
 "( http://www.semanticweb.org#Student
http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks,

2) "+

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

 String queryString= "PREFIX std:

"+
 "PREFIX rdfs: "  +
  "PREFIX rdf: "+
  "SELECT  * " +
" WHERE {  ?x rdf:type std:GoodStudent}";

 Reasoner reasoner2 = new
GenericRuleReasoner(Rule.parseRules(rule));
  InfModel inf = ModelFactory.createInfModel(reasoner2, model);
 Query query = QueryFactory.create(queryString);
  QueryExecution qe = QueryExecutionFactory.create(query, inf);
 ResultSet results = qe.execSelect();
 ResultSetFormatter.out(System.out, results, query);
 qe.close();



 try (FileOutputStream writer = new
FileOutputStream("C://std.owl")) {
model.write(writer, "RDF/XML");
} catch (IOException ex) {
Logger.getLogger(stdinfo.class.getName()).log(Level.SEVERE,
null, ex);
}
model.write(System.out, "N3");

}










Re: Jena rules not working

2016-09-18 Thread javed khan
Thanks Lorenz and Dave, I have corrected the  http://www.semanticweb.org#
Student to ?x but it does not
work.Actually it does not save the updated marks/GPA of student and when I
remove the Jena rules part, it then updates and save the GPA.
I also try the SPARQL query inside Protege Query tab but it does not give
me any instance of the GoodStudent class.

On Sun, Sep 18, 2016 at 12:40 PM, Lorenz Buehmann <
buehm...@informatik.uni-leipzig.de> wrote:

> The second condition of your rule doesn't make any sense as the subject
> is Student and it should be ?x.
>
>
> On 18.09.2016 17:41, javed khan wrote:
> > This code does not work. I want to save student marks/GPA in the file and
> > based on GPA assign students to GoodStudent or WorstStudents sub classes
> of
> > Student via Jena rules.
> >
> >
> >
> >
> > OntModel model=ModelFactory.createOntologyModel();
> >
> >  InputStream in =FileManager.get().open("C://std.owl");
> > if (in==null) {
> > throw new IllegalArgumentException( "File: " +  " not
> > found");
> > }   model.read(in,"");
> >
> >  String ns="http://www.semanticweb.org#;;
> >
> > OntClass user1 = model.getOntClass(ns + "Student");
> >
> >Individual indiv = user1.createIndividual(ns + name); //name
> is
> > variable
> >
> > Property prop= model.getProperty(ns,"GPA");
> >
> > indiv.addLiteral(prop, marks); //marks also variable having
> > some value i-e 3.0
> >
> >
> >
> >  String rule="[rule1:(?x   http://www.w3.org/1999/02/22-
> rdf-syntax-ns#type
> > http://www.semanticweb.org#Student) " +
> >  "( http://www.semanticweb.org#Student
> > http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks,
> 2) "+
> >  " ->  (?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
> > http://www.semanticweb.org#GoodStudent )]";
> >
> >  String queryString= "PREFIX std: org#>
> > "+
> >  "PREFIX rdfs: "  +
> >   "PREFIX rdf: "+
> >   "SELECT  * " +
> > " WHERE {  ?x rdf:type std:GoodStudent}";
> >
> >  Reasoner reasoner2 = new
> > GenericRuleReasoner(Rule.parseRules(rule));
> >   InfModel inf = ModelFactory.createInfModel(reasoner2, model);
> >  Query query = QueryFactory.create(queryString);
> >   QueryExecution qe = QueryExecutionFactory.create(query, inf);
> >  ResultSet results = qe.execSelect();
> >  ResultSetFormatter.out(System.out, results, query);
> >  qe.close();
> >
> >
> >
> >  try (FileOutputStream writer = new
> > FileOutputStream("C://std.owl")) {
> > model.write(writer, "RDF/XML");
> > } catch (IOException ex) {
> > Logger.getLogger(stdinfo.class.getName()).log(Level.SEVERE,
> > null, ex);
> > }
> > model.write(System.out, "N3");
> >
> > }
> >
>
>


Re: Jena rules not working

2016-09-18 Thread Lorenz Buehmann
The second condition of your rule doesn't make any sense as the subject
is Student and it should be ?x.


On 18.09.2016 17:41, javed khan wrote:
> This code does not work. I want to save student marks/GPA in the file and
> based on GPA assign students to GoodStudent or WorstStudents sub classes of
> Student via Jena rules.
>
>
>
>
> OntModel model=ModelFactory.createOntologyModel();
>
>  InputStream in =FileManager.get().open("C://std.owl");
> if (in==null) {
> throw new IllegalArgumentException( "File: " +  " not
> found");
> }   model.read(in,"");
>
>  String ns="http://www.semanticweb.org#;;
>
> OntClass user1 = model.getOntClass(ns + "Student");
>
>Individual indiv = user1.createIndividual(ns + name); //name is
> variable
>
> Property prop= model.getProperty(ns,"GPA");
>
> indiv.addLiteral(prop, marks); //marks also variable having
> some value i-e 3.0
>
>
>
>  String rule="[rule1:(?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
> http://www.semanticweb.org#Student) " +
>  "( http://www.semanticweb.org#Student
> http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks, 2) "+
>  " ->  (?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
> http://www.semanticweb.org#GoodStudent )]";
>
>  String queryString= "PREFIX std:
> "+
>  "PREFIX rdfs: "  +
>   "PREFIX rdf: "+
>   "SELECT  * " +
> " WHERE {  ?x rdf:type std:GoodStudent}";
>
>  Reasoner reasoner2 = new
> GenericRuleReasoner(Rule.parseRules(rule));
>   InfModel inf = ModelFactory.createInfModel(reasoner2, model);
>  Query query = QueryFactory.create(queryString);
>   QueryExecution qe = QueryExecutionFactory.create(query, inf);
>  ResultSet results = qe.execSelect();
>  ResultSetFormatter.out(System.out, results, query);
>  qe.close();
>
>
>
>  try (FileOutputStream writer = new
> FileOutputStream("C://std.owl")) {
> model.write(writer, "RDF/XML");
> } catch (IOException ex) {
> Logger.getLogger(stdinfo.class.getName()).log(Level.SEVERE,
> null, ex);
> }
> model.write(System.out, "N3");
>
> }
>



Re: Jena rules not working

2016-09-18 Thread Dave Reynolds

On 18/09/16 16:41, javed khan wrote:

This code does not work.


You haven't shown us the data and haven't said in what way it doesn't work.


I want to save student marks/GPA in the file and
based on GPA assign students to GoodStudent or WorstStudents sub classes of
Student via Jena rules.


[snip]


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


That *still" has the spurious + in from your last question.

Furthermore it is highly unlikely you mean the subject of that pattern 
to be the Student class, it should be ?x.


A simplified version of your code, which doesn't require any input data is:

public void temp() throws Exception {
OntModel model = ModelFactory.createOntologyModel( 
OntModelSpec.OWL_MEM );

String ns = "http://www.semanticweb.org#;;

OntClass Student = model.createClass(ns + "Student");
OntClass GoodStudent = model.createClass(ns + "GoodStudent");
Individual indiv = Student.createIndividual(ns + "s1");
Property prop = model.getProperty(ns, "GPA");
indiv.addLiteral(prop, 3);

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

+ "( ?x http://www.semanticweb.org#GPA  ?marks )"
+ "greaterThan(?marks, 2) "
+ " ->  (?x 
http://www.w3.org/1999/02/22-rdf-syntax-ns#type 
http://www.semanticweb.org#GoodStudent )]";


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

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

for (Iterator i = inf.listResourcesWithProperty(RDF.type, 
GoodStudent); i.hasNext();) {

System.out.println("Good student: " + i.next());
}
}

Which produces the output:

Good student: http://www.semanticweb.org#s1

Dave


Jena rules not working

2016-09-18 Thread javed khan
This code does not work. I want to save student marks/GPA in the file and
based on GPA assign students to GoodStudent or WorstStudents sub classes of
Student via Jena rules.




OntModel model=ModelFactory.createOntologyModel();

 InputStream in =FileManager.get().open("C://std.owl");
if (in==null) {
throw new IllegalArgumentException( "File: " +  " not
found");
}   model.read(in,"");

 String ns="http://www.semanticweb.org#;;

OntClass user1 = model.getOntClass(ns + "Student");

   Individual indiv = user1.createIndividual(ns + name); //name is
variable

Property prop= model.getProperty(ns,"GPA");

indiv.addLiteral(prop, marks); //marks also variable having
some value i-e 3.0



 String rule="[rule1:(?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.semanticweb.org#Student) " +
 "( http://www.semanticweb.org#Student
http://www.semanticweb.org#GPA  ?marks +   )"   + "greaterThan(?marks, 2) "+
 " ->  (?x   http://www.w3.org/1999/02/22-rdf-syntax-ns#type
http://www.semanticweb.org#GoodStudent )]";

 String queryString= "PREFIX std:
"+
 "PREFIX rdfs: "  +
  "PREFIX rdf: "+
  "SELECT  * " +
" WHERE {  ?x rdf:type std:GoodStudent}";

 Reasoner reasoner2 = new
GenericRuleReasoner(Rule.parseRules(rule));
  InfModel inf = ModelFactory.createInfModel(reasoner2, model);
 Query query = QueryFactory.create(queryString);
  QueryExecution qe = QueryExecutionFactory.create(query, inf);
 ResultSet results = qe.execSelect();
 ResultSetFormatter.out(System.out, results, query);
 qe.close();



 try (FileOutputStream writer = new
FileOutputStream("C://std.owl")) {
model.write(writer, "RDF/XML");
} catch (IOException ex) {
Logger.getLogger(stdinfo.class.getName()).log(Level.SEVERE,
null, ex);
}
model.write(System.out, "N3");

}


Re: Jena Rules not working

2016-07-26 Thread javed khan
Thanks a lot, error is no longer there but not displaying the required
result either i-e instance of StudentExpert class. I, for test case,
created instance of StudentExpert and it display it (so no problem in
ontology) but when I remove the instance, again it display nothing. It
means reasoner not working
.
code is here:

public class Student {
public static void main(String args[])

{

OntModel
model=ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_RDFS_INF);
InputStream in= FileManager.get().open("D://Jena/std.owl");
if (in==null) {
throw new IllegalArgumentException( "File: " +  " not there");
}
model.read(in, null);

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

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

* "->(?x http://www.w3.org/1999/02/22-rdf-syntax-ns#rdf:type

http://www.semanticweb.org/141#StudentExpert)
]";*

String str= "Prefix std: " +
"PREFIX rdf: \n"+

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

Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
InfModel inf = ModelFactory.createInfModel(reasoner2, model);

Query query=QueryFactory.create(str);
QueryExecution qe=QueryExecutionFactory.create(query, inf);
ResultSet rs=qe.execSelect();

 ResultSetFormatter.out(System.out, rs, query);
}}

On Tue, Jul 26, 2016 at 2:41 AM, Lorenz B. <
buehm...@informatik.uni-leipzig.de> wrote:

> As Dave said, wrong PREFIX declaration.
> >>
> >>  "Select *" + "where {   ?x rdf:type std:StudentExpert  }";
> >>
> Moreover, your String concatenation will lead to
>
> Select *where {   ?x rdf:type std:StudentExpert  }
>
> i.e. there is a missing whitespace before "where".
>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>


Re: Jena Rules not working

2016-07-26 Thread Lorenz B.
As Dave said, wrong PREFIX declaration.
>>
>>  "Select *" + "where {   ?x rdf:type std:StudentExpert  }";
>>
Moreover, your String concatenation will lead to

Select *where {   ?x rdf:type std:StudentExpert  }

i.e. there is a missing whitespace before "where".

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



Re: Jena Rules not working

2016-07-26 Thread Dave Reynolds

On 26/07/16 09:53, javed khan wrote:

I have class *Expert*, *Research* and *Student*. Student has Master and Phd
subclasses. Expert hasResearch Research, like BernersLee hasResearch
Ontologies. Phd Student also have Research like: Khan hasResearch
Ontologies.

I added a class *StudentExpert* which have no instance but can be created
with Jena rules.

In Protege, when I give: . SELECT *

 WHERE { ?sub std:hasResearch ?x  }  it gives me research of
both Phd and Expert.

I give then: . SELECT *

 WHERE { ?sub std:hasResearch ?x  . ?sub rdf:type std:Phd }

And it filters research for Phd class only.

In Jena, after read the file, I gives the rules as:

String rule = "[rule1:(?x http://www.semanticweb.org/141#hasResearch ?y) " +

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



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

And query like this:

String str= "Prefix  std: " +

 "PREFIX rdfs: \n"+ "PREFIX
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+

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



I expect it will answer me: instance Khan to be StudentExpert instance but
it gives me exception:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered "  "http: "" at line 2, column 13.

Was expecting:

  ...



 at
com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87)


So that is telling the syntax of your SPARQL query is wrong, in 
particular that it has found http:... when it expected <...


The error is at:

  PREFIX rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#>

which should be

 PREFIX rdf: 

Nothing to do with your rules.

Dave


Jena Rules not working

2016-07-26 Thread javed khan
I have class *Expert*, *Research* and *Student*. Student has Master and Phd
subclasses. Expert hasResearch Research, like BernersLee hasResearch
Ontologies. Phd Student also have Research like: Khan hasResearch
Ontologies.

I added a class *StudentExpert* which have no instance but can be created
with Jena rules.

In Protege, when I give: . SELECT *

WHERE { ?sub std:hasResearch ?x  }  it gives me research of
both Phd and Expert.

I give then: . SELECT *

WHERE { ?sub std:hasResearch ?x  . ?sub rdf:type std:Phd }

And it filters research for Phd class only.

In Jena, after read the file, I gives the rules as:

String rule = "[rule1:(?x http://www.semanticweb.org/141#hasResearch ?y) " +

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



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

And query like this:

String str= "Prefix  std: " +

"PREFIX rdfs: \n"+ "PREFIX
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"+

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



I expect it will answer me: instance Khan to be StudentExpert instance but
it gives me exception:

Exception in thread "main" com.hp.hpl.jena.query.QueryParseException:
Encountered "  "http: "" at line 2, column 13.

Was expecting:

 ...



at
com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:87)

at
com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40)

at
com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132)

at
com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69)

at
com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)