Page MenuHomePhabricator

Unresolved prefixed name in SPARQL Query
Closed, ResolvedPublic

Description

Author: icarnevale

Description:
Installed software

  • MediaWiki 1.18.0 (r525)
  • Semantic MediaWiki (Version 1.6.1) (r525)

I use SMW whit Joseki as default store.
The configuration in my LocalSettings.php is the following

$smwgDefaultStore = 'SMWSparqlStore';
$smwgSparqlQueryEndpoint = 'http://localhost:8080/joseki/sparql';
$smwgSparqlUpdateEndpoint = 'http://localhost:8080/joseki/update/service';
$smwgSparqlDataEndpoint = ''; # optional location of SPARQL over HTTP service

i have this error on browser while generating SPARQL DELETE query:

Unexpected non-MediaWiki exception encountered, of type "SMWSparqlDatabaseError"

		exception 'SMWSparqlDatabaseError' with message 'A SPARQL query error has occurred
		Query: PREFIX wiki: <http://unbreakable.local/mediawiki/index.php/Special:URIResolver/>
		PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
		PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
		PREFIX owl: <http://www.w3.org/2002/07/owl#>
		PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
		PREFIX property: <http://unbreakable.local/mediawiki/index.php/Special:URIResolver/Property-3A>
		PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
		DELETE { ?s ?p ?o } WHERE { ?s swivt:masterPage state-instances:business_service-609 . ?s ?p ?o }
		Error: Query refused
		Endpoint: http://localhost:8080/joseki/update/service
		HTTP response code: 500
		' in /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php:533
		Stack trace:
		#0 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php(446): SMWSparqlDatabase->throwSparqlErrors('http://localhos...', 'PREFIX wiki: <h...')
		#1 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php(317): SMWSparqlDatabase->doUpdate('PREFIX wiki: <h...')
		#2 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php(337): SMWSparqlDatabase->delete('?s ?p ?o', '?s swivt:master...', Array)
		#3 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStore.php(261): SMWSparqlDatabase->deleteContentByValue('swivt:masterPag...', 'state-instances...')
		#4 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStore.php(66): SMWSparqlStore->deleteSparqlData(Object(SMWExpNsResource))
		#5 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php(303): SMWSparqlStore->doDataUpdate(Object(SMWSemanticData))
		#6 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/SMW_ParseData.php(267): SMWStore->updateData(Object(SMWSemanticData))
		#7 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/jobs/SMW_UpdateJob.php(65): SMWParseData::storeData(Object(ParserOutput), Object(Title), false)
		#8 /Evoluzione02/mediawiki/includes/Wiki.php(411): SMWUpdateJob->run()
		#9 /Evoluzione02/mediawiki/includes/Wiki.php(385): MediaWiki->doJobs()
		#10 /Evoluzione02/mediawiki/includes/Wiki.php(627): MediaWiki->finalCleanup()
		#11 /Evoluzione02/mediawiki/includes/Wiki.php(533): MediaWiki->main()
		#12 /Evoluzione02/mediawiki/index.php(57): MediaWiki->run()
		#13 {main}

		#0 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php(446): SMWSparqlDatabase->throwSparqlErrors('http://localhos...', 'PREFIX wiki: <h...')
		#1 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php(317): SMWSparqlDatabase->doUpdate('PREFIX wiki: <h...')
		#2 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/sparql/SMW_SparqlDatabase.php(337): SMWSparqlDatabase->delete('?s ?p ?o', '?s swivt:master...', Array)
		#3 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStore.php(261): SMWSparqlDatabase->deleteContentByValue('swivt:masterPag...', 'state-instances...')
		#4 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_SparqlStore.php(66): SMWSparqlStore->deleteSparqlData(Object(SMWExpNsResource))
		#5 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php(303): SMWSparqlStore->doDataUpdate(Object(SMWSemanticData))
		#6 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/SMW_ParseData.php(267): SMWStore->updateData(Object(SMWSemanticData))
		#7 /Evoluzione02/mediawiki/extensions/SemanticMediaWiki/includes/jobs/SMW_UpdateJob.php(65): SMWParseData::storeData(Object(ParserOutput), Object(Title), false)
		#8 /Evoluzione02/mediawiki/includes/Wiki.php(411): SMWUpdateJob->run()
		#9 /Evoluzione02/mediawiki/includes/Wiki.php(385): MediaWiki->doJobs()
		#10 /Evoluzione02/mediawiki/includes/Wiki.php(627): MediaWiki->finalCleanup()
		#11 /Evoluzione02/mediawiki/includes/Wiki.php(533): MediaWiki->main()
		#12 /Evoluzione02/mediawiki/index.php(57): MediaWiki->run()
		#13 {main}

On Joseki log i have:

PREFIX wiki: http://unbreakable.local/mediawiki/index.php/Special:URIResolver/

		PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
		PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
		PREFIX owl: <http://www.w3.org/2002/07/owl#>
		PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
		PREFIX property: <http://unbreakable.local/mediawiki/index.php/Special:URIResolver/Property-3A>
		PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
		DELETE { ?s ?p ?o } WHERE { ?s swivt:masterPage state-instances:business_service-609 . ?s ?p ?o }"
		 WARN [http-bio-8080-exec-7] (ProcessorBase.java:153) - Internal error - unexpected exception: 
		com.hp.hpl.jena.query.QueryParseException: Line 8, column 49: Unresolved prefixed name: state-instances:business_service-609
			at com.hp.hpl.jena.sparql.lang.ParserBase.throwParseException(ParserBase.java:538)
			at com.hp.hpl.jena.sparql.lang.ParserBase.resolvePName(ParserBase.java:237)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.PrefixedName(ARQParser.java:4958)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.IRIref(ARQParser.java:4942)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GraphTerm(ARQParser.java:3503)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.VarOrTerm(ARQParser.java:3445)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GraphNode(ARQParser.java:3401)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Object(ARQParser.java:2793)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.ObjectList(ARQParser.java:2774)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.PropertyListNotEmptyPath(ARQParser.java:2885)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.TriplesSameSubjectPath(ARQParser.java:2849)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.TriplesBlock(ARQParser.java:2230)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GroupGraphPatternSub(ARQParser.java:2135)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GroupGraphPattern(ARQParser.java:2097)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Modify(ARQParser.java:1693)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Update1(ARQParser.java:1450)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Update(ARQParser.java:1379)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.UpdateUnit(ARQParser.java:1369)
			at com.hp.hpl.jena.sparql.lang.ParserARQUpdate._parse(ParserARQUpdate.java:54)
			at com.hp.hpl.jena.sparql.lang.ParserARQUpdate.parse(ParserARQUpdate.java:45)
			at org.joseki.processors.SPARQLUpdate.execOperation(SPARQLUpdate.java:78)
			at org.joseki.processors.ProcessorBase.exec(ProcessorBase.java:136)
			at org.joseki.ServiceRequest.exec(ServiceRequest.java:36)
			at org.joseki.Dispatcher.dispatch(Dispatcher.java:59)
			at org.joseki.http.Servlet.doCommon(Servlet.java:178)
			at org.joseki.http.ServletUpdate.doPost(ServletUpdate.java:39)
			at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
			at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
			at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
			at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
			at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
			at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
			at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
			at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
			at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
			at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
			at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
			at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
			at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
			at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
			at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
			at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
			at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
			at java.lang.Thread.run(Thread.java:722)
		 WARN [http-bio-8080-exec-7] (Servlet.java:183) - Internal server error
		com.hp.hpl.jena.query.QueryParseException: Line 8, column 49: Unresolved prefixed name: state-instances:business_service-609
			at com.hp.hpl.jena.sparql.lang.ParserBase.throwParseException(ParserBase.java:538)
			at com.hp.hpl.jena.sparql.lang.ParserBase.resolvePName(ParserBase.java:237)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.PrefixedName(ARQParser.java:4958)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.IRIref(ARQParser.java:4942)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GraphTerm(ARQParser.java:3503)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.VarOrTerm(ARQParser.java:3445)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GraphNode(ARQParser.java:3401)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Object(ARQParser.java:2793)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.ObjectList(ARQParser.java:2774)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.PropertyListNotEmptyPath(ARQParser.java:2885)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.TriplesSameSubjectPath(ARQParser.java:2849)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.TriplesBlock(ARQParser.java:2230)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GroupGraphPatternSub(ARQParser.java:2135)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.GroupGraphPattern(ARQParser.java:2097)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Modify(ARQParser.java:1693)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Update1(ARQParser.java:1450)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.Update(ARQParser.java:1379)
			at com.hp.hpl.jena.sparql.lang.arq.ARQParser.UpdateUnit(ARQParser.java:1369)
			at com.hp.hpl.jena.sparql.lang.ParserARQUpdate._parse(ParserARQUpdate.java:54)
			at com.hp.hpl.jena.sparql.lang.ParserARQUpdate.parse(ParserARQUpdate.java:45)
			at org.joseki.processors.SPARQLUpdate.execOperation(SPARQLUpdate.java:78)
			at org.joseki.processors.ProcessorBase.exec(ProcessorBase.java:136)
			at org.joseki.ServiceRequest.exec(ServiceRequest.java:36)
			at org.joseki.Dispatcher.dispatch(Dispatcher.java:59)
			at org.joseki.http.Servlet.doCommon(Servlet.java:178)
			at org.joseki.http.ServletUpdate.doPost(ServletUpdate.java:39)
			at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
			at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
			at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
			at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
			at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
			at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
			at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:581)
			at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
			at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
			at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
			at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
			at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
			at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
			at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
			at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
			at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
			at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
			at java.lang.Thread.run(Thread.java:722)

The problem is that in the PREFIX list i don't have the "state-instances" prefix.

In SMW_SparqlDatabase.php the method
public function delete( $deletePattern, $where, $extraNamespaces = array() )
"extraNamespaces" that is an array (associative) of namespaceId => namespaceUri,
and it contains prefix different from wiki, swivt, rdf, owl, rdfs, property, xsd.

The method
SMW_SparqlStore.php:deleteSparqlData( SMWExpResource $expResource )
invoke SMW_SparqlDatabase.php:delete like

smwfGetSparqlDatabase()->delete( "$resourceUri ?p ?o", "$resourceUri ?p ?o" );

and "extraNamespaces" isn't in the parameters list.

Solution:

  1. Fill extraNamespaces int he following way

$extraNamespaces = array();
$extraNamespaces[$expResource->getNamespaceId()]=$expResource->getNamespace();

  1. Pass the filled array to SMW_SparqlDatabase.php:delete method like

smwfGetSparqlDatabase()->delete( "$resourceUri ?p ?o", "$resourceUri ?p ?o", $extraNamespaces );

and the result is

/**

  • Delete from the SPARQL database all data that is associated with the
  • given resource. *
  • @param $expResource SMWExpResource
  • @return boolean success */

protected function deleteSparqlData( SMWExpResource $expResource ) {

$resourceUri = SMWTurtleSerializer::getTurtleNameForExpElement( $expResource );
$masterPageProperty = SMWExporter::getSpecialNsResource( 'swivt', 'masterPage' );
$masterPagePropertyUri = SMWTurtleSerializer::getTurtleNameForExpElement( $masterPageProperty );
$extraNamespaces = array();
$extraNamespaces[$expResource->getNamespaceId()]=$expResource->getNamespace();
$success = smwfGetSparqlDatabase()->deleteContentByValue( $masterPagePropertyUri, $resourceUri, $extraNamespaces );
if ( $success ) {
        return smwfGetSparqlDatabase()->delete( "$resourceUri ?p ?o", "$resourceUri ?p ?o", $extraNamespaces );
} else {
        return false;
}

}


Version: unspecified
Severity: blocker

Details

Reference
bz33687

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:09 AM
bzimport set Reference to bz33687.
bzimport added a subscriber: Unknown Object (MLST).
bzimport created this task.Jan 12 2012, 5:12 PM

Thanks for the detailed report. Fixed in r111243 in the way you suggested.

As a side remark (not related to this bug, but maybe a new bug/request ...), I note that custom URIs will not work well with the SPARQL backend in general. You should not be able to retrieve pages with custom URIs (using "vocabulary import") in #ask queries, since SMW has no way of translating custom URIs (retrieved by SPARQL) back into wiki pages. Anyway, custom URIs should still not lead to critical errors, so it is good that this bug is fixed now.