[Developers] mjt script to display any topic with a specified date
Nick Thompson
nix at metaweb.com
Thu Mar 29 20:11:39 UTC 2007
hard to say what's going on - you must be using q1 somewhere else because
it doesn't show up inside showTopic().
i think what you want is something like this. note that you need to do
some mjt.script magic to set up the second query, because you need to
ask for a property that was passed in as an argument:
UNTESTED CODE!
<div mjt.def="showTopic(type,property,startdate,enddate)">
<pre mjt.script="">
/* need some js to build the query */
var taskq = {name: null, type: type};
taskq[property] = [{
"value":null,
"value<":"1959-01-01",
"value>":"1957-12-31"
}];
</pre>
<div mjt.task="q2">
mjt.mqlread([taskq])
</div>
<div mjt.if="q2.state=='ready'">
... show q2.result ...
</div>
</div>
<div mjt.task="q1">...</div>
<div mjt.if="q1.state=='ready'">
<div mjt.for="r in q1.result"
<div mjt.for="prop in r.properties">
${showTopic(r.type, prop.id, startdate, enddate)}
</div>
</div>
</div>
let me know how that works...
nick
Jack Alves wrote:
> I have a script that displays types and properties from the first query
> (q1). Firebug reports "q1 has no properties" if I insert the div below in
> the body.
>
> <!-- FUNCTION: Display dated topic -->
> <div mjt.def="showTopic(type,property,startdate,enddate)">
> <div mjt.task="q2">
> mjt.mqlread([{
> "date_of_birth":[{
> "value":null,
> "value<":"1959-01-01",
> "value>":"1957-12-31"
> }],
> "name":null,
> "type":"/people/person"
> }])
> </div>
>
>
> -----Original Message-----
> From: developers-bounces at freebase.com
> [mailto:developers-bounces at freebase.com] On Behalf Of Nick Thompson
> Sent: Tuesday, March 27, 2007 2:59 PM
> To: jack at metaweb.com
> Cc: developers at freebase.com
> Subject: Re: [Developers] mjt script to display any topic with a specified
> date
>
> you can do this by wrapping the mjt.task inside a mjt.def. when you invoke
> the function created by mjt.def, it will fire off the subquery. so you
> can't put the mjt.task inside a mjt.for loop, but if you put the task inside
> a mjt.def and call that function inside your for loop, it should do the
> right thing.
>
> i don't have good examples or documentation of this on mjtemplate.org yet,
> but i've used it quite a bit.
>
> nick
>
> Jack Alves wrote:
>> I want to get all properties that use a datetime then for each
>> property get instances in a specified date range. What is the best way
>> to accomplish what I want to do? I am writing a mjt script. I
>> initially thought I would get the list of properties with datetime
>> then iterate doing queries for each type that has a datetime property.
>>
>> I figured out how to get all properties that use datetime,
>>
>> <div mjt.task="q1">
>> mjt.mqlread([{
>> "properties":[{
>> "expected_type":"/type/datetime",
>> "name":null,
>> "schema":{
>> "/freebase/type_profile/instance_count":null,
>> "name":null
>> }
>> }],
>> "sort":"-properties.schema./freebase/type_profile/instance_count",
>> "limit": 75,
>> "type":"/type/type"
>> }])
>> </div>
>>
>>
>> and I know how to get instances with values in a specific date range,
>>
>> <div mjt.task="q2">
>> mjt.mqlread([{
>> "date_of_birth":[{
>> "value":null,
>> "value<":"1959-01-01",
>> "value>":"1957-12-31"
>> }],
>> "name":null,
>> "type":"/people/person"
>> }])
>> </div>
>>
>>
>> I don't know how or if I can do the second query in a mjt.for loop. I
>> noticed the mjt documentation says, "mjt.task= is very special and
>> doesn't combine with any other attributes,".
>> http://www.mjtemplate.org/tour/intro.html#combining-mjt-attributes.
>>
>>
>> _______________________________________________
>> Developers mailing list
>> Developers at freebase.com
>> http://lists.freebase.com/mailman/listinfo/developers
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
More information about the Developers
mailing list