使用Freebase API时如何从mqlread()获取光标? [英] How to get cursor from mqlread() when using Freebase API?

查看:163
本文介绍了使用Freebase API时如何从mqlread()获取光标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python-Freebase模块的

I'm using the Python-Freebase module's mqlread(). Using the following query:

query = [{
  "cursor": True,
  "id":     None,
  "type":   "/games/game",
  "mid":    None,
}]

这将返回100个条目,但结果不包含光标".如果您手动运行查询,则会得到类似以下内容的信息:

That returns 100 entries, but the result does not include "cursor". If you run the query manually you get something like:

{ "code": "/api/status/ok", "cursor": "eNqFj8FqwzAQRD-mF4sisrtaaaWlhP6H8MHYNTUEW8hpKP36KjgU2kvnMoeZ4THjR923qhKS07wpAvR5VZbYBIL9sE76FDGAs-yCA_FISprL_nWUt5tC383L59ukh9llH_TvpL7Y7rYUdZ4CN9iRITB6vTwnAhriCAwAgXGO8Etkz48dicnvy3ptTGO6OwgsBwIfwJNeHpDWowgh_URO63-M0Z7vM0neGZNL3RrihBKFU_uZS2l3sT-9cpIBaRrnOE8JhaAhQL4B9ZFRmg==", "result": [

{
  "id":   "/en/cities_and_knights_of_catan",
  "mid":  "/m/02hq3",
  "type": "/games/game"
},
....

其中包含光标".但是结果来自:

Which contains the "cursor". But the result from:

freebase.mqlread(query, extended=True)

会返回:

[{u'type': u'/games/game', u'id': u'/en/cities_and_knights_of_catan'}, ...

其中去除了代码"和光标".如何获得光标"?

Which strips out "code" and "cursor". How can I get the "cursor"?

推荐答案

我发现Freebase-Python模块实际上包括一个为您处理游标的方法.只需调用mqlreaditer(query,extended = true),这将返回一个Python生成器,您可以对其进行迭代.在后台,Freebase模块将查询并跟踪光标,按需返回结果,直到到达假"光标为止.

I found that the Freebase-Python module actually includes a method that takes care of cursoring for you. Just call mqlreaditer(query, extended=true), and that will return a Python generator that you can iterate through. Behind the scenes the Freebase module will query and keep track of the cursor, return results on demand until a "false" cursor is reached.

非常简单!

这篇关于使用Freebase API时如何从mqlread()获取光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆