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 <toni...@softcatala.cat>
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 <toni...@softcatala.cat> 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

Reply via email to