def get_extraction_templates_by_keyword(self,
                                            keyword_lemma,
                                            keyword_dep,
                                            include_blanks=True):
        if include_blanks:
            q = Query \
                .from_(self.table_reference) \
                .select("*") \
                .where(
                    (self.table_reference.keywords == keyword_lemma) | (self.table_reference.keywords == keyword_dep) | (self.table_reference.keywords == "")
            )

        else:
            q = Query \
                .from_(self.table_reference) \
                .select("*") \
                .where(
                    (self.table_reference.keywords == keyword_lemma) | (self.table_reference.keywords == keyword_dep)
            )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ALL)
        if result is None: return None

        extraction_templates = []
        for r in result:
            extraction_templates.append(ExtractionTemplate(*r))

        return extraction_templates
    def add_concept(self, concept):
        q = Query\
            .into(self.table_reference)\
            .columns(
                self.table_reference.relation,
                self.table_reference.first,
                self.table_reference.second,
                self.table_reference.userid,
                self.table_reference.score,
                self.table_reference.valid)\
            .insert(
                concept.relation,
                concept.first,
                concept.second,
                concept.user_id,
                concept.score,
                concept.valid)

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        sql_response = SQLExecuter.execute_write_query(query)

        return sql_response
예제 #3
0
    def get_term(self, term):
        # q = Query \
        #     .from_(self.table_reference) \
        #     .select("*") \
        #     .where( (self.table_reference.term == term) | (self.table_reference.synonym_1 == term) | (self.table_reference.synonym_2 == term) | (self.table_reference.synonym_3 == term) )
        #
        # query = q.get_sql()
        # query = query.replace("\"", "")

        query = 'SELECT * FROM %s WHERE term = "%s" OR synonym_1 = "%s" OR synonym_2 = "%s" OR synonym_3 = "%s" LIMIT 20' % (
            self.table_name, term, term, term, term)
        print(query)

        results = SQLExecuter.execute_read_query(query, FETCH_ALL)

        if results is None:
            return None

        if len(results) == 0:
            return None
        #
        # curr_term = Emotion(term=term)

        curr_term = NRC_Emotion(term=term)

        print("Printing dbo results: ", type(results))
        print(results)
        for X in results:
            curr_term.add_values(X)
            print(X)
        print("DOne Printing dbo results")

        return curr_term
예제 #4
0
    def get_all_concepts(self):
        q = Query \
            .from_(self.table_reference).select("*")

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ALL)
        if result is None: return None

        concepts = []
        for r in result:
            concepts.append(self.concept_type(*r))
        return concepts
    def update_valid(self, first, relation, second, valid):
        q = Query\
            .update(self.table_reference)\
            .set(self.table_reference.valid, valid)\
            .where(
            (self.table_reference.first == first) & (self.table_reference.relation == relation) & (
                    self.table_reference.second == second)
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        sql_response = SQLExecuter.execute_write_query(query)

        return sql_response
    def delete_concept(self, first, relation, second):
        q = Query\
            .from_(self.table_reference)\
            .delete()\
            .where(
            (self.table_reference.first == first) & (self.table_reference.relation == relation) & (
                    self.table_reference.second == second)
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        sql_response = SQLExecuter.execute_write_query(query)

        return sql_response
예제 #7
0
    def get_random_concept(self):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .orderby('rand()') \
            .limit(1)

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ONE)
        if result is None: return None

        concept = self.concept_type(*result)

        return concept
    def get_all_extraction_templates(self):

        q = Query \
            .from_(self.table_reference).select("*")

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ALL)
        if result is None: return None

        extraction_templates = []
        for r in result:
            extraction_templates.append(ExtractionTemplate(*r))

        return extraction_templates
예제 #9
0
    def get_concept_by_id(self, id):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .where(
            self.table_reference.id == id
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ONE)
        if result is None: return None

        concept = self.concept_type(*result)

        return concept
    def get_specific_template(self, id):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .where(
            self.table_reference.idtemplates == id
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ONE)
        if result is None: return None

        dialogue_template = DialogueTemplateBuilder.build(*result)

        return dialogue_template
예제 #11
0
    def get_specific_user(self, name, code):
        q = Query\
            .from_(self.table_reference)\
            .select("*")\
            .where(
                (self.table_reference.name == name) & (self.table_reference.code == code)
            )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ONE)
        if result is None: return None

        user = self.user_type(*result)

        return user
예제 #12
0
    def get_concept_by_word(self, word):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .where(
            (self.table_reference.first == word) | (self.table_reference.second == word)
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ALL)
        if result is None: return None

        concepts = []
        for r in result:
            concepts.append(self.concept_type(*r))
        return concepts
예제 #13
0
    def get_specific_concept(self, first, relation, second):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .where(
            (self.table_reference.first == first) & (self.table_reference.relation == relation) & (
                    self.table_reference.second == second)
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ONE)
        print("RESULT IS THIS:", result)
        if result is None or not result: return None

        concept = self.concept_type(*result)

        return concept
예제 #14
0
    def get_similar_concept(self, relation, first="", second=""):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .where(
            (self.table_reference.first.like('%' + first + '%')) &
            (self.table_reference.second.like('%' + second + '%')) &
            (self.table_reference.relation == relation)
        )
        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ALL)
        if result is None: return None

        concepts = []
        for r in result:
            concepts.append(self.concept_type(*r))
        return concepts
예제 #15
0
    def add_user(self, user):
        q = Query\
            .into(self.table_reference)\
            .columns(
                self.table_reference.name,
                self.table_reference.code)\
            .insert(
                user.name,
                user.code )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        sql_response = SQLExecuter.execute_write_query(query)

        if sql_response is not None:
            user.id = sql_response

        return user
예제 #16
0
    def get_user_by_name(self, name):
        q = Query\
            .from_(self.table_reference)\
            .select("*")\
            .where(
                (self.table_reference.name == name)
            )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ONE)
        if result is None: return None

        users = []
        for r in result:
            users.append(self.user_type(*r))

        return users
    def get_templates_of_type(self, dialogue_type):
        q = Query \
            .from_(self.table_reference) \
            .select("*") \
            .where(
            self.table_reference.response_type == dialogue_type
        )

        query = q.get_sql()
        query = query.replace("\"", "")
        print(query)

        result = SQLExecuter.execute_read_query(query, FETCH_ALL)
        if result is None: return None

        dialogue_templates = []
        for r in result:
            print("result is: ", r)
            dialogue_templates.append(DialogueTemplateBuilder.build(*r))

        return dialogue_templates
예제 #18
0
    def get_all_terms(self):
        # q = Query \
        #     .from_(self.table_reference) \
        #     .select("*") \
        #     .where( (self.table_reference.term == term) | (self.table_reference.synonym_1 == term) | (self.table_reference.synonym_2 == term) | (self.table_reference.synonym_3 == term) )
        #
        # query = q.get_sql()
        # query = query.replace("\"", "")

        query = 'SELECT * FROM %s' % self.table_name
        print(query)

        results = SQLExecuter.execute_read_query(query, FETCH_ALL)

        if results is None:
            return None

        if len(results) == 0:
            return None

        for X in results:
            self.get_term()
            print(X[1])