def returnConcepts( self, concepts, namedentities=False ): #returns concepts as a set of tuples (first element of each tuple=concept extent, second element of each tuple=concept intent) transformed_concepts = {(ip.tupToIndices(tup[0]), ip.tupToIndices(tup[1])) for tup in concepts} if namedentities == True: transformed_concepts = {(ip.indicesToNames(tup[0], self.objects), ip.indicesToNames(tup[1], self.attributes)) for tup in transformed_concepts} return transformed_concepts
def printConcepts( self, concepts, outputfile=sys.stdout, namedentities=False): #prints concepts to screen or to file named = namedentities transformed_concepts = {(ip.tupToIndices(tup[0]), ip.tupToIndices(tup[1])) for tup in concepts} if named == True: transformed_concepts = {(ip.indicesToNames(tup[0], self.objects), ip.indicesToNames(tup[1], self.attributes)) for tup in transformed_concepts} self.writeConcepts(transformed_concepts, outputfile, namedentities=named)
def returnItemsets(self, concepts, namedentities=False): transformed_concepts = {ip.tupToIndices(tup[1]) for tup in concepts} if namedentities == True: transformed_concepts = { frozenset(ip.indicesToNames(tup, self.attributes)) for tup in transformed_concepts } else: transformed_concepts = {frozenset(c) for c in transformed_concepts} return transformed_concepts
def fcaCReturn(fca_context, itemsets, proceed_flag, named, attributes): if proceed_flag == True: if named == True: trans_itemsets = { frozenset(ip.indicesToNames(tup, attributes)) for tup in itemsets } else: trans_itemsets = {frozenset(c) for c in itemsets} return FCAoutput(concepts=set(), context=fca_context, naming=named, itemsets=trans_itemsets) else: return "FCA done. Stopping."
def copyCfcaOutput2File(concept_file, names, outputfile=sys.stdout, namedentities=False): itemsets = parseFimiConceptFile(concept_file) if namedentities == True: itemsets_named = {ip.indicesToNames(e, names) for e in itemsets} else: itemsets_named = itemsets if outputfile != sys.stdout: output = open(outputfile, 'w') else: output = sys.stdout #print(itemsets_named) preamble = ['Named:' + str(namedentities) + '\n'] body = ['#'.join([str(i) for i in item]) + '\n' for item in itemsets_named] filecontent = ''.join(preamble + body) print(filecontent, file=output) if output != sys.stdout: output.close()