Ejemplo n.º 1
0
def findParents(TermID, parentHits, secondaryHits, checked):
	if TermID not in checked:
		checked.append(TermID)
		if str(TermID) in primary_parents_list:
			if str(TermID) not in parentHits:
				parentHits.append(TermID)
		else:	
			query = "SELECT DISTINCT `ParentTermID`, `ParentTermLabel` FROM `thesaurusNew2015` WHERE TermID = %s"
			cursor = db.get_cursor()	
			cursor.execute(query, [TermID])
			set  = {}
			while True: 
				row = cursor.fetchone()
				if not row:
					break
				if row:
					set[str(row["ParentTermID"])] = row["ParentTermLabel"]
                        db.get_connection().commit()
			cursor.close()

			for ParentTermID in set:
				if str(ParentTermID) in primary_parents_list:
					if str(ParentTermID) not in parentHits:
						parentHits.append(ParentTermID)
					if str(TermID) not in secondaryHits:
						secondaryHits.append(TermID)
				else:
					parentHits, secondaryHits = findParents(ParentTermID, parentHits, secondaryHits, checked)
	return parentHits, secondaryHits
Ejemplo n.º 2
0
            current_segment = segment_2['SegmentNumber']
            current_segment_id = segment_2['SegmentID']

    else:
        # insert last one
        for term in current_segment_keywords:
            insert_cursor.execute(insert_query, (
                segment_number,
                current_segment_id,
                term[0],
                term[1],
                term[2],
                term[3],
                current_testimony_id,
            ))
        # set current_segment, current_testimony_kid
        current_segment_keywords = [[
            segment_2['TermID'],
            segment_2['TermLabel'],
            segment_2['SecondLevelParentID'],
            segment_2['ParentLabel'],
        ]]
        current_segment = segment_2['SegmentNumber']
        current_testimony_id = segment_2['IntCode']
        current_segment_id = segment_2['SegmentID']

db.get_connection().commit()
insert_cursor.close()

print 'Complete'
# Create parentsProbabilityTable.
tot_tmonies = len(testimonies)
parentsProbabilityTable = parentsTable
for parID in parentsProbabilityTable:
	for i in range(1,101):
		parentsProbabilityTable[parID][i] = parentsProbabilityTable[parID][i]/tot_tmonies


query1 = """
insert into secondLevelBaseProbabilities2015
values %r
"""
cursor1 = db.get_cursor()
print(len(parentsProbabilityTable))
parS = parentsProbabilityTable
for parId in parS:
	varlist = []
	varlist.append(str(parId))
	for i in range(1,101):
		varlist.append(str(parS[parId][i]))
	query2 = query1 % (tuple(varlist),)
	cursor1.execute(query2)
conn = db.get_connection()
conn.commit()
cursor1.close()




Ejemplo n.º 4
0
 def setUp(self):
     cur_dir = os.path.dirname(os.path.relpath(__file__))
     sys.path.insert(0, os.path.join(cur_dir, '../'))
     from common.db import get_connection
     self.conn = get_connection('../test.db')