-
Notifications
You must be signed in to change notification settings - Fork 0
/
watsonNLU.py
84 lines (74 loc) · 2.28 KB
/
watsonNLU.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!~/usr/bin/python
from flask import Flask
#import pymysql
import json
import config
from watson_developer_cloud import NaturalLanguageUnderstandingV1
import watson_developer_cloud.natural_language_understanding.features.v1 as Features
app = Flask(__name__)
sem = NaturalLanguageUnderstandingV1(
username=config.watson_u,
password=config.watson_p,
version=config.watson_d)
# return answer and question keywords
@app.route('/test_watson')
def test_watson(t, t2):
# text = "An organization of workers that tries to improve working conditions, wages, and benefits for its members"
text = t
if len(text) < 15:
answer = text
else:
answer = sem.analyze(
# text="An organization of workers that tries to improve working conditions, wages, and benefits for its members",
text = t,
features=[
Features.Keywords(
# Semantic Roles options
)
]
)
# text2 ="Social Justice"
text2 = t2
if len(text2) < 15:
question = text2
else:
question = sem.analyze(
# text="Social Justice",
text = t2,
features=[
Features.Keywords(
# Semantic Roles options
)
]
)
return(json.dumps(answer, indent=2))+(json.dumps(question, indent=2))
#return single search term given alexa question
@app.route('/test_searchterm')
def text_searchterm():
text = "tell me about social justice and obama?"
if len(text) < 15:
keywords = text
else:
keywords = sem.analyze(
text="tell me about social Justice and obama",
features=[
Features.Keywords(
# Semantic Roles options
)
]
)
dictionary = (json.dumps(keywords, indent=2))
keyword = keywords["keywords"][0]["text"]
return(keyword)
@app.route('/setup')
def fetch():
set_to_fetch = request.args.get('fetch')
return json.dumps({"message": "fetched the {} set!".format(set_to_fetch)},indent=2)
@app.route('/hello/<u_name>')
def address(u_name):
return 'hey {}! did you know that harris is gay'.format(u_name)
@app.route('/')
def index():
return "ssssssssss"
if __name__ == '__main__':
app.run()