Search code examples
rdfjenaowlprotegeprotege4

Different result in Protege 4.3 and result in jena in Eclipse


In Protégé 4.3 I have results with ObjectProperties (exactly as I need). But I need to implement it in my project so I use Jena in Eclipse and the result is different. How can I get object with ObjectProperties in Jena?

Protégé: https://i.sstatic.net/oLpCD.png

Eclipse Jena:

------------------------------------------------------------------------------- | 
subject                                | object                     
|
=============================================================================== | vidlica:VidlicaKrytTelo                | _:b0                       
| | vidlica:KolikNulovy_SkrutkaM3          | _:b1                     
| | vidlica:KolikFazovy_SkrutkaM3          | _:b2                     
| | vidlica:Hlava_4Kolik_SkrutkaM3_Nalepka | _:b3                     
| | vidlica:Hlava_4Kolik_SkrutkaM3         | _:b4                     
| | vidlica:Final                          | _:b5                     
| | _:b5                                   | vidlica:Final            
| | _:b4                                   |
vidlica:Hlava_4Kolik_SkrutkaM3         | | _:b2                       
| vidlica:KolikFazovy_SkrutkaM3          | | _:b3                     
| vidlica:Hlava_4Kolik_SkrutkaM3_Nalepka | | _:b1                     
| vidlica:KolikNulovy_SkrutkaM3          | | _:b0                     
| vidlica:VidlicaKrytTelo                | | vidlica:TesnenieGumove   
| vidlica:TesnenieGumove                 | | rdf:List                 
| rdf:List                               | | _:b6                     
| _:b6                                   | | _:b7                     
| _:b7                                   | | owl:Restriction          

Solution

  • I have no prob to write down some code as answer, but its hard to write it clear and easy to understand.

    One more time: I ask how to get in jena sparql result like this object + object property + subject(s) [ C2-C4].

    And the result is (this sample with 3 subjects)

    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    SELECT ?c ?p1 ?C2 ?C3 ?C4
    WHERE { 
        ?c rdfs:subClassOf ?r . 
        ?r rdf:type owl:Restriction . 
        ?r owl:onProperty ?p1 . 
        ?r owl:someValuesFrom ?i . 
        ?i rdf:type owl:Class . 
        ?i ?prop ?l . 
        ?l rdf:first ?C2 . 
        ?l rdf:rest ?m . 
        ?m rdf:first ?C3 . 
        ?m rdf:rest ?m2 . 
        ?m2 rdf:first ?C4 . 
        ?m2 rdf:rest rdf:nil .
        }