How to stack SpinSail on top of GraphDB remote repository - graphdb

I am using GraphDB to store my triples and need to stack SpinSail component upon the GraphDB to support Spin Rules along with all the rest of the features that GraphDB supports by default.
So far I have managed to create a SailRepository on the remote server supporting Spin Rules (more details below) but it seems that it only supports Spin and none of the other features that GraphDB supports (e.g. reviewing the Graph, adding triples through files, searching etc.)
The configuration file, once the repository is created, looks like below:
#prefix ms: <http://www.openrdf.org/config/sail/memory#> .
#prefix rep: <http://www.openrdf.org/config/repository#> .
#prefix sail: <http://www.openrdf.org/config/sail#> .
#prefix sr: <http://www.openrdf.org/config/repository/sail#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<#Test1> a rep:Repository;
rep:repositoryID "Test1";
rep:repositoryImpl [
rep:repositoryType "openrdf:SailRepository";
sr:sailImpl [
sail:delegate [
sail:sailType "openrdf:MemoryStore";
ms:persist true
];
sail:sailType "openrdf:SpinSail"
]
] .
Although a normal configuration file (i.e. if someone would create a repository through the workbench) would look like the one below:
#prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
#prefix rep: <http://www.openrdf.org/config/repository#> .
#prefix sail: <http://www.openrdf.org/config/sail#> .
#prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<#Test> a rep:Repository;
rep:repositoryID "Test";
rep:repositoryImpl [
rep:repositoryType "graphdb:FreeSailRepository";
<http://www.openrdf.org/config/repository/sail#sailImpl> [
<http://www.ontotext.com/trree/owlim#base-URL> "http://example.org/owlim#";
<http://www.ontotext.com/trree/owlim#check-for-inconsistencies> "false";
<http://www.ontotext.com/trree/owlim#defaultNS> "";
<http://www.ontotext.com/trree/owlim#disable-sameAs> "false";
<http://www.ontotext.com/trree/owlim#enable-context-index> "false";
<http://www.ontotext.com/trree/owlim#enable-literal-index> "true";
<http://www.ontotext.com/trree/owlim#enablePredicateList> "true";
<http://www.ontotext.com/trree/owlim#entity-id-size> "32";
<http://www.ontotext.com/trree/owlim#entity-index-size> "10000000";
<http://www.ontotext.com/trree/owlim#imports> "";
<http://www.ontotext.com/trree/owlim#in-memory-literal-properties> "true";
<http://www.ontotext.com/trree/owlim#query-limit-results> "0";
<http://www.ontotext.com/trree/owlim#query-timeout> "0";
<http://www.ontotext.com/trree/owlim#read-only> "false";
<http://www.ontotext.com/trree/owlim#repository-type> "file-repository";
<http://www.ontotext.com/trree/owlim#ruleset> "owl2-rl-optimized";
<http://www.ontotext.com/trree/owlim#storage-folder> "storage";
<http://www.ontotext.com/trree/owlim#throw-QueryEvaluationException-on-timeout> "false";
sail:sailType "graphdb:FreeSail"
]
];
rdfs:label "Test" .
The following code was used to create the repository.
RemoteRepositoryManager manager = new RemoteRepositoryManager("http://localhost:7200");
manager.init();
String repositoryId = "Test1";
// create a configuration for the SAIL stack
boolean persist = true;
// create a configuration for the SAIL stack
SailImplConfig spinSailConfig = new MemoryStoreConfig(persist);
spinSailConfig = new SpinSailConfig(spinSailConfig);
RepositoryImplConfig repositoryTypeSpec = new SailRepositoryConfig(spinSailConfig);
// create a configuration for the repository implementation
// RepositoryImplConfig repositoryTypeSpec = new SailRepositoryConfig(backendConfig);
RepositoryConfig repConfig = new RepositoryConfig(repositoryId, repositoryTypeSpec);
manager.addRepositoryConfig(repConfig);
Once I created this repository I was able to insert the following rule into it through the SPARQL section (by using INSERT DATA):
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX sp: <http://spinrdf.org/sp#>
PREFIX spin: <http://spinrdf.org/spin#>
PREFIX ex: <http://example.org/>
INSERT DATA {
ex:Person a rdfs:Class ;
spin:rule [
a sp:Construct ;
sp:text """PREFIX ex: <http://example.org/>
CONSTRUCT { ?this ex:childOf ?parent . }
WHERE { ?parent ex:parentOf ?this . }"""
] . }
and then similarly add the following statements:
PREFIX ex: <http://example.org/>
INSERT DATA {
ex:John a ex:Father ;
ex:parentOf ex:Lucy .
ex:Lucy a ex:Person .
}
After that by running the following query:
PREFIX ex: <http://example.org/>
SELECT ?child WHERE { ?child ex:childOf ?parent }
I was able to confirm that the Spin rule was executed successfully.
So my question is:
Is there a way to create a remote repository supporting all the features of GraphDB and then stack upon it the SpinSail component?

As of the moment GraphDB (version 8.10.0) does not support SpinSail. Such option is under consideration for one of the next GraphDB releases.

Related

SPARQLRule not constructing

I have a Nodeshape with a sh:SPARQLTarget and a sh:SPARQLRule. I tried to run both Target and Rule as Queries and both deliver results, but when I'm executing the Shapes with the Apache Jena SHACL Processor, it won't construct any triples. Did I do something wrong? I'm out of ideas.
Here is my Nodeshape:
iep:hasKG331
a rdf:Property, sh:NodeShape ;
sh:Target [
a sh:SPARQLTarget ;
sh:select """
PREFIX express: <https://w3id.org/express#>
PREFIX ifcowl: <http://standards.buildingsmart.org/IFC/DEV/IFC4/ADD1/OWL#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX iep: <https://www.inf.bi.rub.de/semweb/ns/ifc-enrichment-procedure/iep#>
SELECT ?this
WHERE {
?this rdf:type ifcowl:IfcWallStandardCase .
?relDefinesByProperties ifcowl:relatedObjects_IfcRelDefines ?this .
?relDefinesByProperties ifcowl:relatingPropertyDefinition_IfcRelDefinesByProperties ?pset .
}
""" ;
] ;
sh:rule [
a sh:SPARQLRule ;
sh:construct """
PREFIX express: <https://w3id.org/express#>
PREFIX ifcowl: <http://standards.buildingsmart.org/IFC/DEV/IFC4/ADD1/OWL#>
PREFIX iep: <xxx/ifc-enrichment-procedure/iep#>
CONSTRUCT {
$this iep:hasKG iep:hasKG331 .
}
WHERE {
?relDBP ifcowl:relatedObjects_IfcRelDefines $this .
?relDBP ifcowl:relatingPropertyDefinition_IfcRelDefinesByProperties ?propSet .
?propSet ifcowl:hasProperties_IfcPropertySet ?psv1 .
?propSet ifcowl:hasProperties_IfcPropertySet ?psv2 .
?psv1 iep:isExternal true .
?psv2 iep:isLoadBearing true .
}
""" ;
] .
As I mentioned, when I execute the Target or the Rule as single queries, I do get results and the Focus Nodes from the Target do come up as $this in the Rule. The IRIs iep:isExternal and iep:isLoadBearing got inferenced in a step before. Am I missing something?
Without looking at details, the sh:Target needs to be sh:target with lower-case t. All property names are typically lower-case.

rewrite OWL class expression as SPARQL query?

I have been familiarizing myself with AKSW's https://github.com/SmartDataAnalytics/OWL2SPARQL, which is pretty easy to use, even with Scala and sbt, but doesn't rewrite Class Expressions.
I (and at least one other person!) would find class expression -> SPARQL rewriting helpful. Maybe that's because I (at least) make punning statements? For example, I need to find all drug prescription individuals that mention any drug tablet class that (indirectly) has the chemical 'rosuvastatin' as an active ingredient
:X a 'drug prescription' .
:X mentions 'rosuvastatin Oral Tablet' .
where
'drug prescription' is http://purl.obolibrary.org/obo/PDRO_0000024
mentions is http://purl.obolibrary.org/obo/IAO_0000142
'rosuvastatin Oral Tablet' is http://purl.obolibrary.org/obo/DRON_00027869
Superclasses & Asserted Axioms for 'rosuvastatin Oral Tablet':
drug tablet
has_proper_part some (scattered molecular aggregate and
(is bearer of some active ingredient) and
(has granular part some rosuvastatin))
where rosuvastatin is http://purl.obolibrary.org/obo/DRON_00018679 (and the other IRIs can be seen in RDF/XML context at http://www.ontobee.org/ontology/rdf/DRON?iri=http://purl.obolibrary.org/obo/DRON_00027869)
Are there other tools that can rewrite an OWL Class Expression as a SPARQL query?
If not, I guess I might write a property chain shortcut... but that disregards the types of classes involved in the chain, right?
I have an example at https://github.com/turbomam/owl2sparql4turbo
AKSW added the functionality I requested and gave me some good tips about using the OWL API. My bridge from a Java stream to a Scala stream may be a little kludgy.
Clone https://github.com/turbomam/owl2sparql4turbo to see how I set up build.sbt to import dependencies.
Ontology rots.owl includes the axioms like these (in Manchester notation... RDF/XML or Turtle would be OK, too):
Class: obo:DRON_00027869
Annotations:
rdfs:label "rosuvastatin Oral Tablet"^^xsd:string,
obo:DRON_00010000 "402354"^^xsd:string
SubClassOf:
obo:DRON_00000022,
<http://www.obofoundry.org/ro/ro.owl#has_proper_part> some
(obo:OBI_0000576
and (obo:BFO_0000053 some obo:DRON_00000028)
and (obo:BFO_0000071 some obo:DRON_00018679))
Run through https://github.com/turbomam/owl2sparql4turbo/blob/master/src/main/scala/ROTS.scala...
import java.io.File
import scala.compat.java8.StreamConverters.RichStream
import org.aksw.owl2sparql.OWLClassExpressionToSPARQLSubClassQueryConverter
import org.semanticweb.owlapi.apibinding.OWLManager
import org.semanticweb.owlapi.model.IRI
import org.semanticweb.owlapi.search.EntitySearcher
object ROTS {
// SPARQL searches for Rosuvastatin Oral Tablet classes
def main(args: Array[String]): Unit = {
var manager = OWLManager.createOWLOntologyManager()
var ontology = manager.loadOntologyFromOntologyDocument(new File("rots.owl"))
// use a factory to convert stings to IRI objects
var factory = manager.getOWLDataFactory()
var termIRI = IRI.create("http://purl.obolibrary.org/obo/DRON_00081385")
var someClass = factory.getOWLClass(termIRI)
var classSupers = EntitySearcher.getSuperClasses(someClass, ontology).toScala[Stream]
var oneSuper = classSupers(0)
var scConverter = new OWLClassExpressionToSPARQLSubClassQueryConverter()
var targetVar = "?x"
var queryStr = scConverter.convert(oneSuper, targetVar)
println(queryStr)
}
}
generates the output:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT ?x WHERE { ?x rdf:type owl:Class ;
rdfs:subClassOf [ rdf:type owl:Restriction ;
owl:onProperty <http://www.obofoundry.org/ro/ro.owl#has_proper_part> ;
owl:someValuesFrom [ owl:intersectionOf ( <http://purl.obolibrary.org/obo/OBI_0000576>
[ rdf:type owl:Restriction ;
owl:onProperty <http://purl.obolibrary.org/obo/BFO_0000053> ;
owl:someValuesFrom <http://purl.obolibrary.org/obo/DRON_00000029>
]
[ rdf:type owl:Restriction ;
owl:onProperty <http://purl.obolibrary.org/obo/BFO_0000071> ;
owl:someValuesFrom <http://purl.obolibrary.org/obo/CHEBI_30618>
]
) ;
rdf:type owl:Class
]
] .
}

Fuseki SPARQL INSERT produces the "Error 400: SPARQL Query: No 'query=' parameter"

I try to insert an individual into my ontology, but get the error:
Error 400: SPARQL Query: No 'query=' parameter
Fuseki - version 2.4.1 (Build date: 2016-11-04T18:59:20+0000)
This is my SPARQL INSERT query #1:
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 oo: <http://www.test.com/test-ontology.owl#>
INSERT {
oo:cap_123 rdf:type oo:MyTours .
oo:cap_123 oo:active true .
oo:cap_123 oo:title 'Text text text' .
}
WHERE {
FILTER NOT EXISTS { oo:cap_123 rdf:type oo:MyTours .
}
}
And this is my INSERT query #2:
INSERT DATA {
oo:cap_123 rdf:type oo:MyTours .
oo:cap_123 oo:active true .
oo:cap_123 oo:title 'Text text text' .
}
If I insert the individual using Protégé, then it works and saves the result as follows:
<owl:NamedIndividual rdf:about="http://www.test.com/test-ontology.owl#cap_123">
<rdf:type rdf:resource="http://www.test.com/test-ontology.owl#MyTours"/>
<active rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</active>
<title>Text text text</title>
</owl:NamedIndividual>
Both queries fail. What is wrong with them?
What is your SPARQL endpoint address? It should end with /update (instead of /query):
Available services are listed on http://example.com/dataset.html?tab=info&ds=/<dataset_name>:
Configuration file is %FUSEKI_HOME%/run/configuration/<dataset_name>.ttl
Access might be restricted in %FUSEKI_HOME%/run/shiro.ini

SPARQL INSERT not working with PUT method. why?

I am trying to create a new object with PUT method and to add some of my own prefixes with SPARQL query. But, the object is being created without the added prefixes. It works with POST and PATCH though. Why and is there alternative way for SPARQL to use with PUT method and add using user-defined prefixes?
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>
DELETE { }
INSERT {
<> indexing:hasIndexingTransformation "default";
rdf:type indexing:Indexable;
dc:title "title3";
dc:identifier "test:10";
}
WHERE { }
What I am saying was all the above values specified in the insert clause are not added at all.
EDIT1:
url = 'http://example.com/rest/object1'
payload = """
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>
PREFIX custom: <http://customnamespaces/custom#/>
DELETE { }
INSERT {
<> indexing:hasIndexingTransformation "default";
rdf:type indexing:Indexable;
dc:title "title1";
custom:objState "Active";
custom:ownerId "Owner1";
dc:identifier "object1";
}
WHERE { }
"""
headers = {
'content-type': "application/sparql-update",
'cache-control': "no-cache"
}
response = requests.request("PUT", url, data=payload, headers=headers, auth=('username','password'))
Prefixes are not triples and therefore cannot be added using a SPARQL query. You can always specify prefixes in the SPARQL query and it will generate the correct URI for storage in your triple store.
Also note that your custom namespace is errantly defined by ending with both a hash and a slash. It should be either PREFIX custom: <http://customnamespaces/custom#> or PREFIX custom: <http://customnamespaces/custom/>.
I.e. by your query indexing:hasIndexingTransformation will be stored in the triple store as <http://fedora.info/definitions/v4/indexing#hasIndexingTransformation>.
There is no reason to store the prefix in the triple store (actually, prefixes are an artifact of the text serialization, not the data itself), so you can subsequently query this data in one of two ways.
1) Using a prefix
PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>
SELECT ?o {
[] indexing:hasIndexingTransformation ?o .
}
2) Using the full URI:
SELECT ?o {
[] <http://fedora.info/definitions/v4/indexing#hasIndexingTransformation> ?o .
}

SPARQL DELETE: not possible in jena/pellet?

I am working on ontology reconciliation between two ontologies. I apply the jena/pellet platform, locally, and apply sparql rules as much as possible. For inserts this is successful, for deletes it is not, no matter what I try. This raises the question whether sparql deletes are supported at all with jena/pellet. Please advise!
Please find the related code snippets below. First the code, then the sparql DELETE query.
public void executeDelete(String mySparqlFile, OntModel o ) {
UpdateRequest updateObj = null;
UpdateProcessor up = null;
GraphStore graphStore = GraphStoreFactory.create();
graphStore.setDefaultGraph( o.getGraph() );
updateObj = UpdateFactory.read( mySparqlFile );
up = UpdateExecutionFactory.create(updateObj, graphStore);
up.execute();
}
public static void main() {
static OntModel ontModel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC, rawModel);
static OntModel stanfordModel = ModelFactory.createOntologyModel(PelletReasonerFactory.THE_SPEC);
stanfordModel.read("path/to/modelA.owl");
ontModel.addSubModel(stanfordModel);
executeDelete("path/to/delQuery.sparql", ontModel);
}
the file "delQuery.sparql"
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#>
PREFIX stfd: <http://www.semanticweb.org/brandtp/ontologies/2014/6/Goose-stanford-metamodel.owl#>
DELETE { ?c a stfd:Token . }
WHERE {
?c stfd:hasFeature stfd:Determiner .
}