[Developers] Clojure library
Richard Newman
rnewman at twinql.com
Fri Jul 17 01:04:21 UTC 2009
> This looks great!
> Now I have an actual excuse to go fiddle with clojure, thanks!
Thanks! Enjoy it :)
> Most of it's pretty straightforward looking, but i'm a little confused
> by the syntax of mql-reconcile, whats going on there?
mql-reconcile takes one required argument, which is the "simplified
MQL" accepted by the reconciliation service[1]. That page describes
the simplification:
> Requests resemble simplified MQL queries, with a dictionary of
> canonical properties and literal values. Any properties can be used
> as long as they use the canonical ids. If the property's expected
> value is a literal, then the value in the request is matched against
> the literal. If the property's expected value is a topic, then the
> value is matched against the name. CVT properties are flattened.
E.g., the MQL example on the service page
{
"/type/object/name":"Blade Runner",
"/type/object/type":"/film/film",
"/film/film/starring/actor":["Harrison Ford", "Rutger Hauer"],
"/film/film/starring/character":["Rick Deckard", "Roy Batty"],
"/film/film/director":
{
"name":"Ridley Scott",
"id":"/guid/9202a8c04000641f8000000000032ded"
},
"/film/film/release_date_s":"1981"
}
is represented by the Clojure literal map
{
"/type/object/name" "Blade Runner",
"/type/object/type" "/film/film",
"/film/film/starring/actor" ["Harrison Ford", "Rutger Hauer"],
"/film/film/starring/character" ["Rick Deckard", "Roy Batty"],
"/film/film/director"
{
"name" "Ridley Scott",
"id" "/guid/9202a8c04000641f8000000000032ded"
},
"/film/film/release_date_s" "1981"
}
Note the missing colons, but otherwise identical syntax.
The function also takes some optional keyword arguments which
correspond to those of the API service: start, limit, and jsonp.
An example invocation might be
(mql/mql-reconcile
{
"/type/object/name" "Blade Runner",
"/type/object/type" "/film/film",
"/film/film/starring/actor" ["Harrison Ford", "Rutger Hauer"],
"/film/film/starring/character" ["Rick Deckard", "Roy Batty"],
"/film/film/director"
{
"name" "Ridley Scott",
"id" "/guid/9202a8c04000641f8000000000032ded"
},
"/film/film/release_date_s" "1981"
}
:limit 2)
which returns the top two results as a Clojure vector of maps:
[{:type
["/common/topic"
"/film/film"
"/media_common/quotation_source"
"/media_common/adaptation"
"/media_common/adapted_work"
"/fictional_universe/work_of_fiction"
"/award/award_nominated_work"
"/award/award_winning_work"
"/base/greatfilms/ranked_item"
"/base/greatfilms/topic"
"/base/dystopia/topic"
"/base/filmnoir/topic"
"/award/ranked_item"],
:match true,
:score 2.224857,
:name ["Blade Runner" "Bladerunner"],
:id "/guid/9202a8c04000641f8000000000009e89"}
{:type
["/common/topic"
"/film/film"
"/fictional_universe/fictional_universe"],
:match false,
:score 0.47910464,
:name ["Blade"],
:id "/guid/9202a8c04000641f80000000002643d0"}]
Hope that helps,
-R
[1] <http://mqlx.com/reconciliation/>
More information about the Developers
mailing list