def get_word_concept(word): sql = "SELECT idconcepts, " \ "relation," \ "first," \ "second " \ "FROM concepts " \ "WHERE first = %s OR second = %s " conn = SqlConnConcepts.get_connection() cursor = conn.cursor() resulting = [] try: cursor.execute(sql, (word, word,)) # Fetch all the rows in a list of lists. result = cursor.fetchall() for row in result: id = row[0] relation = row[1] first = row[2] second = row[3] resulting.append(Concept(id, first, relation, second)) except: print("Error Concept: unable to fetch data for word "+word) conn.close() return resulting
def get_all_concepts(): sql = "SELECT idconcepts, " \ "relation," \ "first," \ "second " \ "FROM concepts " conn = SqlConnConcepts.get_connection() cursor = conn.cursor() resulting = [] try: cursor.execute(sql) result = cursor.fetchall() for row in result: id = row[0] relation = row[1] first = row[2] second = row[3] resulting.append(Concept(id, first, relation, second)) except: print("Error Concepts: unable to fetch all data") conn.close() return resulting
def get_specific_concept(id): sql = "SELECT idconcepts, " \ "relation," \ "first," \ "second " \ "FROM concepts " \ "WHERE idconcepts = %d;" % id conn = SqlConnConcepts.get_connection() cursor = conn.cursor() resulting = None try: # Execute the SQL command cursor.execute(sql) # Fetch all the rows in a list of lists. result = cursor.fetchone() row = result id = row[0] relation = row[1] first = row[2] second = row[3] resulting = Concept(id, first, relation, second) except: print("Error Concepts: unable to fetch data of character #%d" % id) conn.close() return resulting
def get_concept_specified(first, relation, second): sql = "SELECT idconcepts, " \ "relation," \ "first," \ "second " \ "FROM concepts " \ "WHERE first = %s AND second = %s AND relation = %s " conn = SqlConnConcepts.get_connection() cursor = conn.cursor() resulting = None try: # Execute the SQL command cursor.execute(sql, (first, second, relation,)) # Fetch all the rows in a list of lists. result = cursor.fetchone() if result != None: id = result[0] relation = result[1] first = result[2] second = result[3] resulting = (Concept(id, first, relation, second)) except: print("Error Concept: unable to fetch data for word " + first + " and " + second + " relation: " + relation) conn.close() return resulting
def get_concept_like(relation, first="", second=""): sql = "SELECT idconcepts, " \ "relation," \ "first," \ "second " \ "FROM concepts " \ "WHERE first LIKE '%"+str(first)+"%' AND second LIKE '%"+str(second)+"%' AND relation = '"+str(relation)+"'" conn = SqlConnConcepts.get_connection() cursor = conn.cursor() resulting = [] try: cursor.execute(sql) # Fetch all the rows in a list of lists. result = cursor.fetchall() print("GLOBAL, LENGTH OF RESULT:", len(result)) id = -1 relation = "" first = "" second = "" for row in result: id = row[0] relation = row[1] first = row[2] second = row[3] resulting.append(Concept(id, first, relation, second)) except: print("Error Concept: unable to fetch like data") conn.close() return resulting
import requests from src.db.concepts.DBO_Concept import DBO_Concept from src.objects.concepts.Concept import Concept # obj = requests.get('http://api.conceptnet.io/c/en/fitting?rel=/r/RelatedTo&limit=1000').json() # print(obj.keys()) # print(len(obj['edges'])) # print(obj['edges'][2]) res = DBO_Concept.getConceptForWord("cat") for a in res: print(a) conc = Concept(-1, "horse", Concept.RELATION_ISA, "animal") resu = DBO_Concept.addConcept(conc) print(resu)