SemanticMediaWiki
SemanticMediaWiki copied to clipboard
Imported_from seems to break ask-queries with SPARQL-backend
Setup
- SMW version: 4.1.1 (also tested: 3.2.3)
- MW version: 1.39.3 (also tested: 1.35.7)
- PHP version: 7.4.33 (also tested: 8.1)
- DB system (MySQL, Blazegraph, etc.) and version: MySQL 8.0.17, Blazegraph 2.1.5
Issue
[[Imported from::...]] statements seem to break ask-queries when a SPARQL-backend is used.
I asume this is due to the change from the local IRI (/id/
Steps to reproduce the observation:
- Create a page with an
[[Imported from::foaf:Person]]statement, e. g. ImportedFromTestPage - Query for that page with
[[Imported_from::foaf:Person]], e. g. https://demo.open-semantic-lab.org/w/api.php?action=ask&query=[[Imported_from::foaf:Person]] - Result is empty while in the sandbox instance it works as expected
Update:
The test query above works after purging the page and the iri replacement within the SPARQL query seems fine, so category:ImportedFromTestPage gets replaced with foaf:Person
But when I set the displaytitle to ImportedFromTestPageDisplayTitle with {{DISPLAYTITLE: ImportedFromTestPageDisplayTitle}}, the query https://demo.open-semantic-lab.org/w/api.php?action=ask&query=[[:Category:ImportedFromTestPage]]|?Imported_from returns
"results": {
"Category:ImportedFromTestPageDisplayTitle": {
"printouts": {
"Imported from": []
},
"fulltext": "Category:ImportedFromTestPageDisplayTitle",
"fullurl": "https://demo.open-semantic-lab.org/wiki/Category:ImportedFromTestPageDisplayTitle",
"namespace": 14,
"exists": "",
"displaytitle": ""
}
},
so the actual title gets replaced with the display title and fulltext points to a non-existing page which leads to errors in any consumer.
Sandbox works fine: https://sandbox.semantic-mediawiki.net/w/api.php?action=ask&query=[[Imported_from::foaf:Person]]|?Imported_from
Looking at the logs it looks like the actual title gets replaced in the SQL queries by the display title after the SPARQL query was executet:
SMW\SQLStore\EntityStore\EntityIdFinder::fetchFromTableByTitle [0.001s] db: SELECT ... WHERE smw_title = 'ImportedFromTestPage' ...
SMW\SPARQLStore\QueryEngine\ConditionBuilder ...
SMW\SQLStore\EntityStore\EntityIdFinder::fetchFromTableByTitle [0.001s] db: SELECT ... WHERE smw_title = 'ImportedFromTestPageDisplayTitle' ...
Update:
The actual errors occurs here for self-queries (e. g. [[{{FULLPAGENAME}}]] ):
rdfs:label, which holds the display title, is used as DB_KEY, resulting in an invalid dataItem. Instead swivt:page (after removing / spliting at $wgArticlePath + namespace, e. g. Category-3A) or rdfs:isDefinedBy (after removing / spliting at Special:ExportRDF/ + namespace, e. g. Category-3A) should be used.
https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/13c7bbe896abd188fb206c941da58b224b40cf37/src/Exporter/DataItemMatchFinder.php#L136-L163
But since the ExpElement passed to matchExpElement() e. g.
{"options":null,"value":"ImportedFromTestPage#14##","_type_":"SMW\\DIWikiPage","sortkey":null,"contextReference":null,"pageLanguage":null,"id":0}
already contains correct DB_KEY and namespace, a lookup in the triplestore is maybe not needed at all.
https://github.com/SemanticMediaWiki/SemanticMediaWiki/blob/13c7bbe896abd188fb206c941da58b224b40cf37/src/Exporter/DataItemMatchFinder.php#L52-L70