0

The following is a subquestion to my previous question: available here.

How to modify the following SPARQL query:

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>

select ?dt ?element ?elementType {
   ?dt a rdfs:Datatype ;
   owl:oneOf/rdf:rest*/rdf:first ?element .
   bind(datatype(?element) as ?elementType)
}

in order to to get a result of only A and C? I would like to obtain { "a1" "a2" "c1" "c2" }. The above query returns all enumeration values from the ontology, I mean: { "a1" "a2" "b1" "b2" "c1" "c2" }

We are given the ontology (A and B are equivalent but presented in different style syntax):

Variant A) in the functional style syntax:

 Prefix(ont:=<http://www/ont.owl#>)
 Prefix(owl:=<http://www.w3.org/2002/07/owl#>)
 Prefix(rdf:=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>)
 Prefix(xsd:=<http://www.w3.org/2001/XMLSchema#>)
 Prefix(rdfs:=<http://www.w3.org/2000/01/rdf-schema#>)

 Ontology(<http://www/ont.owl>
    DatatypeDefinition( ont:A DataOneOf( "a1" "a2" ) ) 
    DatatypeDefinition( ont:B DataOneOf( "b1" "b2" ) ) 
    DatatypeDefinition( ont:C DataOneOf( "c1" "c2" ) )      
 )

Variant B) in the RDF/XML style syntax:

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
<!ENTITY ont "http://www/ont.owl#" >
<!ENTITY owl "http://www.w3.org/2002/07/owl#" >
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
<!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
]>

<rdf:RDF xmlns="http://www/ont.owl#"
 xml:base="http://www/ont.owl"
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
 xmlns:ont="http://www/ont.owl#"
 xmlns:owl="http://www.w3.org/2002/07/owl#"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:xml="http://www.w3.org/XML/1998/namespace">
<owl:Ontology rdf:about="http://www/ont.owl"/>



<!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Datatypes
//
///////////////////////////////////////////////////////////////////////////////////////
 -->




<!-- http://www/ont.owl#A -->

<rdfs:Datatype rdf:about="&ont;A">
    <owl:equivalentClass>
        <rdfs:Datatype>
            <owl:oneOf>
                <rdf:Description>
                    <rdf:type rdf:resource="&rdf;List"/>
                    <rdf:first>a1</rdf:first>
                    <rdf:rest>
                        <rdf:Description>
                            <rdf:type rdf:resource="&rdf;List"/>
                            <rdf:first>a2</rdf:first>
                            <rdf:rest rdf:resource="&rdf;nil"/>
                        </rdf:Description>
                    </rdf:rest>
                </rdf:Description>
            </owl:oneOf>
        </rdfs:Datatype>
    </owl:equivalentClass>
</rdfs:Datatype>



<!-- http://www/ont.owl#B -->

<rdfs:Datatype rdf:about="&ont;B">
    <owl:equivalentClass>
        <rdfs:Datatype>
            <owl:oneOf>
                <rdf:Description>
                    <rdf:type rdf:resource="&rdf;List"/>
                    <rdf:first>b1</rdf:first>
                    <rdf:rest>
                        <rdf:Description>
                            <rdf:type rdf:resource="&rdf;List"/>
                            <rdf:first>b2</rdf:first>
                            <rdf:rest rdf:resource="&rdf;nil"/>
                        </rdf:Description>
                    </rdf:rest>
                </rdf:Description>
            </owl:oneOf>
        </rdfs:Datatype>
    </owl:equivalentClass>
</rdfs:Datatype>



<!-- http://www/ont.owl#C -->

<rdfs:Datatype rdf:about="&ont;C">
    <owl:equivalentClass>
        <rdfs:Datatype>
            <owl:oneOf>
                <rdf:Description>
                    <rdf:type rdf:resource="&rdf;List"/>
                    <rdf:first>c1</rdf:first>
                    <rdf:rest>
                        <rdf:Description>
                            <rdf:type rdf:resource="&rdf;List"/>
                            <rdf:first>c2</rdf:first>
                            <rdf:rest rdf:resource="&rdf;nil"/>
                        </rdf:Description>
                    </rdf:rest>
                </rdf:Description>
            </owl:oneOf>
        </rdfs:Datatype>
    </owl:equivalentClass>
</rdfs:Datatype>
</rdf:RDF>

<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->
Community
  • 1
  • 1
Annabelle
  • 734
  • 9
  • 23
  • I'm not clear how it makes sense to have a list of literals for equivalent class relationships. – scotthenninger May 10 '16 at 21:07
  • @scotthenninger It's correct, that's the TURTLE style syntax to represent a user-defined datatype in OWL2. – UninformedUser May 10 '16 at 22:04
  • I.e. datatypes and classes are different things. It doesn't make sense to have a list of strings as equivalent classes. A list of URIs would make sense. – scotthenninger May 10 '16 at 22:11
  • See @ASKW's comment. Something is not right. `"a1"` cannot be an equivalent class. `:a1` could be. A class must be represented by a URI. – scotthenninger May 10 '16 at 22:31
  • There was no mistake, but in order to avoid any misunderstandings, I edited my question and posted the ontology in the functional style syntax – Annabelle May 10 '16 at 22:43
  • If you're looking to query this in SPARQL, Turtle would be best, as the syntax for the query will fall in place. BTW, the functional syntax does not match the RDF/XML serialization you posted earlier. Not close. Something is wrong with the translation or you posted the wrong file. – scotthenninger May 11 '16 at 01:11
  • @scotthenninger is not common to see it, but this is apparently the way that datatype definitions are encoded in RDF, using owl:equivalentClass. If you load that RDF/XML into protégé and save in the functional syntax, you get that ontology. This is for enumerated datatype expressions like `{"a" "b" "c"}`. – Joshua Taylor May 11 '16 at 11:08

1 Answers1

1

As I said in the comments on the previous answer:

@Annabelle I was basing the retrieval methods on the ontology that I provided. There are certainly other ways to select the data types if they're identified by IRIs. In your case, it looks like it would be values ?dt {:A :B } if you only want ?dt to be A or B.

and

In this case, note that the axiom is encoded by saying that :A is owl:equivalentClass to the datatype class expression. That's the extra link you need between the class IRI and the expression.

That gives us:

select ?dt ?element ?elementType {
  values  ?dt { ont:A ont:B }
  ?dt owl:equivalentClass/a rdfs:Datatype ;
      owl:oneOf/rdf:rest*/rdf:first ?element .
  bind(datatype(?element) as ?elementType)
}

This really isn't much different from the previous answer. You just need to add on the specific values that you're looking for, and then add the equivalentClass link.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Yes, but it does not want to work somehow. With the line "values (...)" No output is printed. Without the line "values (...)" I am reciving such an output: | dt | element | elementType | | _:b0 | "b1" | xsd:string | | _:b0 | "b2" | xsd:string | | _:b1 | "a1" | xsd:string | | _:b1 | "a2" | xsd:string | | _:b2 | "c1" | xsd:string | | _:b2 | "c2" | xsd:string | – Annabelle May 11 '16 at 16:16
  • @annabelle It's not "values ()", it's "values ?dt { ... }" with a variable name and curly braces, not parentheses. Again though, without your actual RDF data, we can't test the queries. Could you provide the actual RDF data, please? Also, how are you running your queries? – Joshua Taylor May 11 '16 at 17:05
  • I'm sorry for being not precise. In the comment above by "values (...)" I ment "values ?dt { ont:A ont:B }". I also added the ontology in RDF/XML style. – Annabelle May 11 '16 at 17:51
  • I wish I could run my queries with Protege but as it does not support "values" (or I cannot make it work) I am also using Apache Jena. – Annabelle May 11 '16 at 17:56
  • Yes, protégé doesn't support sparql 1.1. Jena does though. – Joshua Taylor May 11 '16 at 19:07
  • Do you have any suggestions why on Jena (run from Java code) I am receiving the above output? – Annabelle May 12 '16 at 09:40