Extension talk:SparqlExtension

From mediawiki.org
Latest comment: 7 years ago by Bouzinac in topic Airport lookup sparql code

Removed 'obsolete' notice[edit]

I just removed the obsolete notice for this extension. From discussions on the smw development mailing list, I realized that the SparqlExtension still has functionality not included in the core SMW code. For SMW 1.6+, we do need to make some upgrades to the code to get it working with that version. Mr3641 09:11, 7 September 2011 (UTC)Reply

Magic word 'twinkle' not found[edit]

I am getting the above error when trying to add Extension:SparqlExtension into my wiki. Following is the backtrace:

Backtrace:

#0 G:\xampp\htdocs\wiki\includes\MagicWord.php(257): Language->getMagic(Object(MagicWord))
#1 G:\xampp\htdocs\wiki\includes\MagicWord.php(206): MagicWord->load('twinkle')
#2 G:\xampp\htdocs\wiki\includes\parser\Parser.php(4039): MagicWord::get('twinkle')
#3 G:\xampp\htdocs\wiki\extensions\SparqlExtension\SparqlExtension.php(86): Parser->setFunctionHook('twinkle', 'Sparql_ParserFu...')
#4 G:\xampp\htdocs\wiki\includes\Hooks.php(117): Sparql_ParserFunctionSetup(Object(Parser))
#5 G:\xampp\htdocs\wiki\includes\parser\Parser.php(178): wfRunHooks()
#6 G:\xampp\htdocs\wiki\includes\MessageCache.php(659): Parser->firstCallInit('Sparql_ParserFu...', Array)
#7 G:\xampp\htdocs\wiki\includes\GlobalFunctions.php(600): MessageCache->transform('ParserFirstCall...', Array)
#8 G:\xampp\htdocs\wiki\includes\GlobalFunctions.php(563): wfMsgGetKey()
#9 G:\xampp\htdocs\wiki\includes\GlobalFunctions.php(469): wfMsgReal('$1 - {{SITENAME...')
#10 G:\xampp\htdocs\wiki\includes\OutputPage.php(325): wfMsg()
#11 G:\xampp\htdocs\wiki\includes\SpecialPage.php(750): OutputPage->setPageTitle('pagetitle', true, false, true)
#12 G:\xampp\htdocs\wiki\extensions\SparqlExtension\SparqlExtension_body.php(47): SpecialPage->setHeaders('pagetitle', Array, true)
#13 G:\xampp\htdocs\wiki\includes\SpecialPage.php(559): SparqlExtension->execute('pagetitle', 'SparqlExtension')
#14 G:\xampp\htdocs\wiki\includes\Wiki.php(229): SpecialPage::executePath('SparqlExtension')
#15 G:\xampp\htdocs\wiki\includes\Wiki.php(59): MediaWiki->initializeSpecialCases()
#16 G:\xampp\htdocs\wiki\index.php(116): MediaWiki->initialize(NULL)
#17 {main}

My components and versions[edit]

MediaWiki 1.15.1
PHP 5.2.8 (apache2handler)
MySQL 5.1.30-community
Data Import Extension (Version 1.4.0_3)
ScriptManager Extension (Version 1.0.0_0)
Semantic MediaWiki (Version 1.5.1_1)
SMWHalo Extension (Version 1.5.1_4-for-SMW-1.5.1 [B36])
IAI (Version 0.1)
Semantic Gardening extension v1.3.2_1

Solution[edit]

Turns out the problem was related to the way that SparqlExtension v0.7 hooks into SMW...

Here is what I needed to do to make this work for me:

1. In the file ./extensions/SparqlExtension/SparqlExtension.php
2. locate function Sparql_Setup()
3. locate the lines:

    $wgHooks["ParserFirstCallInit"][] = "Sparql_ParserFunctionSetup";
    $wgHooks['LanguageGetMagic'][]    = "Sparql_ParserFunctionMagic";

4. Replace them with the following lines:

    global $wgParser;
    $wgParser->setHook("ParserFirstCallInit","Sparql_ParserFunctionSetup");
    $wgParser->setHook( "LanguageGetMagic", "Sparql_ParserFunctionMagic" );

5. Pat yourself on the back.

Cheers,

LyleC.
8th November 2010
lyle_chamarette at hotmail dot com

Alternative solution[edit]

Lyle, thanks a lot for your solution. I had to do this slightly differently, though, since the twinkle/sparql and sparqlencode parser functions were not registered. What I did:

1. In the file ./extensions/SparqlExtension/SparqlExtension.php
2. locate function Sparql_Setup()

3. locate the lines:

    $wgHooks["ParserFirstCallInit"][] = "Sparql_ParserFunctionSetup";
    $wgHooks['LanguageGetMagic'][]    = "Sparql_ParserFunctionMagic";

4. cut those two lines from the function

5. locate the lines

    //setup function
    $wgExtensionFunctions[] = "Sparql_Setup";

6. paste the two $wgHooks lines from step 3 below the line that starts with $wgExtensionFunctions[]. This part now reads:

    //setup function
    $wgExtensionFunctions[] = "Sparql_Setup";
    $wgHooks["ParserFirstCallInit"][] = "Sparql_ParserFunctionSetup";
    $wgHooks['LanguageGetMagic'][]    = "Sparql_ParserFunctionMagic";

Rcdeboer 10:17, 19 November 2010 (UTC)Reply


The alternative solution worked for me. Thanks!
To also get sparqlencode to work I had to

7. Replace in function Sparql_ParserFunctionSetup()

   $parser->setFunctionHook("sparqlencode", "Sparql_SparqlEncode", SFH_NO_HASH);

by

   $parser->setFunctionHook("sparqlencode", "Sparql_SparqlEncode");

--F.trott 10:46, 13 December 2010 (UTC)Reply

Thank you[edit]

thank you, thank you!

68.224.44.77 02:50, 25 August 2010 (UTC)Reply

Import triples (Update facts in wiki articles) column in comparison table[edit]

Hi Alfredas!

Nice that you are mentioning RDFIO in the comparison! What would you think about adding a column for "Enable writing to wiki", "RDF Import" or similar, which is the main motivation behind RDFIO, which allows updating wiki articles from the SPARQL endpoint. (Technically this is done via Denny's SMWWriter extension)? :) Otherwise SparqlExtension seems to be great for data integrations, so I'll be looking into it for one of my current projects.

Best Regards
--SHL 18:29, 10 September 2010 (UTC)Reply

Hey Samuel,

feel free to add any columns to the table. I've discussed with the SMW crew to move the comparison to the SMW SPARQL page - so I think it should be as objective and informing as possible.

--Alfredas 13:03, 13 September 2010 (UTC)Reply

Ok! Have added a new feature now: "Import triples (Update facts in wiki articles)". Feel free to adjust it if you like.

--SHL 21:22, 14 September 2010 (UTC)Reply

Thank you Alfredas for this fantastic extension. Just what I have been waiting for! Keep up the excellent work, Matt. --192.93.164.28 08:36, 12 November 2010 (UTC)Reply

PHP warning: Invalid argument supplied for foreach() in SparqlUtil line ..[edit]

Query results containing bad characters were breaking the json_decode on line 41 of SparqlUtil.php, and causing invalid arguments to be passed to the subsequent foreach loops. I recommend the following patch to protect yourself from having PHP Warnings thrown on your page:

1. In ./extensions/SparqlExtension/SparqlUtil.php

2. Find the following lines (@42-45):

 $fields = $json["head"]["vars"];
 $results = $json["results"]["bindings"];
 $res = array();
 foreach ($results as $result) {
    ...

3. And force the results to an array by inserting the following two lines (marked with a +):

  $fields = $json["head"]["vars"];
  $results = $json["results"]["bindings"];
  $res = array();
+ $fields = is_array($fields)? $fields : array($fields);
+ $results = is_array($results)? $results : array($results);
  foreach ($results as $result) {
     ...

It won't clean up the bad input or display the missing results from your corrupted sparql query, but it will prevent PHP Warnings from appearing on your pages.

Jweers 16:23, 18 April 2011 (UTC)Reply

Does this extension work with fuseki?[edit]

I know joseki has been replaced with fuseki. Please let me know if this extension is being maintained still.

Airport lookup sparql code[edit]

Hello, i've found out how to look for Wikipedia article for an XXX airport

SELECT ?item ?itemLabel ?_Officiel ?_Court ?_AITA WHERE {
  ?item wdt:P31 wd:Q1248784.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "fr,en".
    ?item rdfs:label ?itemLabel.
  }
  OPTIONAL {
    ?item wdt:P1448 ?_Officiel.
    ?item wdt:P1813 ?_Court.
    ?item wdt:P238 ?_AITA.
  }
  FILTER(UCASE(?_AITA)= "AUR")
}
LIMIT 1

.

[1]
This code looks to run ok but how to embed this into a wikipage?template? Thanks! --Bouzinac (talk) 21:15, 3 July 2016 (UTC)Reply