def retrivAnswer(anotherDict,part,prio,keys,fieldKeywords): #print prio reqCollections=sortDict(prio)# these are the required collections with priority #print reqCollections for collection in reqCollections: keywords=part[collection] interList=[] for keyword in keywords: # print keyword interList+=anotherDict[collection][keyword].keys() break tempKey={} coll=reqCollections[0] interList=list(set(interList)) returnresult={} for key in keys: for field in interList: #print key #print anotherDict[coll].keys() if not returnresult.has_key(field): returnresult[field]=[] if key in anotherDict[coll].keys(): # print key if anotherDict[coll].has_key(key): if type(anotherDict[coll][key]) is dict: if anotherDict[coll][key].has_key(field): returnresult[field].append(key) else: get=getword.getwordtonum([key]) try: key=list(set(get) & set(anotherDict[coll].keys()))[0] if type(anotherDict[coll][key]) is dict: if anotherDict[coll][key].has_key(field): returnresult[field].append(key) except: pass return printResult(reqCollections[0],returnresult,sortDictLen(returnresult),part[reqCollections[0]],keys,fieldKeywords)
def addToDict(collection,content,key): global dicti words=content.split() for word in words : word=str(word) if dicti.has_key(word): subDict=dicti[word] if subDict.has_key(collection): superSubDict=dicti[word][collection] if superSubDict.has_key(key): dicti[word][collection][key]=int(superSubDict[key])+1 else: dicti[word][collection][key]=1 else: dicti[word][collection]={} dicti[word][collection][key]=1 else: dicti[word]={} dicti[word][collection]={} dicti[word][collection][key]=1 varKeys=getword.getwordtonum([word]) if varKeys: k=varKeys.pop(0) for word in varKeys: if dicti.has_key(word): subDict=dicti[word] if subDict.has_key(collection): superSubDict=dicti[word][collection] if superSubDict.has_key(k): subSuperSubDict=dicti[word][collection][k] if subSuperSubDict.has_key(key): dicti[word][collection][k][key]=int(subSuperSubDict[key])+1 else: dicti[word][collection][k][key]=1 else: dicti[word][collection]={} dicti[word][collection][k]={} dicti[word][collection][k][key]=1 else: dicti[word]={} dicti[word][collection]={} dicti[word][collection][k]={} dicti[word][collection][k][key]=1