def build(self, data=None, attributeSet=None): if attributeSet is None: # build an attribute set. aa = AttributeSet() for line in data: if line[0] == '@': aa.add(Attribute(line[1:].split('\t'))) return aa else: # build an example set. ee = ExampleSet() for line in data: if type(line) == type(str()): if line[0] == '#': ee.add(Example(line[1:], attributeSet)) #elif type(line) == type(ExampleSet()): # ee.add(line) else: ee.add(line) return ee
def construct(self, data = None, objectClass = None): """ construct() creates data structures -- attributes or examples -- as indicated by the obj variable. Returns an AttributeSet or ExampleSet data structure. data: resource required to construct object. objectClass: indicator for the type of object class to use. Signals construction of ExampleSet. """ if data is None: raise ValueError("No data specified.") elif objectClass is None: a = AttributeSet() for line in data: a.add(Attribute(line.split('\t'))) return a elif objectClass is not None: e = ExampleSet() for line in data: e.add(Example(line, objectClass)) return e else: raise ValueError("Object type needs to be indicated as either 'Attribute' (0) or 'Example' (1).")
def build(self, data = None, attributeSet = None): if attributeSet is None: # build an attribute set. aa = AttributeSet() for line in data: if line[0] == '@': aa.add(Attribute(line[1:].split('\t'))) return aa else: # build an example set. ee = ExampleSet() for line in data: if type(line) == type(str()): if line[0] == '#': ee.add(Example(line[1:], attributeSet)) elif type(line) == type(ExampleSet()): ee.add(line) return ee
def build(self, data=None, attributeSet=None): """ return an AttributeSet or ExampleSet object @param data: input data; raw (textual) attributes or examples @param attributeSet: AttributeSet object required to create ExampleSet objects @return AttributeSet or ExampleSet objects """ # Build an AttributeSet object from raw (text) attributes. if attributeSet is None: attributeSet = AttributeSet() for line in data: # If the line is prefixed with '@', create an Attribute object and add it to the AttributeSet if line[0] == '@': attributeSet.add(Attribute(line[1:].split('\t'))) return attributeSet # Build an ExampleSet object from raw (text) examples and an AttributeSet. else: exampleSet = ExampleSet() # Loop through the data split by newline for line in data: # If the line is a string, check it is an example (prefixed by '#') if type(line) == type(str()): # If the line is an example, create an Example object and add it to the ExampleSet if line[0] == '#': exampleSet.add(Example(line[1:], attributeSet)) # Commented out for the time being 7/13/2016 #else: # exampleSet.add(line) return exampleSet
def build(self, data = None, attributeSet = None): """ return an AttributeSet or ExampleSet object @param data: input data; raw (textual) attributes or examples @param attributeSet: AttributeSet object required to create ExampleSet objects @return AttributeSet or ExampleSet objects """ # Build an AttributeSet object from raw (text) attributes. if attributeSet is None: attributeSet = AttributeSet() for line in data: # If the line is prefixed with '@', create an Attribute object and add it to the AttributeSet if line[0] == '@': attributeSet.add(Attribute(line[1:].split('\t'))) return attributeSet # Build an ExampleSet object from raw (text) examples and an AttributeSet. else: exampleSet = ExampleSet() # Loop through the data split by newline for line in data: # If the line is a string, check it is an example (prefixed by '#') if type(line) == type(str()): # If the line is an example, create an Example object and add it to the ExampleSet if line[0] == '#': exampleSet.add(Example(line[1:], attributeSet)) # Commented out for the time being 7/13/2016 #else: # exampleSet.add(line) return exampleSet
self.values = example[:-1] self.label = example[-1] if __name__ == "__main__": from AttributeSet import AttributeSet from Attribute import Attribute a1 = ["weather", "n", "sunny rainy windy"] a2 = ["people", "n", "none some many"] a3 = ["time", "n", "morning afternoon evening"] d1 = Attribute(a1) d2 = Attribute(a2) d3 = Attribute(a3) aa = AttributeSet() aa.add(d1) aa.add(d2) aa.add(d3) e1 = "sunny some evening" e2 = "rainy many morning" e3 = "windy none morning" x1 = Example(e1, aa) print x1.getLabel() print x1.getValues()
return "{} {}".format(self.data, self.label) if __name__=="__main__": from AttributeSet import AttributeSet from Attribute import Attribute a1 = ["weather", "n", "sunny rainy windy"] a2 = ["people", "n", "none some many"] a3 = ["time", "n", "morning afternoon evening"] d1 = Attribute(a1) d2 = Attribute(a2) d3 = Attribute(a3) aa = AttributeSet() aa.add(d1) aa.add(d2) aa.add(d3) #print aa.toString() print aa.get(0).toString() print aa.get(0).getValues("sunny") e1 = "sunny some evening" e2 = "rainy many morning" e3 = "windy none morning" x1 = Example(e1, aa)
return "{} {}".format(self.data, self.label) if __name__ == "__main__": from AttributeSet import AttributeSet from Attribute import Attribute a1 = ["weather", "n", "sunny rainy windy"] a2 = ["people", "n", "none some many"] a3 = ["time", "n", "morning afternoon evening"] d1 = Attribute(a1) d2 = Attribute(a2) d3 = Attribute(a3) aa = AttributeSet() aa.add(d1) aa.add(d2) aa.add(d3) #print aa.toString() print aa.get(0).toString() print aa.get(0).getValues("sunny") e1 = "sunny some evening" e2 = "rainy many morning" e3 = "windy none morning" x1 = Example(e1, aa)