[Developers] Python query not working?
Christopher R. Maden
crism at metaweb.com
Tue Jul 22 14:26:19 UTC 2008
Chris Mahon wrote:
> Right ok, so do I still put the {} brackets before and after or do I
> simple do this?
>
> query = [...query here...]
Short answer is to do what you show: query = [...]
However, it’s important to note that the square brackets don’t
*surround* the query; they are *part of* the query.
The important part in freebase-python is the call to mqlread().
If you are looking for a single object:
result = mss.mqlread( { constraints } )
If you are looking for multiple objects:
results = mss.mqlread( [ { constraints } ] )
E.g.:
sting = mss.mqlread( { "type" : "/music/artist",
"name" : "Sting",
"id" : None } )
smiths = mss.mqlread( [ { "type" : "/music/artist",
"name" : "Robert Smith",
"id" : None } ] )
[As a note, it is generally a bad idea to assume that a name-based query
is going to have a single result, as the freebase-python sample, and my
Sting example above, do. If a Freebase user adds another instance of
the same name, all your code will break. Unless your query is
ID-constrained, you are better off looking for multiple results all the
time.]
~Chris
--
Christopher R. Maden
Data Architect
Freebase.com: <URL: http://www.freebase.com/ >
Metaweb Technologes, Inc. <URL: http://www.metaweb.com/ >
More information about the Developers
mailing list