[SMW-devel] Ask query in extension
I'm creating a parser function in which I'm going to include an ask query. In this particular case I'd like it just return a normal HTML table of results, as if I were to do: {{#ask: [[Category:Some category]] |? Property 1 |? Property 2 | limit = 10 | sort = Property 2 }} Once I understand this I'll probably have cases where I need to modify the results of the query before passing it to a result formatter or formatting the results manually. What is the best way to do this using existing SMW methods? Thanks, James -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
Hey, So you'd have something like {{#gimmeh_datas_in_a_table: [[Category:Some category]]}} that results in the same output as the #ask call you posted? If that's all you're doing you can of course just use a template. Which indeed does not work if you want to modify the result in certain ways. Your parser function would hand the query string to the QueryProcessor, get back the result, and then hand the result over to the formatting thing (can't recall where this code is). And in between you could try modifying the result. Be warned though, the result data structure is... odd... So it might not be trivial to do this. Cheers -- Jeroen De Dauw - http://www.bn2vs.com Software craftsmanship advocate Evil software architect at Wikimedia Germany ~=[,,_,,]:3 -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
If your extension includes a JavaScript component, and you need to make the ask query in the JavaScript, SMW includes the ask query as an API module (action=ask or action=askargs, depending on what format you prefer to send in the query). -- Jason Ji jason.y...@gmail.com On Sat, Nov 1, 2014 at 8:38 PM, Jeroen De Dauw wrote: > Hey, > > So you'd have something like > > {{#gimmeh_datas_in_a_table: [[Category:Some category]]}} > > that results in the same output as the #ask call you posted? If that's all > you're doing you can of course just use a template. Which indeed does not > work if you want to modify the result in certain ways. > > Your parser function would hand the query string to the QueryProcessor, > get back the result, and then hand the result over to the formatting thing > (can't recall where this code is). And in between you could try modifying > the result. Be warned though, the result data structure is... odd... So it > might not be trivial to do this. > > Cheers > > -- > Jeroen De Dauw - http://www.bn2vs.com > Software craftsmanship advocate > Evil software architect at Wikimedia Germany > ~=[,,_,,]:3 > > > -- > > ___ > Semediawiki-devel mailing list > Semediawiki-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/semediawiki-devel > > -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
Hi James, you can try this, works fine in similar case for me: 1) Create the ask string in php like this: /$search = "{{#ask: }}";/ 2) Create the result string which you can manipulate later: $resultString = $parser->mStripState->unstripBoth($parser->recursiveTagParse( $/search/, $frame ),$parser->mStripState); Greetings Frank On 01.11.2014 19:18, James Montalvo wrote: I'm creating a parser function in which I'm going to include an ask query. In this particular case I'd like it just return a normal HTML table of results, as if I were to do: {{#ask: [[Category:Some category]] |? Property 1 |? Property 2 | limit = 10 | sort = Property 2 }} Once I understand this I'll probably have cases where I need to modify the results of the query before passing it to a result formatter or formatting the results manually. What is the best way to do this using existing SMW methods? Thanks, James -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
Hi James, I found this link some weeks ago: https://semantic-mediawiki.org/wiki/User:Yury_Katkov/programming_examples Even though Semantic Tasks is unmaintained, I found some piece of code that could inspire you as well: https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php Hope it helps, El 01/11/14 a les 19:18, James Montalvo ha escrit: > I'm creating a parser function in which I'm going to include an ask query. > In this particular case I'd like it just return a normal HTML table of > results, as if I were to do: > > {{#ask: [[Category:Some category]] > |? Property 1 > |? Property 2 > | limit = 10 > | sort = Property 2 > }} > > Once I understand this I'll probably have cases where I need to modify the > results of the query before passing it to a result formatter or formatting > the results manually. What is the best way to do this using existing SMW > methods? > > Thanks, > James > -- Toni Hermoso Pulido http://www.cau.cat http://www.similis.cc -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
Hi, > Even though Semantic Tasks is unmaintained, I found some piece of code > that could inspire you as well: > https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php Please try not follow these as general guideline because things like [0] will not work in 1.9 or 2.0* and is a rather odd practice to invoke the `QueryProcessor`. If you need examples on how to use a particular class or an integration scenario try to have a look at [1] and if you can't find an appropriate example then add a request to [2] with a clear description of a possible test example. [0] https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php#L321 [1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests [2] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/445 Cheers On 11/2/14, Toni Hermoso Pulido wrote: > Hi James, > > I found this link some weeks ago: > https://semantic-mediawiki.org/wiki/User:Yury_Katkov/programming_examples > > Even though Semantic Tasks is unmaintained, I found some piece of code > that could inspire you as well: > https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php > > Hope it helps, > > El 01/11/14 a les 19:18, James Montalvo ha escrit: >> I'm creating a parser function in which I'm going to include an ask >> query. >> In this particular case I'd like it just return a normal HTML table of >> results, as if I were to do: >> >> {{#ask: [[Category:Some category]] >> |? Property 1 >> |? Property 2 >> | limit = 10 >> | sort = Property 2 >> }} >> >> Once I understand this I'll probably have cases where I need to modify >> the >> results of the query before passing it to a result formatter or >> formatting >> the results manually. What is the best way to do this using existing SMW >> methods? >> >> Thanks, >> James >> > > -- > Toni Hermoso Pulido > http://www.cau.cat > http://www.similis.cc > > -- > ___ > Semediawiki-devel mailing list > Semediawiki-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/semediawiki-devel > -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
Thanks for the notes, James! El 02/11/14 a les 12:57, James HK ha escrit: > Hi, > >> Even though Semantic Tasks is unmaintained, I found some piece of code >> that could inspire you as well: >> https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php > > Please try not follow these as general guideline because things like > [0] will not work in 1.9 or 2.0* and is a rather odd practice to > invoke the `QueryProcessor`. > > If you need examples on how to use a particular class or an > integration scenario try to have a look at [1] and if you can't find > an appropriate example then add a request to [2] with a clear > description of a possible test example. > > [0] > https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php#L321 > > [1] https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests > > [2] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/445 > > Cheers > > On 11/2/14, Toni Hermoso Pulido wrote: >> Hi James, >> >> I found this link some weeks ago: >> https://semantic-mediawiki.org/wiki/User:Yury_Katkov/programming_examples >> >> Even though Semantic Tasks is unmaintained, I found some piece of code >> that could inspire you as well: >> https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php >> >> Hope it helps, >> >> El 01/11/14 a les 19:18, James Montalvo ha escrit: >>> I'm creating a parser function in which I'm going to include an ask >>> query. >>> In this particular case I'd like it just return a normal HTML table of >>> results, as if I were to do: >>> >>> {{#ask: [[Category:Some category]] >>> |? Property 1 >>> |? Property 2 >>> | limit = 10 >>> | sort = Property 2 >>> }} >>> >>> Once I understand this I'll probably have cases where I need to modify >>> the >>> results of the query before passing it to a result formatter or >>> formatting >>> the results manually. What is the best way to do this using existing SMW >>> methods? >>> -- Toni Hermoso Pulido http://www.cau.cat http://www.similis.cc -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
I spent a lot of time on Friday trying to figure out how to replicate an ask query in PHP. I was pretty sure I could do something to reuse the parser, but since I wanted to be able to manipulate the data before displaying it I did not pursue that method. Thank you, Frank, for the way you described. I'm sure that will come in handy in the future. I also spent some time messing around with QueryProcessor. I agree with Jeroen that the result data is odd, and I came to the conclusion that I must have been doing something wrong. This morning I looked at Yuri Katkov's examples provided by Toni [0], and as MWJames said they do not work with SMW 2.0. Below I have modified Yuri's "all pages with the property" example [1], and upon immediate inspection it appears to be working. I plan on modifying Yuri's more complex examples to work with SMW 2.0, but would like any input if I'm doing anything wrong here. Also I'll make the examples do something more interesting than print_r. // Perform query replicating {{#ask: [[Age::23]] }} $numberValue = new \SMWDINumber( 23 ); $queryDescription = new \SMWSomeProperty( new \SMW\DIProperty( 'Age' ), new \SMWValueDescription( $numberValue ) ); $query = new \SMWQuery( $queryDescription ); $store = \SMW\StoreFactory::getStore(); $result = $store->getQueryResult( $query ); print_r( $result->getResults() ); --James [0] https://semantic-mediawiki.org/wiki/User:Yury_Katkov/programming_examples [1] https://semantic-mediawiki.org/wiki/User:Yury_Katkov/programming_examples#All_pages_with_the_property On Sun, Nov 2, 2014 at 6:25 AM, Toni Hermoso Pulido wrote: > Thanks for the notes, James! > > El 02/11/14 a les 12:57, James HK ha escrit: > > Hi, > > > >> Even though Semantic Tasks is unmaintained, I found some piece of code > >> that could inspire you as well: > >> > https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php > > > > Please try not follow these as general guideline because things like > > [0] will not work in 1.9 or 2.0* and is a rather odd practice to > > invoke the `QueryProcessor`. > > > > If you need examples on how to use a particular class or an > > integration scenario try to have a look at [1] and if you can't find > > an appropriate example then add a request to [2] with a clear > > description of a possible test example. > > > > [0] > https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php#L321 > > > > [1] > https://github.com/SemanticMediaWiki/SemanticMediaWiki/tree/master/tests > > > > [2] https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/445 > > > > Cheers > > > > On 11/2/14, Toni Hermoso Pulido wrote: > >> Hi James, > >> > >> I found this link some weeks ago: > >> > https://semantic-mediawiki.org/wiki/User:Yury_Katkov/programming_examples > >> > >> Even though Semantic Tasks is unmaintained, I found some piece of code > >> that could inspire you as well: > >> > https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FSemanticTasks/5363a0ba564c5c3708c246a4c316260d781da1e1/SemanticTasks.classes.php > >> > >> Hope it helps, > >> > >> El 01/11/14 a les 19:18, James Montalvo ha escrit: > >>> I'm creating a parser function in which I'm going to include an ask > >>> query. > >>> In this particular case I'd like it just return a normal HTML table of > >>> results, as if I were to do: > >>> > >>> {{#ask: [[Category:Some category]] > >>> |? Property 1 > >>> |? Property 2 > >>> | limit = 10 > >>> | sort = Property 2 > >>> }} > >>> > >>> Once I understand this I'll probably have cases where I need to modify > >>> the > >>> results of the query before passing it to a result formatter or > >>> formatting > >>> the results manually. What is the best way to do this using existing > SMW > >>> methods? > >>> > > -- > Toni Hermoso Pulido > http://www.cau.cat > http://www.similis.cc > > > -- > ___ > Semediawiki-devel mailing list > Semediawiki-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/semediawiki-devel > -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel
Re: [SMW-devel] Ask query in extension
James Montalvo wrote > I spent a lot of time on Friday trying to figure out how to replicate an > ask query in PHP. I was pretty sure I could do something to reuse the > parser, but since I wanted to be able to manipulate the data before > displaying it I did not pursue that method. Thank you, Frank, for the way > you described. I'm sure that will come in handy in the future. There is also the following extension, which provides a simple interface for making queries in PHP: https://www.mediawiki.org/wiki/User:Vedmaka/Semantic_Query_Interface https://github.com/vedmaka/SemanticQueryInterface Even if the extension is not used directly, the code it contains is useful in showing how querying can be done. -- View this message in context: http://wikimedia.7.x6.nabble.com/Ask-query-in-extension-tp5038530p5038566.html Sent from the Semantic Mediawiki - Development mailing list archive at Nabble.com. -- ___ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel