/
start.py
127 lines (111 loc) · 3.63 KB
/
start.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from flask.ext.wtf import Form
from wtforms import TextField, TextAreaField, SubmitField
from wtforms.validators import Required
from flask import Flask
from flaskext.mysql import MySQL
from flask import render_template
from flask import jsonify
from flask import request
import json
import random
import os
mysql = MySQL()
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = 'root'
app.config['MYSQL_DATABASE_DB'] = 'wn_pro_mysql'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
# @app.route("/")
# def one_html():
# return render_template("Bar_Chat.html", title = 'Projects')@app.route("/")
@app.route("/test")
def test():
return jsonify({"hello":"dear"})
@app.route("/")
def one_html():
return render_template("Bar_Chat.html", title = 'Projects')
@app.route("/word_count")
def word_count():
cursor = mysql.connect().cursor()
list_of_dict = []
key = ''
val = ''
for word in range(97,123):
var1 = chr(word)
subSet = {}
#print var1
cursor.execute("SELECT count(word) from wn_synset WHERE word LIKE '{:s}%%'".format(var1))
data = cursor.fetchone()
key = str(var1)
val = data[0]
subSet['index'] = key
subSet['0'] = val
list_of_dict.append(subSet)
return json.dumps(list_of_dict)
@app.route('/my-form.html')
def my_form():
return render_template("my-form.html")
@app.route('/abcd', methods=['GET'])
def my_form_post():
i = 0
text = request.args.get('text')
elementsSet ={}
dataList = []
dataSet = {}
subSet ={}
dataList1 = []
cursor = mysql.connect().cursor()
list_of_dict = []
word = text
var1 = word
shapes = ["rectangle","roundrectangle","ellipse","triangle","square","pentagon","hexagon","heptagon","octagon","star","diamond","vee","rhomboid","polygon"]
subSet['id'] = word
subSet['name'] = word
subSet['weight'] = 90
color = lambda: random.randint(0,255)
subSet['faveColor'] = ('#%02X%02X%02X' % (color(),color(),color()))#'#6FB1FC'
subSet['faveShape'] = 'triangle'
dataSet['data'] = subSet
dataList.append(dataSet)
cursor.execute("SELECT substr(synset_id,1,10) from wn_synset WHERE word ='{:s}'".format(word))
data = cursor.fetchall()
for row in data:
print (row[0])
list_of_dict.append(str(row[0]))
idList = ",".join(list_of_dict)
list_l =['wn_antonym','wn_attr_adj_noun','wn_cause','wn_class_member','wn_entails','wn_hyponym','wn_hypernym','wn_mbr_meronym','wn_part_meronym','wn_subst_meronym','wn_participle','wn_pertainym','wn_see_also','wn_similar','wn_verb_group']
for r in list_l:
cursor.execute("SELECT count(*) from {:s} where synset_id_1 in ({:s})".format(r,idList))
antonym_data = cursor.fetchone()
if antonym_data[0] != 0:
dataSeta = {}
subSeta ={}
print (r,antonym_data[0])
if i > 13:
i=0
subSeta['id'] = r
subSeta['name'] = r
subSeta['weight'] = antonym_data[0]
color = lambda: random.randint(0,255)
subSeta['faveColor'] = ('#%02X%02X%02X' % (color(),color(),color()))#'#EDA1ED'
subSeta['faveShape'] = shapes[i]
dataSeta['data'] = subSeta
dataList.append(dataSeta)
#print (dataList)
dataSet1 = {}
subSet1 ={}
subSet1['source'] = word
subSet1['target'] = r
subSet1['faveColor'] = '#6FB1FC'
subSet1['strength'] = 90
dataSet1['data'] = subSet1
dataList1.append(dataSet1)
i = i+1
#print (dataList1)
elementsSet['nodes'] = dataList
elementsSet['edges'] = dataList1
return jsonify(elementsSet)
if __name__ == "__main__":
port = int(os.environ.get('PORT', 5000))
app.run(host="0.0.0.0",port=port,debug=True)