def __init__(self): self.childlist = {} self.parentlist = {} self.categorylist = Classification.getclassificationrule() self.childlist['x'] = [] for catnode in self.categorylist: if(Classification.isCat(catnode)): self.parentlist[catnode] = 'x' self.childlist['x'].append(catnode) self.childlist[catnode] = [] elif(Classification.isSubcat(catnode)): self.parentnode = Classification.subcatToCat(catnode) self.parentlist[catnode] = self.parentnode self.childlist[self.parentnode].append(catnode)
import BaseXClient import Classification import Tree import math import xml.dom.minidom as xmldom from array import * from collections import defaultdict try: session1 = BaseXClient.Session('localhost',1984,'admin','admin') session2 = BaseXClient.Session('localhost',1984,'admin','admin') session1.execute('open keywordXML') session2.execute('create db distinctness') categorylist = Classification.getclassificationrule() # Prepare dictionaries kf = {} siblingcount = {} siblingkeyword = {} distinctness = {} # Create a Category Tree. this will be later used for finding sibling of the category. cattree = Tree.Categorytree() # Count the amount of sibling categories for each category for cat in categorylist: siblingcount[cat] = len(cattree.getSibling(cat)) # Calculate keyword frequency in a category, store it to the kf table