以下代码:
import rdflib.graph as g
graph = g.Graph()
graph.parse('C:\\Python27\\phyton projects\\senticnet-3.0\\senticnet3.rdf.xml', format='xml')
print graph.serialize(format='pretty-xml')
在Python中返回此数据:
^{pr2}$如何查询此输出的各个元素?在
例如,如何检索apipolarity
的值?在
或者,我怎样才能找回所有的apisemantics
,例如“爱另一个人”,“亲爱的”。。。?在
编辑
我可以检索以下数据:
qres = result.query(
"""SELECT ?subject ?predicate ?object
WHERE {
?subject ?predicate ?object.
}""")
for r in qres.result:
print str(r[0]), str(r[1]), str(r[2])
返回:
http://sentic.net/api/en/concept/a_lot_of_study http://sentic.net/apitext a lot of study
http://sentic.net/api/en/concept/a_lot_of_study http://sentic.net/apiaptitude -0.111
http://sentic.net/api/en/concept/a_lot_of_study http://sentic.net/apiattention -0.005
http://sentic.net/api/en/concept/a_lot_of_study http://sentic.net/apipolarity -0.064
http://sentic.net/api/en/concept/a_lot_of_study http://sentic.net/apipleasantness -0.074
我现在怎样才能把我的问题缩小到一个特定的概念,比如说,它的极性?在
检索概念“a_little”极性的查询示例:
编辑
根据Joshua的建议改进解决方案:
^{pr2}$相关问题 更多 >
编程相关推荐