【发布时间】:2018-03-30 20:15:44
【问题描述】:
我正在尝试使用 BabelNet RESTful API 来检索页面上光泽下方和“探索网络”按钮上方的信息。例如在page for GPS 上,我希望能够提取这些属性值对:
IS A navigational system • sat nav • avionics
HAS PART USA-242 • USA-248
COUNTRY United States
COUNTRY OF ORIGIN United States
OPERATOR Air Force Space Command
USE location • place
这些信息可以通过 RESTful API 获得吗?
更新:
我实际上或多或少地想通了这一点。关键是getOutgoingEdges 查询,尽管其中的某些部分是反复试验,因为我没有发现文档像人们希望的那样有用。但这是我得到的(现在只是为了调试目的打印出来),使用 python 请求和 BeautifulSoup:
import requests
from bs4 import BeautifulSoup
import json
proxy_dict = {} # set according to system needs
nextId = "bn:00040680n" # the GPS page
r = requests.get('https://babelnet.io/v5/getOutgoingEdges?id='+nextId+'&key=<mykey>', proxies = proxy_dict)
idsoup = BeautifulSoup(r.text, "lxml")
jsonedgesitem = json.loads(idsoup.html.body.p.string)
for relation in jsonedgesitem:
lang = relation.get("language")
if lang == "EN" or lang == "MUL":
if "pointer" in relation:
shortName = relation["pointer"].get("shortName")
if shortName != "related" and shortName != "gloss-related":
print(json.dumps(relation,indent=2))
我会筛选掉非英语链接,以及只是“相关”和“光泽相关”链接的链接,它们占绝大多数。
产生以下输出:
{
"pointer": {
"name": "operator",
"fSymbol": "wd92",
"relationGroup": "OTHER",
"shortName": "operator",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00001859n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "use",
"fSymbol": "wd148",
"relationGroup": "OTHER",
"shortName": "use",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00051760n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "use",
"fSymbol": "wd148",
"relationGroup": "OTHER",
"shortName": "use",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00062699n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "Hypernym",
"fSymbol": "@",
"relationGroup": "HYPERNYM",
"shortName": "is-a",
"isAutomatic": false
},
"language": "EN",
"target": "bn:00057078n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "has_part",
"fSymbol": "wd76",
"relationGroup": "HOLONYM",
"shortName": "has_part",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:15441159n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "has_part",
"fSymbol": "wd76",
"relationGroup": "HOLONYM",
"shortName": "has_part",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:16971426n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "country_of_origin",
"fSymbol": "wd35",
"relationGroup": "OTHER",
"shortName": "country_of_origin",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00003341n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "subclass_of",
"fSymbol": "wd21",
"relationGroup": "HYPERNYM",
"shortName": "subclass_of",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00007477n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "country",
"fSymbol": "wd3",
"relationGroup": "OTHER",
"shortName": "country",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00003341n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "Hyponym",
"fSymbol": "~@w",
"relationGroup": "HYPONYM",
"shortName": "has-kind",
"isAutomatic": true
},
"language": "EN",
"target": "bn:01177672n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "Hyponym",
"fSymbol": "~@w",
"relationGroup": "HYPONYM",
"shortName": "has-kind",
"isAutomatic": true
},
"language": "EN",
"target": "bn:02122452n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "Hyponym",
"fSymbol": "~@w",
"relationGroup": "HYPONYM",
"shortName": "has-kind",
"isAutomatic": true
},
"language": "EN",
"target": "bn:03088008n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "Hypernym",
"fSymbol": "@wd",
"relationGroup": "HYPERNYM",
"shortName": "is-a",
"isAutomatic": false
},
"language": "MUL",
"target": "bn:00732900n",
"normalizedWeight": 0.0,
"weight": 0.0
}
{
"pointer": {
"name": "Hypernym",
"fSymbol": "@w",
"relationGroup": "HYPERNYM",
"shortName": "is-a",
"isAutomatic": true
},
"language": "EN",
"target": "bn:00732900n",
"normalizedWeight": 0.0,
"weight": 0.0
}
在哪里记录了这里可以包含哪些类型的关系?特别是,上位词“is-a”和上位词“子类”类型的关系之间是否存在有意义的区别? fSymbol 值记录在哪里?
【问题讨论】:
-
您是否参考了如何建模语义关系?以下链接中的部分? w3.org/community/bpmlod/wiki/…
-
不,我不知道那个资源——我只使用了babelnet.org/guide
标签: rest