Hi Dave,

I tested exactly your code and the result was:
 - (exa:Ricardo exa:seaPartner exa:Miguel)
 - (exa:Miguel exa:seaPartner exa:Ricardo)
 - (exa:Miguel exa:seaPartner -484cfb84:144a5ec16c1:-7fcf)
 - (exa:Ricardo exa:seaPartner -484cfb84:144a5ec16c1:-7fce)
---------------------------------------------------------------------------
------------
| x                                        | y
           |
===========================================================================
============
| <http://www.example.org/example#Ricardo> |
<http://www.example.org/example#Miguel>  |
| <http://www.example.org/example#Miguel>  |
<http://www.example.org/example#Ricardo> |
| <http://www.example.org/example#Miguel>  | _:b0
           |
| <http://www.example.org/example#Ricardo> | _:b1
           |
---------------------------------------------------------------------------
------------


Really, i don¹t understand. I only included the file that I put available
in other mail, I removed other rules and I didn¹t included pellet engine.
I¹m using Jena 11.0. Related to your code, the prefix is ³exa² and not
³eax². 

Below, I list my java code.

Miguel


package jenatest26;

import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.util.FileManager;
import com.hp.hpl.jena.util.PrintUtil;
import java.util.List;

/**
 *
 * @author mba
 */
public class Jenatest26 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
                String NS = "http://www.example.org/example#";;
     PrintUtil.registerPrefix("exa", NS);

     Model data =
    
FileManager.get().loadModel("/Volumes/DATA/MBA/Doutoramento/mbaowl1/schema_
data_Sport2.xml");
     List<Rule> rules =
Rule.rulesFromURL("/Volumes/DATA/MBA/Doutoramento/mbaowl1/rules_sport.txt")
;
     GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
     InfModel inf = ModelFactory.createInfModel(reasoner, data);
     inf.setNsPrefixes(data);
     printStatements(inf, null, inf.createProperty(NS + "seaPartner"),
null);

     String query = "prefix exa: <http://www.example.org/example#> "+
        " select ?x ?y where { ?x exa:seaPartner ?y . }";
     QueryExecution qexec = QueryExecutionFactory.create(query, inf);
     ResultSetFormatter.out( qexec.execSelect() );
    }
    
       public static void printStatements(Model m, Resource s, Property p,
Resource o) {
        for (StmtIterator i = m.listStatements(s,p,o); i.hasNext(); ) {
            Statement stmt = i.nextStatement();
            System.out.println(" - " + PrintUtil.print(stmt));
        }
    }
    
}





On 08/03/14 18:58, "Dave Reynolds" <[email protected]> wrote:

>On 08/03/14 13:05, Miguel Bento Alves wrote:
>> I have an ontology where is defined that several sports are played by
>> several people. if you want to consult it, the file is in the following
>> link:
>> https://www.dropbox.com/s/vcazac9vdvx4me6/schema_data_Sport2.xml
>>
>>
>> I have the follow jena rule:
>>
>> (?x exa:seaPartner ?y) <-
>> (?x exa:playSport ?s1),
>> (?y exa:playSport ?s2),
>> notEqual(?x, ?y),
>> (?s1 rdf:type exa:SeaSport),
>> (?s2 rdf:type exa:SeaSport).
>>
>> When I execute the follow SPARQL command:
>> prefix exa: <http://www.example.org/example#>
>> select ?x ?y
>> where {
>> ?x exa:sportPartner ?y .
>> }
>
>I assume you mean exa:seaPartner.
>
>> the output is:
>> x -> exa:Ricardo; y -> exa:Miguel;
>> x -> exa:Miguel; y -> exa:Ricardo;
>> x -> exa:Miguel; y -> null:null;
>> x -> exa:Ricardo; y -> null:null;
>>
>> I don't understand why the last two rows are listed.
>
>Works for me:
>
>"""
>     String NS = "http://www.example.org/example#";;
>     PrintUtil.registerPrefix("eax", NS);
>
>     Model data = 
>FileManager.get().loadModel("data/schema_data_Sport2.rdf");
>     List<Rule> rules = Rule.rulesFromURL("file:data/test.rules");
>     GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
>     InfModel inf = ModelFactory.createInfModel(reasoner, data);
>     inf.setNsPrefixes(data);
>     printStatements(inf, null, inf.createProperty(NS + "seaPartner"),
>null);
>
>     String query = "prefix exa: <http://www.example.org/example#>
>select ?x ?y where { ?x exa:seaPartner ?y . }";
>     QueryExecution qexec = QueryExecutionFactory.create(query, inf);
>     ResultSetFormatter.out( qexec.execSelect() );
>"""
>
>where test.rules is your rule, produces:
>
>  - (eax:Ricardo eax:seaPartner eax:Miguel)
>  - (eax:Miguel eax:seaPartner eax:Ricardo)
>
>--------------------------------------------------------------------------
>-------------
>| x                                        | y
>               |
>==========================================================================
>=============
>| <http://www.example.org/example#Ricardo> |
><http://www.example.org/example#Miguel>  |
>| <http://www.example.org/example#Miguel>  |
><http://www.example.org/example#Ricardo> |
>--------------------------------------------------------------------------
>-------------
>
>Perhaps you have some other rules, such as the OWL rules?
>
>Dave
>


Reply via email to