raoulbia raoulbia - 21 days ago 15
Python Question

Access Senticnet API using Python

I am trying to run a simple Python script as shown on the sentic.net website:

from senticnet.senticnet import Senticnet
sn = Senticnet()
concept_info = sn.concept('love')
polarity = sn.polarity('love')
semantics = sn.semantics('love')
sentics = sn.sentics('love')


I get this warning:

Traceback (most recent call last):
File "C:\Python27\phyton projects\sentic parser Cambria\sentic_basic.py", line 4, in <module>
concept_info = sn.concept('love')
File "C:\Python27\phyton projects\sentic parser Cambria\senticnet.py", line 22, in concept
result["polarity"] = self.polarity(concept, parsed_graph)
File "C:\Python27\phyton projects\sentic parser Cambria\senticnet.py", line 72, in polarity
return parsed_graph.objects(predicate=URIRef(predicate_uri)).next().toPython()
StopIteration


Why? How should I interpret this message?

Snippet of the code that includes the parsed_graph line:

def polarity(self, concept, parsed_graph=None):
"""
Return the polarity of a concept.
If you pass a parsed graph, the method do not load the rdf again.
"""
concept_polarity_uri = self.concept_base_uri+concept+"/polarity"
predicate_uri = self.senticapi_base_uri+"polarity"

if parsed_graph is None:
graph = rdflib.Graph()
parsed_graph = graph.parse(concept_polarity_uri, format="xml")

return parsed_graph.objects(predicate=URIRef(predicate_uri)).next().toPython()


Note: I use Python 2.7

Answer

received response from the API Developer:

I fixed a bug recently that solve this error. So, I think you are using an old version of the API. Try to update the package, and I think the code will run fine.

If you installed the API using pip, you can use the command: pip show senticnet to verify the version. The up to date version is 0.3.3.

Comments