source: orange/Orange/doc/reference/example3.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 1.4 KB checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1# Description: Shows some more uses for meta-attributes with orange.Example
2# Category:    basic classes, meta-attributes
3# Classes:     Example
4# Uses:        lenses
5# Referenced:  Example.htm
6
7import orange, random
8random.seed(0)
9
10data = orange.ExampleTable("lenses")
11
12#id2 = orange.newmetaid()
13#w2 = orange.FloatVariable("ww")
14#The below two lines fail (and SHOULD fail):
15#data[0].setmeta(id, orange.Value(ww, 2.0))
16#data[0].setmeta(id2, "2.0")
17
18ok_id = orange.newmetaid()
19ok = orange.EnumVariable("ok?", values=["no", "yes"])
20
21data[0][ok_id] = orange.Value(ok, "yes")
22
23data.domain.addmeta(ok_id, ok)
24
25data[0][ok_id] = "yes"
26data[0][ok] = "no"
27data[0]["ok?"] = "no"
28
29no_yes = [orange.Value(ok, "no"), orange.Value(ok, "yes")]
30for example in data:
31    example.setvalue(no_yes[random.randint(0, 1)])
32
33print data[0][ok_id]
34print data[0][ok]
35print data[0]["ok?"]
36
37data[0].removemeta(ok_id)
38data[1].removemeta(ok)
39data[2].removemeta("ok?")
40
41w = orange.FloatVariable("w")
42w_id = orange.newmetaid()
43data.domain.addmeta(w_id, w)
44data[0].setweight(w, 1)
45data[1].setweight("w", 2)
46data[2].setweight(w_id, 3)
47data[3].setweight(0, 4)
48data[4].setweight(None, 5)
49
50print "Some weights..."
51for example in data[:6]:
52    print example
53
54data[0].removeweight(w)
55data[1].removeweight("w")
56data[2].removeweight(w_id)
57data[3].removeweight(0)
58data[4].removeweight(None)
59
60print "\n\n... and without them"
61for example in data[:6]:
62    print example
63
Note: See TracBrowser for help on using the repository browser.