def getAttribute(self, _name): i = 0 for i in range(0, len(self.__attributes)): if (Attribute(self.__attributes[i]).getName() == _name): break if (i == len(self.__attributes)): return None return Attribute(self.__attributes[i])
def searchUndefPosition(self, attToDel): undefCount = 0, count = 0 att_aux = Attribute(self.__attributes[count]) while (attToDel != att_aux): if (att_aux.getDirectionAttribute() == Attribute.DIR_NOT_DEF): undefCount += 1 count += 1 att_aux = Attribute(self.__attributes[count]) return undefCount
def removeAttribute(self, inputAtt, whichAtt): atToDel = None if (inputAtt and (whichAtt >= len(self._inputAttr) or whichAtt < 0)): return False if (self.__inputAtt and (whichAtt >= len(self.__outputAttr) or whichAtt < 0)): return False if (inputAtt): #inputAttribute atToDel = Attribute(self.__inputAttr[whichAtt]) atToDel.setDirectionAttribute(Attribute.DIR_NOT_DEF) self.__inputAttr.removeElementAt(whichAtt) else: #output attribute atToDel = Attribute(self.__outputAttr[whichAtt]) atToDel.setDirectionAttribute(Attribute.DIR_NOT_DEF) self.__outputAttr.removeElementAt(whichAtt) #We get the position where it has to go in the undefined attributes vector. self.__undefPosition = self.searchUndefPosition(atToDel) self.__undefinedAttr.insertElementAt(atToDel, self.__undefPosition) self.__hasNominal = False self.__hasInteger = False self.__hasReal = False for index in (0, 2): iterations = 0 if (index == 0): iterations = len(self.__inputAttr) else: iterations = len(self.__outputAttr) for i in range(0, iterations): if (index == 0): att = Attribute(self.__inputAttr[i]) else: att = Attribute(self.__outputAttr[i]) attTypeHere = att.getType() if (attTypeHere == Attribute.NOMINAL): self.__hasNominal = True elif (attTypeHere == Attribute.INTEGER): self.__hasInteger = True elif (attTypeHere == Attribute.REAL): self.__hasReal = True return True
def getInputAttributes(self): if (len(self.__inputAttr) == 0): return None attr = Attribute[len(self.__inputAttr)] for i in range(0, len(attr)): attr[i] = Attribute(self.__inputAttr[i]) return attr
def getUndefinedAttributes(self): if (len(self.undefinedAttr) == 0): return None attr = [Attribute() for x in range (0, len(self.undefinedAttr))] for i in range(0,attr.length): attr[i] = self.undefinedAttr[i] return attr
def getInputAttributes(self): if (len(self.inputAttr) == 0) : return None attr = [Attribute() for x in range (0, len(self.inputAttr))] for i in range (0, len(attr)): attr[i] = self.inputAttr[i] return attr
def getAttributesExcept(self, v): restAt = [] for i in range(0, len(self.__attributes)): attName = Attribute(self.__attributes[i]).getName() if (attName not in v): restAt.append(attName) return restAt
def getUndefinedAttributes(self): if (len(self.__undefinedAttr) == 0): return None attr = Attribute[len(self.__undefinedAttr)] for i in range(0, attr.length): attr[i] = Attribute(self.__undefinedAttr[i]) return attr
def areAllDefinedAsInputs(self, inputNames): if (len(inputNames) != len(self.__inputAttr)): return False for i in range(0, len(self.__inputAttr)): input_name = Attribute(self.inputAttr[i]).getName() if (input_name not in inputNames): return False return True
def setOutputInputAttributes(self, inAttNames, outAttNames): i = 0 attName = "" att = Attribute() for i in range(0, len(self.__attributes)): att = Attribute(self.__attributes[i]) attName = att.getName() if (attName in inAttNames): att.setDirectionAttribute(Attribute.INPUT) self.__inputAttr.append(self.__attributes[i]) elif (attName in outAttNames): att.setDirectionAttribute(Attribute.OUTPUT) self.__outputAttr.append(self.__attributes[i]) else: self.__undefinedAttr.append(self.__attributes[i]) #Finally, making some statistics self.__hasNominal = False self.__hasInteger = False self.__hasReal = False for index in range(0, 2): if (index == 0): iterations = len(self._inputAttr) else: iterations = len(self._outputAttr) for i in range(0, iterations): if (index == 0): att = Attribute(self._inputAttr[i]) else: att = Attribute(self._outputAttr[i]) if (att.getType() == Attribute.NOMINAL): self.__hasNominal = True elif (att.getType() == Attribute.INTEGER): self.__hasInteger = True elif (att.getType() == Attribute.REAL): self.__hasReal = True
def getOutputAttributes(self): print("get Output Attributes in Attributes begin.......") if len(self.outputAttr) == 0: print("The output attributes are 0:") return None else: attr= [Attribute() for x in range(0,len(self.outputAttr))] for i in range(0,len(self.outputAttr)): attr[i]=self.outputAttr[i] return self.outputAttr
def getInputHeader(self): aux = "@inputs " ending = "," inputLength = len(self.__inputAttr) for i in range(0, inputLength): if i == (inputLength - 1): ending = "" aux += (Attribute(self.__inputAttr[i])).getName() + ending return aux
def areAllDefinedAsOutputs(self, outputNames): if (outputNames.size() != len(self.__outputAttr)): return False for i in range(0, len(self.__outputAttr)): out_put_name = Attribute(self._outputAttr[i]).getName() if (out_put_name not in outputNames): return False return True
def getOutputHeader(self): aux = "@outputs " ending = "," out_put_att_length = len(self.__outputAttr) for i in range(0, out_put_att_length): if (i == out_put_att_length - 1): ending = "" aux += (Attribute(self.outputAttr[i]).getName()) + ending return aux
def printInsAttr(self): print("@relation = " + self.__relationName) print("Number of attributes: " + str(len(self.__attributes))) for i in range(0, len(self.__attributes)): att = Attribute(self.__attributes[i]) if (att.getDirectionAttribute() == Attribute.INPUT): print(" > INPUT ATTRIBUTE: ") elif (att.getDirectionAttribute() == Attribute.OUTPUT): print(" > OUTPUT ATTRIBUTE: ") else: print(" > UNDEFINED ATTRIBUTE: ") att.printAttr()
def insertAttribute(self,line): print("Insert attribute begin :") indexL = 0 indexR = 0 attType = "" # Treating string and declaring a string tokenizer if "{" in line: token_str = "{" elif "[" in line: token_str = "[" token_withT= "\t" + token_str line=line.replace(token_str,token_withT) print("token_double is:" + token_withT + ", line is :" + line) # System.out.println (" > Processing line: "+ line ); #st = line.split(" [{\t"); st = line.split("\t")# first we need to split the attribute line into two part , attribute name and attribute values print("word in st are as below: ") for word in st: print(word) # Disregarding the first token. It is @attribute st[0] = st[0].replace("@attribute","").strip() # delete @attribute print("st[0] is:" + st[0]) first_part=st[0].split() at = Attribute() # print("Get type once get instance object, at.getType() = " + str(type_string)) at.setName(first_part[0]) print("att set name as first_part[0] is:" + first_part[0]) # print( "Attribute name: "+ at.getName() ) # to get the class name values we need to split the second part of the attribute line, to get values of attribute # Next action depends on the type of attribute: continuous or nominal if (len(st)==1): # Parsing a nominal attribute with no definition of values print("Parsing nominal attribute without values: setType=0") #print("Get type =" + at.getType()) at.setType(Attribute.NOMINAL) elif ( "{" in line): # this because it is the class values line print("Parsing nominal attribute with values: "+line ) #print("Get type =" + at.getType()) print("Before setType = 0") at.setType(Attribute.NOMINAL) print("after setType= 0") at.setFixedBounds(True) indexL = line.index("{")+1 #print("indexL: " + indexL ) indexR = line.index("}") #print("indexR: " + str(indexR)) print("indexL : " + str(indexL)+"indexR : " +str(indexR)) #print( "The Nominal values are: " + line[indexL: indexR]); lineSub = line[indexL: indexR] print("The lineSub : " + lineSub) st2 = lineSub.split(",") for nominalStr in st2: at.addNominalValue(nominalStr.strip()) else: # Parsing an integer or real attType = first_part[1].lower() print("attribute Name : " + str(first_part[0]) + ", attribute type = "+ str(attType)) # System.out.println (" > Parsing "+ type + " attributes"); if (attType == "integer"): at.setType(Attribute.INTEGER) print("set integer type") if (attType == "real"): at.setType(Attribute.REAL) print("set real type") indexL = line.index("[") indexR = line.index("]") print("indexL is: "+ str(indexL)+ " indexR: "+str(indexR)) if (indexL !=-1 and indexR !=- 1): # System.out.println ( " > The real values are: " + line.substring( indexL+1, indexR) ); lineSub = line[indexL + 1: indexR] print("lineSub: " + lineSub) st2 = lineSub.split(",") print("st2[0].strip() :" + st2[0]) print("st2[1].strip() :"+st2[1]) minBound = float(st2[0].strip()) maxBound = float(st2[1].strip()) print("Before at.setBounds(minBound, maxBound): ( "+ str(minBound) + " , " + str(maxBound) + " )") at.setBounds(minBound, maxBound) print("Before add attribute :::: ") Attributes.addAttribute(Attributes,at) print("insertAttribute is finished :::: ")
def finishStatistics(self): if (len(self.__outputAttr) != 1): return for i in range(0, len(self.__inputAttr)): Attribute(self.__inputAttr[i]).finishStatistics()
def getOutputAttribute(self, pos): if (pos < 0 or pos >= len(self._outputAttr)): return None return Attribute(self._outputAttr[pos])
def getAttributes(self): if (len(self.__attributes) == 0): return None attr = Attribute[len(self.__attributes)] for i in range(0, len(attr)): attr[i] = Attribute(self.__attributes[i])
def getAttribute(self, pos): return Attribute(self.__attributes[pos])
def getUndefinedAttribute(self, pos): if (pos < 0 or pos >= len(self.__undefinedAttr)): return None return Attribute(self.undefinedAttr[pos])