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 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
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 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
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
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
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
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
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
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
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])