SemanticMediaWiki icon indicating copy to clipboard operation
SemanticMediaWiki copied to clipboard

Imported_from seems to break ask-queries with SPARQL-backend

Open simontaurus opened this issue 2 years ago • 2 comments

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/

) to the imported one (e. g. foaf:Person) as primary identifier. <p>Steps to reproduce the observation:</p> <ol> <li>Create a page with an <code>[[Imported from::foaf:Person]]</code> statement, e. g. <a href="https://demo.open-semantic-lab.org/wiki/Category:ImportedFromTestPage" rel="nofollow" target="_blank" >ImportedFromTestPage</a></li> <li>Query for that page with <code>[[Imported_from::foaf:Person]]</code>, e. g. <a href="https://demo.open-semantic-lab.org/w/api.php?action=ask&query=%5B%5BImported_from::foaf:Person%5D%5D" rel="nofollow" target="_blank" >https://demo.open-semantic-lab.org/w/api.php?action=ask&query=[[Imported_from::foaf:Person]]</a></li> <li>Result is empty while in the <a href="https://sandbox.semantic-mediawiki.net/wiki/Cat%C3%A9gorie:ImportedFromTestPage" rel="nofollow" target="_blank" >sandbox instance</a> it works as expected</li> </ol>

simontaurus avatar Sep 02 '23 10:09 simontaurus

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' ...

simontaurus avatar Sep 16 '23 11:09 simontaurus

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

simontaurus avatar Sep 17 '23 08:09 simontaurus