-
Notifications
You must be signed in to change notification settings - Fork 2
/
flask_app.py
83 lines (64 loc) · 2.39 KB
/
flask_app.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
from flask import Flask, request,jsonify
import CTextSearch as ts
import CClassification as clf
app = Flask(__name__)
SearchObj = ts.CTextSearch()
FileHandlingObj = SearchObj.getFileReadObj()
ClassificationObj = clf.CClassification()
@app.route('/')
def WelcomeToDataMining():
return 'Welcome To Data Mining'
@app.route('/search/',methods=['POST'])
def searchText():
req_data = request.get_json()
print(req_data)
if 'searchString' in req_data:
searchQ = req_data['searchString']
ResultData = SearchQuery(searchQ)
if ResultData == []:
ResultData = {"Movie": ["NA","NA","NA","NA","NA"],
"description": ["NA", "NA" ,"NA","NA" ,"NA"]}
print("Search Result : method :searchText File :DataMiningServer.py")
print(ResultData)
return jsonify(ResultData)
@app.route('/classification/',methods=['POST'])
def classificationdata():
req_data = request.get_json()
print(req_data)
if 'classification' in req_data:
searchQ = req_data['classification']
ResultData = ClassificationT()
if ResultData == []:
ResultData = {"Movie": ["NA", "NA", "NA", "NA", "NA"],
"Class": ["NA", "NA", "NA", "NA", "NA"]}
print("classificationdata : method :classificationdata File :DataMiningServer.py")
print(ResultData)
return jsonify(ResultData)
def InitialiseSearchObject():
print("Initialising search Object")
SearchObj.Read_and_initialise_document()
print("Initialising term frequency")
SearchObj.Calculating_Document_frequency()
print("Search Initialise")
def InitializeClassificationObject():
print("Initialising Classification Object")
ClassificationObj.setFileReadObj(FileHandlingObj)
ClassificationObj.Initialize()
ClassificationObj.CreateTraingData()
ClassificationObj.TrainingClassification()
print("Classification Initialise")
def SearchQuery(query):
print("Inside Search Query Server: DataMiningServer.py")
return SearchObj.Search(query)
def ClassificationT():
print("Inside ClassificationT Server: DataMiningServer.py")
[data, actual_label, index] = ClassificationObj.getTestData()
#print(data)
print(actual_label)
PredictedClass = ClassificationObj.PredictedClass(data, index)
return PredictedClass
InitialiseSearchObject()
InitializeClassificationObject()
#SearchQuery("Woody Summoned Tibet happily")
if __name__ == '__main__':
app.run()