예제 #1
0
def aangetSuggestion():
    '''獲得輸入的字串, 回傳建議字'''
    text = flask.request.args['text'].strip()
    text = text.split()
    if len(text) > 1:
        # print text[-2]
        if text[-2][-1] == ',' or text[-2][-1] == '.' or text[-2][-1] == '!' or text[-2][-1] == '?':
            text[-2] = text[-2][-1]
        # print "I get the query:",' '.join(text[-2:])
        result = AAN.getWordSuggestion(' '.join(text[-2:]))
        # print result
        return json.dumps(result)
    else:
        return ''
예제 #2
0
def lexgetSuggestion():
    '''獲得輸入的字串, 回傳建議字'''
    text = flask.request.args['text'].strip()
    text = text.split()
    textarray = []
    if len(text) > 1:
        # print text[-2]
        if text[-2][-1] == ',' or text[-2][-1] == '.' or text[-2][-1] == '!' or text[-2][-1] == '?':
            text[-2] = text[-2][-1]
        # print "I get the query:",' '.join(text[-2:])
        result = AAN.getPhraseSuggestion(' '.join(text[-2:]))
        for textjson in result:
          if textjson == 'a':
            textarray.append({"name": ' a'})
          else:
            textarray.append({"name": textjson})
        print textarray
        if not textarray:
          return json.dumps([{"name": "no recommendation :("}])
        else:
          return json.dumps(textarray)
    else:
      return json.dumps([{"name": "no recommendation :("}])
예제 #3
0
 def run(self):
     if lock_of_suggestion.acquire(100):
         #print 'I\'m working...'
         GetSuggestion.thread_query(self.sqlconn)
         lock_of_suggestion.release()
예제 #4
0
 def run(self):
     #while True:
         #PrBdkey.thread_sug()
     if lock_of_suggestion.acquire(100):
         GetSuggestion.thread_sug(self.sqlconn)
         lock_of_suggestion.release()