Exemple #1
0
    def commit(self):
        rows = self.tableView.selectionModel().selectedRows()
        rows = [self.proxyModel.mapToSource(index) for index in rows]
        rows = [index.row() for index in rows]
        selectedRules = [self.classifier.rules[row] for row in rows]

        if selectedRules:
            examples = self.classifier.examples
            selectedExamples = self.selectedExamplesFromRules(
                selectedRules, self.classifier.examples)
            selectedAttrs = self.selectedAttrsFromRules(selectedRules)
            selectedAttrs = [
                attr for attr in examples.domain.attributes
                if attr in selectedAttrs
            ]  # restore the order
            if self.selectedAttrsOnly:
                domain = orange.Domain(selectedAttrs, examples.domain.classVar)
                domain.addmetas(examples.domain.getmetas())
                selectedExamples = orange.ExampleTable(domain,
                                                       selectedExamples)
            else:
                selectedExamples = orange.ExampleTable(selectedExamples)

            self.send("Data", selectedExamples)
            self.send("Features", orange.VarList(list(selectedAttrs)))

        else:
            self.send("Data", None)
            self.send("Features", None)

        self.changedFlag = False
Exemple #2
0
 def test_reverse(self):
     self.l.reverse()
     self.ll.reverse()
     self.assertEqual(self.l, self.ll)
     empty = orange.VarList()
     empty.reverse()
     self.assertEqual(empty, [])
     self.assertFalse(empty)
Exemple #3
0
 def test_pop(self):
     self.assertEqual(self.l.pop(), self.ll.pop())
     self.assertEqual(self.l, self.ll)
     ll = tv("a")
     l = orange.VarList(ll)
     self.assertEqual(l.pop(), ll.pop())
     self.assertFalse(l, ll)
     with self.assertRaises(IndexError):
         l.pop()
Exemple #4
0
    def sendOutput(self):
        if len(self.matrix.items) < 1:
            return

        selectedIndices = []
        tmp = []

        if len(self.selection.getSelection()) == 0:
            self.send("Attribute List", None)
            self.send("Examples", None)
        else:
            selection = self.selection.getSelection()

            for sel in selection:
                x1, y1 = sel.x(), sel.y()
                x2, y2 = x1 + sel.width(), y1 + sel.height()

                if (len(self.distanceMap.elementIndices) == 0):
                    tmp += list(range(x1, x2))
                    tmp += list(range(y1, y2))
                else:
                    tmp += list(
                        range(self.distanceMap.elementIndices[x1],
                              self.distanceMap.elementIndices[x2]))
                    tmp += list(
                        range(self.distanceMap.elementIndices[y1],
                              self.distanceMap.elementIndices[y2]))

            for i in tmp:
                if self.distanceMapConstructor.order:
                    if not (self.distanceMapConstructor.order[i]
                            in selectedIndices):
                        selectedIndices += [
                            self.distanceMapConstructor.order[i]
                        ]

                if not (i in selectedIndices):
                    selectedIndices += [i]

            items = self.matrix.items
            if issubclass(orange.EnumVariable, type(items[0])):
                selected = orange.VarList()
                for i in selectedIndices:
                    selected.append(items[i])
                self.send("Attribute List", selected)

            if isinstance(items[0], orange.Example):
                ex = [items[x] for x in selectedIndices]
                selected = orange.ExampleTable(items[0].domain, ex)
                self.send("Examples", selected)
Exemple #5
0
 def commit(self):
     if self.examples:
         selected = self.selectAttributes()
         varList = [self.classifier.examples.domain[s] for s in selected]
         if self.SelectedAttrOnly:
             domain = orange.Domain(
                 varList + [self.classifier.examples.domain.classVar])
             domain.addmetas(self.classifier.examples.domain.getmetas())
             examples = orange.ExampleTable(domain, self.examples)
         else:
             examples = orange.ExampleTable(self.examples)
         self.send("Examples", examples)
         self.send("Attribute List", orange.VarList(varList))
     else:
         self.send("Examples", None)
         self.send("Attribute List", None)
Exemple #6
0
 def test_repeat(self):
     self.assertEqual(self.l * 3, self.ll * 3)
     self.assertEqual(orange.VarList([]) * 3, [])
Exemple #7
0
 def test_empty(self):
     l = orange.VarList()
     self.assertEqual(len(l), 0)
     l = orange.VarList([])
     self.assertEqual(len(l), 0)
Exemple #8
0
 def setUp(self):
     self.ll = tv("abcde")
     self.l = orange.VarList(self.ll)