예제 #1
0
# Demonstrates the sentiment analysis capability of the expert.ai (Cloud based) Natural Language API performed by the 'sentiment' resource

from expertai.nlapi.cloud.client import ExpertAiClient
client2 = ExpertAiClient()

text = "Michael Jordan was one of the best basketball players of all time."
language = 'en'

output = client2.specific_resource_analysis(body={"document": {
    "text": text
}},
                                            params={
                                                'language': language,
                                                'resource': 'sentiment'
                                            })

# Output overall sentiment

print("Output overall sentiment:")

print(output.sentiment.overall)

output = client2.specific_resource_analysis(body={"document": {
    "text": text
}},
                                            params={
                                                'language': language,
                                                'resource': 'sentiment'
                                            })

# Output overall sentiment
from expertai.nlapi.cloud.client import ExpertAiClient
client = ExpertAiClient()

text = "Michael Jordan was one of the best basketball players of all time. Scoring was Jordan's stand-out skill, but he still holds a defensive NBA record, with eight steals in a half."
language = 'en'

output = client.specific_resource_analysis(body={"document": {
    "text": text
}},
                                           params={
                                               'language': language,
                                               'resource': 'relations'
                                           })

# Output relations' data

print("Output relations' data:")

for relation in output.relations:
    print(relation.verb.lemma, ":")
    for related in relation.related:
        print("\t", "(", related.relation, ")", related.lemma)
예제 #3
0
# Get precise business name and Yelp ID
myBizName = thebusinesses[0]["name"]
myBizID = thebusinesses[0]["id"]

# Get the Yelp reviewss
url = 'https://api.yelp.com/v3/businesses/' + myBizID + '/reviews'
resp = requests.get(url, headers=headers)
parsed = json.loads(resp.text)

thereviews = parsed["reviews"]

for theYelpReview in thereviews:
    #print (theYelpReview["text"])
    document = client.specific_resource_analysis(
        body={"document": {"text": theYelpReview["text"]}},
        params={'language': language, 'resource': 'sentiment'})

    # Add sentiment scores to our masterList
    masterList.append(document.sentiment.overall)


# Get Google Places info
url = 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=' + myBizName + '+' + searchLocation + '&key=' + googleAPIKey
resp = requests.get(url)
parsed = json.loads(resp.text)
googleSearch = parsed["results"]

googleBizName = googleSearch[0]["name"]
googleBizID = googleSearch[0]["place_id"]