Extension talk:SparqlExtension

Magic word 'twinkle' not found
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...')
 * 1) 10 G:\xampp\htdocs\wiki\includes\OutputPage.php(325): wfMsg
 * 2) 11 G:\xampp\htdocs\wiki\includes\SpecialPage.php(750): OutputPage->setPageTitle('pagetitle', true, false, true)
 * 3) 12 G:\xampp\htdocs\wiki\extensions\SparqlExtension\SparqlExtension_body.php(47): SpecialPage->setHeaders('pagetitle', Array, true)
 * 4) 13 G:\xampp\htdocs\wiki\includes\SpecialPage.php(559): SparqlExtension->execute('pagetitle', 'SparqlExtension')
 * 5) 14 G:\xampp\htdocs\wiki\includes\Wiki.php(229): SpecialPage::executePath('SparqlExtension')
 * 6) 15 G:\xampp\htdocs\wiki\includes\Wiki.php(59): MediaWiki->initializeSpecialCases
 * 7) 16 G:\xampp\htdocs\wiki\index.php(116): MediaWiki->initialize(NULL)
 * 8) 17 {main}

My components and versions
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
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 2. locate 3. locate the lines: 4. Replace them with the following lines: 5. Pat yourself on the back.

Cheers,

LyleC. 8th November 2010 lyle_chamarette at hotmail dot com

Alternative solution
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 2. locate 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  lines from step 3 below the line that starts with. This part now reads: //setup function $wgExtensionFunctions[] = "Sparql_Setup"; $wgHooks["ParserFirstCallInit"][] = "Sparql_ParserFunctionSetup"; $wgHooks['LanguageGetMagic'][]   = "Sparql_ParserFunctionMagic"; Rcdeboer 10:17, 19 November 2010 (UTC)


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

7. Replace in     $parser->setFunctionHook("sparqlencode", "Sparql_SparqlEncode", SFH_NO_HASH); by $parser->setFunctionHook("sparqlencode", "Sparql_SparqlEncode"); --F.trott 10:46, 13 December 2010 (UTC)

Thank you
thank you, thank you!
 * 68.224.44.77 02:50, 25 August 2010 (UTC)

Import triples (Update facts in wiki articles) column in comparison table
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)

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)

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)

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)

PHP warning: Invalid argument supplied for foreach in SparqlUtil line ..
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)