owl2sparql-core

A simple OWL to SPARQL converter

License

License

GroupId

GroupId

org.seerc.paasword
ArtifactId

ArtifactId

owl2sparql-core
Last Version

Last Version

0.1
Release Date

Release Date

Type

Type

jar
Description

Description

owl2sparql-core
A simple OWL to SPARQL converter
Project URL

Project URL

https://github.com/AKSW/OWL2SPARQL
Project Organization

Project Organization

AKSW
Source Code Management

Source Code Management

https://github.com/chrispetsos/OWL2SPARQL

Download owl2sparql-core

How to add to project

<!-- https://jarcasting.com/artifacts/org.seerc.paasword/owl2sparql-core/ -->
<dependency>
    <groupId>org.seerc.paasword</groupId>
    <artifactId>owl2sparql-core</artifactId>
    <version>0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.seerc.paasword/owl2sparql-core/
implementation 'org.seerc.paasword:owl2sparql-core:0.1'
// https://jarcasting.com/artifacts/org.seerc.paasword/owl2sparql-core/
implementation ("org.seerc.paasword:owl2sparql-core:0.1")
'org.seerc.paasword:owl2sparql-core:jar:0.1'
<dependency org="org.seerc.paasword" name="owl2sparql-core" rev="0.1">
  <artifact name="owl2sparql-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.seerc.paasword', module='owl2sparql-core', version='0.1')
)
libraryDependencies += "org.seerc.paasword" % "owl2sparql-core" % "0.1"
[org.seerc.paasword/owl2sparql-core "0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
net.sourceforge.owlapi : owlapi-distribution jar 4.2.4
com.google.guava : guava jar 19.0
org.apache.jena : jena-arq jar 2.13.0

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

OWL2SPARQL - "Yet another OWL To SPARQL Query rewriter?!"

Build Status Coverity Scan Build Status Codacy Badge This project provides a simple converter from OWL axioms and OWL class expressions to SPARQL queries.

Maven Settings

<repositories>
    <repository>
        <id>maven.aksw.internal</id>
        <name>University Leipzig, AKSW Maven2 Repository</name>
        <url>http://maven.aksw.org/archiva/repository/internal</url>
    </repository>

    <repository>
        <id>maven.aksw.snapshots</id>
        <name>University Leipzig, AKSW Maven2 Repository</name>
        <url>http://maven.aksw.org/archiva/repository/snapshots</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.aksw.owl2sparql</groupId>
        <artifactId>owl2sparql-core</artifactId>
        <version>0.1</version>
    </dependency>

    ...
</dependencies>

From OWL axiom to SPARQL query

Usage

// create the converter
OWLAxiomToSPARQLConverter converter = new OWLAxiomToSPARQLConverter("?s","?o");

// provide some OWL axiom using OWL API datastructures
OWLAxiom axiom = ...;

// convert the axiom into a SPARQL query
String queryString = converter.convert(axiom);

Example

OWL axiom (in Manchester OWL Syntax)

PREFIX: : <http://example.org#>
ObjectProperty: r
  Domain: A

SPARQL query

PREFIX : <http://example.org#>
SELECT DISTINCT  ?s
WHERE
  { ?s :r ?s0 .
    ?s a :A
  }

From OWL class expression to SPARQL query

Usage

// create the converter
OWLClassExpressionToSPARQLConverter converter = new OWLClassExpressionToSPARQLConverter();

// provide some OWL class expression using OWL API datastructures
OWLClassExpression ce = ...;

// convert the class expression into a SPARQL query
String queryString = converter.convert(ce);

Example

OWL class expression (in Manchester OWL Syntax)

PREFIX: : <http://example.org#>
A and ( B or not (r some B))

SPARQL query

PREFIX : <http://example.org#>
SELECT DISTINCT  ?x
WHERE
  { ?x a :A
      { ?x a :B }
    UNION
      { ?x ?p ?o
        FILTER NOT EXISTS {
          ?x :r ?s0 .
          ?s0 a :B
        }
      }  
  }

License

The source code of this repo is published under the Apache License Version 2.0.

This project makes use of several dependencies: When in doubt, please cross-check with the respective projects:

  • OWL API (Apache License 2.0 and GNU LGPL Version 3.0)
  • Apache Jena (Apache License 2.0)
  • Guava (Apache License 2.0)

More Examples

Class Expression SPARQL Query
A
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A>}

A
 and (B or (not (r some Thing)))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> { ?x rdf:type <B>} UNION { ?x ?p ?o FILTER NOT EXISTS {?x <r> ?s0} } }

A
 and (not (B))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> FILTER NOT EXISTS {?x rdf:type <B>} }

A
 and (not (r some B))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> FILTER NOT EXISTS {?x <r> ?s0 . ?s0 rdf:type <B> } }

A
 and (r some  Self )
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> . ?x <r> ?x }

A
 and (t some boolean)
BASE    <http://example.org/ontology/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> . ?x <t> ?s0 FILTER ( datatype(?s0) = xsd:boolean ) }

A
 and (t some  not boolean)
BASE    <http://example.org/ontology/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> . ?x <t> ?s0 FILTER ( datatype(?s0) != xsd:boolean ) }

A
 and (t value 1)
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> . ?x <t> 1 }

A
 and (t min 2 boolean)
BASE    <http://example.org/ontology/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <A> { SELECT ?x WHERE { ?x <t> ?s0 FILTER ( datatype(?s0) = xsd:boolean ) } GROUP BY ?x HAVING ( COUNT(?s0) >= 2 ) } }

B
 and (r some B)
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <B> . ?x <r> ?s0 . ?s0 rdf:type <B> }

B
 and (r some B)
 and (s some A)
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <B> . ?x <r> ?s0 . ?s0 rdf:type <B> . ?x <s> ?s1 . ?s1 rdf:type <A> }

B
 and (r some 
    (C
     and (s some A)))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <B> . ?x <r> ?s0 . ?s0 rdf:type <C> . ?s0 <s> ?s1 . ?s1 rdf:type <A> }

Place
 and (language min 2 Language)
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x rdf:type <Place> { SELECT ?x WHERE { ?x <language> ?s0 . ?s0 rdf:type <Language> } GROUP BY ?x HAVING ( COUNT(?s0) >= 2 ) } }

(not (A))
 and (r some (s some (not (B))))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { FILTER NOT EXISTS {?x rdf:type <A>} ?x <r> ?s0 . ?s0 <s> ?s1 FILTER NOT EXISTS {?s1 rdf:type <B>} }

A or B
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { { ?x rdf:type <A>} UNION { ?x rdf:type <B>} }

(not (A)) or (not (B))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { { ?x ?p ?o FILTER NOT EXISTS {?x rdf:type <A>} } UNION { ?x ?p ?o FILTER NOT EXISTS {?x rdf:type <B>} } }

not (B)
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x ?p ?o FILTER NOT EXISTS {?x rdf:type <B>} }

{a , b}
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { VALUES ?x { <a> <b> }}

r some B
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x <r> ?s0 . ?s0 rdf:type <B> }

r some 
    (A
     and (not (B)))
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x <r> ?s0 . ?s0 rdf:type <A> FILTER NOT EXISTS {?s0 rdf:type <B>} }

r some ({a})
(logically equivalent to
r value a)
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <r> <a>}

r some ({a , b})
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <r> ?s0 VALUES ?s0 { <a> <b> } }

language only Language
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x ?p ?o FILTER NOT EXISTS {?x <language> ?s1 FILTER NOT EXISTS {?s1 rdf:type <Language>} } }

r only B
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x ?p ?o FILTER NOT EXISTS {?x <r> ?s1 FILTER NOT EXISTS {?s1 rdf:type <B>} } }

r only Thing
(logically equivalent to
Thing)
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x ?p ?o}

r only 
    (A
     and (s only Thing))
(logically equivalent to
r only A)
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x ?p ?o FILTER NOT EXISTS {?x <r> ?s1 FILTER NOT EXISTS {?s1 rdf:type <A>} } }

r only 
    (A or (s only Thing))
(logically equivalent to
Thing)
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x ?p ?o}

r only (s only Thing)
(logically equivalent to
Thing)
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x ?p ?o}

r value a
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <r> <a>}

language min 2 Language
BASE    <http://example.org/ontology/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?x WHERE { ?x <language> ?s0 . ?s0 rdf:type <Language> } GROUP BY ?x HAVING ( COUNT(?s0) >= 2 )

t some (integer or (boolean and {1 , 2}))
BASE    <http://example.org/ontology/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?x WHERE { ?x <t> ?s0 FILTER ( ( datatype(?s0) = xsd:integer ) || ( ( datatype(?s0) = xsd:boolean ) && ( ?s0 IN (1, 2) ) ) ) }

t some  not ({1 , 2})
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <t> ?s0 FILTER ( ?s0 NOT IN (1, 2) ) }

t some {1 , 2}
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <t> ?s0 FILTER ( ?s0 IN (1, 2) ) }

t some (boolean and {1 , 2})
BASE    <http://example.org/ontology/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?x WHERE { ?x <t> ?s0 FILTER ( ( datatype(?s0) = xsd:boolean ) && ( ?s0 IN (1, 2) ) ) }

t some PlainLiteral[length 10]
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <t> ?s0 FILTER strlen(( str(?s0) = 10 )) }

t some integer[>= 3 , < 10]
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x <t> ?s0 FILTER ( ( ?s0 >= 3 ) && ( ?s0 < 10 ) ) }

t only boolean
BASE    <http://example.org/ontology/>
PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?x WHERE { ?x ?p ?o FILTER NOT EXISTS {?x <t> ?s1 FILTER ( datatype(?s1) != xsd:boolean ) } }

t only {1}
BASE    <http://example.org/ontology/>

SELECT DISTINCT ?x WHERE { ?x ?p ?o FILTER NOT EXISTS {?x <t> ?s1 FILTER ( ?s1 NOT IN (1) ) } }

org.seerc.paasword

AKSW Research Group @ University of Leipzig

Versions

Version
0.1