예제 #1
0
    def find(self):
        db = DB()
        db.init()

        if db.find_one(self.collection, {"intent": self.intent}):
            return True
        else:
            return False
예제 #2
0
    def find_response(self):
        db = DB()
        db.init()

        if self.find:
            get = db.find_one(self.collection, {"intent": self.intent,
                                                "entity": self.entity})
            return get['response']
        else:
            return {"message": "Object not found."}
예제 #3
0
    def find_response(self):
        db = DB()
        db.init()

        if self.intent == "admissibilite_congé":
            if self.find:
                get = db.find_one(self.collection, {"intent": self.intent})
                return random.choice(get['response'])
            else:
                return {"message": "Object not found."}
        else:
            if self.find:
                get = db.find_one(self.collection, {"intent": self.intent})
                return get['response']
            else:
                return {"message": "Object not found."}
예제 #4
0
 def __init__(self, dbconfig):
     self.db = DB.getDatabase(dbconfig.user, dbconfig.password,
                              dbconfig.database_name)
예제 #5
0
    if not '-' in age:
        raise ValueError('Invalid format. Try again.')
    age = list(map(int, age.split('-')))
    if age[0] > age[1]:
        reversed(age)
    if age[0] < 18:
        age[0] = 18
        print("We won't search among kids. Let's start from 18")
    if age[1] > 120:
        age[1] = 120
        print(
            "We don't judge you, but we can't find such old people. Let's put 120 y.o. as maximum, that will be enough for you."
        )
    sexis = {'b': 2, 'g': 1, 'd': 0}
    sex = input(
        "Are you searching for boys / girls / doesn't matter [b/g/d]?: ")
    if not sex in ['b', 'g', 'd']:
        raise ValueError('Invalid format. Try again')

    context = {
        'user_id': user_id,
        'age': age,
        'sex': sexis[sex],
        'fields': 'sex, bdate, city, career, universities, schools, common_count, personal'\
        'connections, activities, interests, music, movies, tv, books, games, about, photo_max',
    }

    lonely_user = User(context['user_id'], context['fields'])
    db_api = DB(context['user_id'])
    main(lonely_user, context)
예제 #6
0
    def post():

        global entitiz, nlu2, nlu

        # -- NLP treatment --

        # Input body composition
        data = request.get_json()

        body = dict({
            'query': data['msg'],
            'nlp-address': data['nlp-url'],
            'collection-name': data['collection']
        })

        # NLU post request
        intent = requests.post(url=body['nlp-address'],
                               data=json.dumps(dict({'query': body['query']})))
        entity = requests.post(url=body['nlp-address'],
                               data=json.dumps(dict({'query': body['query']})))
        text = requests.post(url=body['nlp-address'],
                             data=json.dumps(dict({'query': body['query']})))
        date = intent.headers['Date']

        # Database class using
        db = DB()
        db.Collection = body['collection-name']
        db.init()

        # Extracting Intent and Entity
        intent = intent.json()['intent']['name']
        intent_confidence = entity.json()['intent']['confidence']
        entity_array = entity.json()['entities']

        # Implement entity array into list
        length = len(entity_array)
        i = 0
        entitiz = list()
        while i != length:
            entitiz.append(entity_array[i]['value'])
            i = i + 1

        text = text.json()['text']

        # Checking if the entity is none
        if not is_empty(entitiz):
            nlu2 = NluObjectWithEntity(body['collection-name'],
                                       intent,
                                       entitiz[0],
                                       response=None)
        nlu = NluObjectSimple(body['collection-name'], intent, response=None)

        # Saving request informations

        saves = dict(date=date,
                     text=text,
                     intent=intent,
                     intent_confidence=intent_confidence,
                     entities=entity_array)
        save(saves)

        # Sending Json Object with Headers & Response
        if nlu.find:
            json_object = dict({
                'success':
                'Message sent with success',
                'text':
                text,
                'msg-type':
                'text',
                'bot':
                dict(response=nlu.find_response
                     if is_empty(entitiz) else nlu2.find_response,
                     quickReplies=True,
                     quicks=["congé", "contrats", "obligation patronale"])
            })

            return json_object, 200, {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json'
            }

        else:
            json_object = {
                'response': 'Pouvez-vous mieux préciser ce vous voulez dire ??'
            }
            return json_object, 400, {'Content-Type': 'application/json'}
예제 #7
0
import connexion
from api import config
from api.db import DB

app = connexion.FlaskApp(__name__)

app.add_api(
    "swagger.yaml",
    resolver=connexion.RestyResolver("customer_review.api"),
    strict_validation=True,
    validate_responses=True,
)
app = app.app

app.config.update(**config.MYSQL.params())
DB.init_app(app)

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')