예제 #1
0
def find_matches(data):
    # Look for matches in all sentences
    # Load the role pattern class
    send('Find matches request received')
    send('Loading pattern')
    pattern_id = data['pattern_id']
    role_pattern = db.load_role_pattern(pattern_id)
    send('Finding matches')
    # Init a minimal vocab to save on deserialisation and memory
    vocab = util.init_vocab()
    sentence_ids = db.get_ids('sentences')
    match_ids = []
    for sentence_id in sentence_ids:
        doc = db.load_sentence_doc(sentence_id, vocab)
        for token in doc:
            print(token, token._.valence)
        matches = role_pattern.match(doc)
        for match in matches:
            slots, match_tokens = db.despacify_match(match, sentence_id)
            match_row = {
                'sentence_id': sentence_id,
                'data': json.dumps({
                    'slots': slots,
                    'match_tokens': match_tokens
                })
            }
            match_id = db.insert_row('matches', match_row)
            match_ids.append(match_id)
            pattern_match_row = {
                'match_id': match_id,
                'pattern_id': pattern_id,
            }
            db.insert_row('pattern_matches', pattern_match_row)
    send('Matches saved. IDs: {}'.format(match_ids))
    emit('find_matches_success')
 def patch_courier(self, courier_id):
     existing_couriers = db.get_ids("couriers")
     if courier_id not in existing_couriers:
         self.invalid.append(courier_id)
         return
     for key in list(self.data):
         if key == "regions":
             self.data[key] = self.validate_regions(self.data[key])
             if self.data[key] is not None:
                 self.data["regions"] = json.dumps(self.data["regions"])
         elif key == "working_hours":
             self.data[key] = self.validate_hours(self.data[key])
             if self.data[key] is not None:
                 self.data["working_hours"] = json.dumps(
                     self.data["working_hours"])
         elif key == "courier_type":
             self.data["type"] = self.validate_type(self.data.pop(key))
             key = "type"
         else:
             self.invalid.append(courier_id)
             return
         if not self.data[key]:
             self.invalid.append(courier_id)
             return
     db.update("couriers", courier_id, self.data)
예제 #3
0
import telebot
import qna
import db
import os
from flask import Flask, request


TOKEN = config.token
bot = telebot.TeleBot(TOKEN)
server = Flask(__name__)
isgamestarted = None
players = []
gamestatus = 'The game hasn\'t started yet.'
try:
    isgamestarted = db.get_game_status()
    players = db.get_ids()
except Exception as e:
    print(e)


@bot.message_handler(commands=['start'])
def start(message):
    try:
        global isgamestarted
        global players
        isinbase = db.add_player(message.from_user.id, message.from_user.username,
                                 message.from_user.first_name, message.from_user.last_name)
        if isinbase:
            response = 'You already registered.\n*/rules* - Rules.'
        else:
            response = 'Hola, thanks for registration!\n*/rules* - Rules.'
 def is_valid(self):
     self.to_internal_value()
     existing_orders = db.get_ids("orders")
     return self.no_duplicates(existing_orders)
예제 #5
0
def find_matches_all_patterns():
    pattern_ids = db.get_ids('patterns')
    for pattern_id in pattern_ids:
        find_matches_data = {'pattern_id': pattern_id}
        find_matches(find_matches_data)