-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi.py
More file actions
54 lines (44 loc) · 1.89 KB
/
api.py
File metadata and controls
54 lines (44 loc) · 1.89 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
50
51
52
53
54
from bottle import route,run,response
from autoComplete.middleware import autoMain
# from load_data import NWORDS
from spellcheck import correct
from nearestWord import nearestWordMain
from wordSegment.wordSegment import segment
import entityTagger.getEntity as GE
@route('/')
def hello():
return "Welcome to the language model"
@route('/language_model/')
def default_list():
return {" /wordsegment/words":"separated words" , \
" /spellcheck/incorrectWord ":" correct word", \
" /nearestwords/word" : "words near to the given word", \
" /nearestWords/word/number" : "return n words near to the given word where n is number", \
" /autocomplete/word": "will return the list of related words",\
" /getentity/query": "will detect entities and return domain/property "}
@route('/language_model/wordsegment/<name>',method = 'GET')
def wordSegment(name = " "):
words = segment(name)
return {"words" : words}
@route('/language_model/nearestword/<name>/<top_n>',method = 'GET')
def nearestWords(name = " ",top_n = " "):
return {"tags":(nearestWordMain(name,top_n))}
@route('/language_model/nearestword/<name>',method = 'GET')
def nearestWords(name = " "):
return {"tags":(nearestWordMain(name,5))}
@route('/language_model/getentity/<name>',method = 'GET')
def getEntity(name = " "):
query = name
entity_info = GE.querySegment(name)
entity_data = entity_info["entity_details"]
entities = entity_info["segments"]
return {"query": query,"entityData": entity_data,"Entities":entities}
@route('/language_model/spellcheck/<name>',method = 'GET')
def spellcheck(name = " " ):
return {"candidates":correct(name)}
@route('/language_model/autocomplete/<name>', method='GET')
def automplete_show(name = " "):
response.content_type = 'application/json'
response.set_header('Cache-Control', 'no-cache')
return {"content": autoMain(name)}
run(host='localhost', port=7777, debug=True)