用于python的官方tagme api包装器

tagme的Python项目详细描述


python的官方tagme api包装器。

安装和设置

这个库由pypi托管。您可以使用以下命令安装它:

pip install tagme

要访问TagmeAPI,您必须注册(免费!)在d4science平台上获得一个授权token

  • 注册到D4Science TagMe VRE
  • 登录后,单击左侧面板上的show按钮以获取授权令牌。

使用标记名

在对web服务进行任何调用之前,需要设置模块级的GCUBE_TOKEN变量。您可以使用:

importtagme# Set the authorization token for subsequent calls.tagme.GCUBE_TOKEN="<Your token goes here>"

作为设置模块变量的替代方法,可以在每次调用时使用可选的gcube_token参数传递令牌。

注释

注释服务允许您查找文本中提到的实体并将它们链接到维基百科。 这就是所谓的sa2kb问题。您可以使用以下内容对文本进行批注:

lunch_annotations=tagme.annotate("My favourite meal is Mexican burritos.")# Print annotations with a score higher than 0.1foranninlunch_annotations.get_annotations(0.1):printann

annotate方法接受参数来设置语言(参数lang,默认为en)和其他内容。 有关详细信息,请参见代码。 注释与表示注释正确的可能性的rho分数相关联。在这个例子中,我们放弃 分数低于0.1的批注。

提及查找

提到查找服务允许您查找文本中哪些部分可能是对某个实体的提及,而无需将它们链接到任何实体。

tomatoes_mentions=tagme.mentions("I definitely like ice cream better than tomatoes.")formentionintomatoes_mentions.mentions:printmention

mentions参数接受默认为en的可选语言参数lang

实体关联性

tagme还提供了实体对之间的语义关系。实体可以指定为维基百科标题 (比如Barack Obama)或者作为维基百科的id(比如534366,实体barack obama的id)。 获取实体之间关系的两种方法是relatedness_title(接受标题)和 relatedness_wid(接受维基百科ID)。两个方法都接受一对实体或一组对。 您可以提交任意大小的对的列表,但是TagmeWeb服务将每100对发出一个查询。 如果一个实体不存在,结果将是^ {TT14} $。

# Get relatedness between a pair of entities specified by title.rels=tagme.relatedness_title(("Barack Obama","Italy"))print"Obama and italy have a semantic relation of",rels.relatedness[0].rel# Get relatedness between a pair of entities specified by Wikipedia ID.rels=tagme.relatedness_wid((31717,534366))print"IDs 31717 and 534366 have a semantic relation of ",rels.relatedness[0].rel# Get relatedness between three pairs of entities specified by title.# The last entity does not exist, hence the value for that pair will be None.rels=tagme.relatedness_title([("Barack_Obama","Italy"),("Italy","Germany"),("Italy","BAD ENTITY NAME")])forrelinrels.relatedness:printrel# You can also build a dictionaryrels_dict=dict(rels)printrels_dict[("Barack Obama","Italy")]

变更日志

请参阅Changelog

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何修复尝试将用户签名到服务器主机时出现的“字符串无法转换为json对象”错误?   控制台Java:不使用新行更新命令行中的文本   java servlet接收xml数据时,出现错误   使用REST API在Bitbucket中复制或复制存储库   java如何在JavaFX中对齐一行?   java如何在活动中显示通过服务获得的数据?   返回BigDecimal作为字符串:返回int   java组织。openqa。硒。InvalidSelectorException:尝试查找元素时选择器无效   java仅在阻塞状态下通知和通知所有影响线程   java JBOSS无法启动部署   java方法的返回值能保证类型安全吗?   JavaeShadoop序列化组织。阿帕奇。hadoop。木卫一。短写失败   java如果我在同一个类上同步了两个方法,它们能同时运行吗?   不使用java数据库的spring分页实现   java如何将字符串切碎成这样的数组?