forked from watson-developer-cloud/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathalchemy_language_v1.py
More file actions
49 lines (44 loc) · 2.5 KB
/
alchemy_language_v1.py
File metadata and controls
49 lines (44 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import json
from os.path import join, dirname
from watson_developer_cloud import AlchemyLanguageV1
alchemy_language = AlchemyLanguageV1(api_key='YOUR API KEY')
url = 'https://developer.ibm.com/watson/blog/2015/11/03/price-reduction-for' \
'-watson-personality-insights/'
print(json.dumps(
alchemy_language.targeted_sentiment(text='I love cats! Dogs are smelly.',
targets=['cats', 'dogs'],
language='english'), indent=2))
# print(json.dumps(alchemy_language.targeted_emotion(text='I love apples. I
# hate bananas',
# targets=['apples',
# 'bananas'], language='english'), indent=2))
# print(json.dumps(alchemy_language.author(url=url), indent=2))
# print(json.dumps(alchemy_language.concepts(max_items=2, url=url), indent=2))
# print(json.dumps(alchemy_language.dates(url=url, anchor_date='2016-03-22
# 00:00:00'), indent=2))
# print(json.dumps(alchemy_language.emotion(url=url), indent=2))
# print(json.dumps(alchemy_language.entities(url=url), indent=2))
# print(json.dumps(alchemy_language.keywords(max_items=5, url=url), indent=2))
# print(json.dumps(alchemy_language.category(url=url), indent=2))
# print(json.dumps(alchemy_language.typed_relations(url=url), indent=2))
# print(json.dumps(alchemy_language.relations(url=url), indent=2))
# print(json.dumps(alchemy_language.language(url=url), indent=2))
# print(json.dumps(alchemy_language.text(url=url), indent=2))
# print(json.dumps(alchemy_language.raw_text(url=url), indent=2))
# print(json.dumps(alchemy_language.title(url=url), indent=2))
# print(json.dumps(alchemy_language.feeds(url=url), indent=2))
# print(json.dumps(alchemy_language.microformats(
# url='http://microformats.org/wiki/hcard-examples'), indent=2))
# print(json.dumps(alchemy_language.publication_date(url=url), indent=2))
# print(json.dumps(alchemy_language.taxonomy(url=url), indent=2))
combined_operations = ['page-image', 'entity', 'keyword', 'title', 'author',
'taxonomy', 'concept', 'doc-emotion']
print(
json.dumps(alchemy_language.combined(url=url, extract=combined_operations),
indent=2))
# Get sentiment and emotion information results for detected entities/keywords:
# print(json.dumps(alchemy_language.entities(url=url, sentiment=True,
# emotion=True), indent=2))
# print(json.dumps(alchemy_language.keywords(max_items=5, url=url,
# sentiment=True, emotion=True),
# indent=2))