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

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

Moved orange to Orange (part 2)

Line 
1# Description: Shows different ways for constructing orange.Example and conversion to native Python objects
2# Category:    basic classes
3# Classes:     Example
4# Uses:        lenses
5# Referenced:  Example.htm
6
7import orange
8data = orange.ExampleTable("lenses")
9domain = data.domain
10
11for attr in domain:
12    print attr.name, attr.values
13
14ex = orange.Example(domain)
15print ex
16
17ex = orange.Example(domain, ["young", "myope", "yes", "reduced", "soft"])
18print ex
19
20ex = orange.Example(domain, ["young", 0, 1, orange.Value(domain[3], \
21                             "reduced"), "soft"])
22print ex
23
24reduced_dom = orange.Domain(["age", "lenses"], domain)
25reduced_ex = orange.Example(reduced_dom, ex)
26print reduced_ex
27
28age = data.domain["age"]
29example = data[0]
30print example[0]
31print example[age]
32print example["age"]
33
34print data[0]
35d = data[0][0]
36example[age] = (int(example[age])+1) % 3
37print data[0]
38if d == data[0][0]:
39    raise Exception("Error in Example: not a reference, but a copy")
40
41print example.native()
42print example.native(0)
43print example.native(1)
44
45e1 = orange.Example(data[0])
46e2 = orange.Example(data[0])
47print e1.compatible(e2)
48e2.setclass((e1.getclass() + 1) % 3)
49print e1.compatible(e2)
50print e1.compatible(e2, False)
51print e1.compatible(e2, True)
Note: See TracBrowser for help on using the repository browser.