简体   繁体   English

Twitter API的复杂查询-Python包装器

[英]Complex queries with twitter API- python wrapper

Are complex queries possible using the twitter API? 使用twitter API是否可以进行复杂的查询? For example in the example queries shown in the dev site can I have my query be something like: 例如,在开发站点中显示的示例查询中,我是否可以将查询设为:

("chocolate" AND "cat") OR ("super ninja" AND "ghost" AND "person" but NOT "dog") (“巧克力”和“猫”)或(“超级忍者”和“鬼”和“人”,但不是“狗”)

The queries in the site look really simple and I'm wondering if you can have multiple at the same time, AND as well as OR in a query or is it mutually exclusive? 该站点中的查询看起来非常简单,我想知道您是否可以同时具有多个查询,以及一个查询中的AND还是互斥?

I tried googling around but I could only find one word example queries (useless). 我尝试使用谷歌搜索,但只能找到一个单词示例查询(无用)。 does this mean that I can join the developer documentation examples from the site and mesh them in one query like so: 这是否意味着我可以从该站点加入开发人员文档示例,并将它们划分为一个查询,如下所示:

q="chocolate cat -dog OR super ninja ghost person -dog" q =“ chocolate cat -dog or super ninja ghost person -dog”

is the above query the same result as the first statement with the AND/OR? 上面的查询结果与使用AND / OR的第一个语句的结果相同吗?

I have been using TwitterSearch library but I can only do queries such as: 我一直在使用TwitterSearch库,但只能执行以下查询:

"chocolate" AND "cat" “巧克力”和“猫”

"chocolate" OR "dog" “巧克力”或“狗”

I might be able to do the following but haven't tested yet: 我可能可以执行以下操作,但尚未经过测试:

("chocolate" OR "cat") AND "person" (“巧克力”或“猫”)和“人”

( page 22 TwitterSearch library doc ). 第22页,TwitterSearch库文档 )。

Also the library allows for NOT but I can't tell if I can use both AND and OR then a NOT. 此外,该库还允许使用NOT,但我无法确定是否可以同时使用AND和OR,然后再使用NOT。 This is also on page 22 under 'excepting keywords' 这也在第22页的“关键字除外”下

This is not complex enough to my taste, I am open to any other libraries/wrapper that have more complexity in their query searches but I am not sure if twitter even has this complexity in their API. 这还不足以使我满意,我对在查询搜索中具有更高复杂性的任何其他库/包装器持开放态度,但我不确定twitter的API是否具有这种复杂性。

Thank you,and any links you have would be much appreciated as well. 谢谢,您所拥有的任何链接也将不胜感激。

Yes you are correct, you're able to combine the query operators in any way that fits your criteria. 是的,您是正确的,您能够以适合您条件的任何方式组合查询运算符。

q="chocolate cat -dog OR super ninja ghost person -dog" q =“ chocolate cat -dog or super ninja ghost person -dog”

However, in that one you're specifically remove dog in the first one, but you are not in: 但是,在该狗中,您特别要在第一个狗中将其删除,但您不在:

("chocolate" AND "cat") OR ("super ninja" AND "ghost" AND "person" but NOT "dog") (“巧克力”和“猫”)或(“超级忍者”和“鬼”和“人”,但不是“狗”)

Don't you mean to have 你不是故意要

q="chocolate cat OR super ninja ghost person -dog" q =“巧克力猫或超级忍者鬼人-狗”

Either way, yes that will filter out the tweets based on the operators provided. 无论哪种方式,是的,这将根据提供的运算符过滤掉这些推文。

From your comment: 根据您的评论:

You are getting exactly what you're specifying. 您得到的正是您指定的内容。

If we look at the "nap cat -dog" sentence first, you're filtering all tweets that must contain nap and cat in the same tweet excluding dog. 如果我们先看“ nap cat -dog”一句话,您将在同一条推文中过滤所有必须包含nap和cat的推文,但不包括dog。 They also contain any other word which in your case you're getting breakfast because you have no restriction for that in "nap cat -dog" filter. 它们还包含其他任何单词,在您的情况下您要吃早餐,因为您对“小睡猫-狗”过滤器没有任何限制。

The second filter works separately from the first hence the OR statement. 第二个过滤器与第一个过滤器分开工作,因此与OR语句分开工作。 In there again you're saying all tweets that contain time and breakfast, but not dog. 在这里,您再次说所有包含时间和早餐但不包含狗的推文。 The second filter could have nap and cat in it. 第二个过滤器中可能有小睡和猫。

If you want to somehow link them then you'll need: 如果您想以某种方式链接它们,则需要:

q = "nap cat -dog -time -breakfast OR time breakfast - nap -cat -dog" q =“小睡猫-狗-时间-早餐或时间早餐-小睡-猫-狗”

That filter should prevent overlapping of tweets which I'm assuming what you're after. 该过滤器应防止发推文重叠,我假设您要这样做。 Correct? 正确?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM