Exemplo n.º 1
0
class Model(QAbstractTableModel):

    counter = Counter()
    COL_NAME = counter.pp()
    COL_VALUE = counter.pp()

    def __init__(self, view):
        QAbstractTableModel.__init__(self)

        self._data = []
        self.view = view
        self.view.setModel(self)
        self.view.setColumnWidth(self.COL_NAME, 300)

    def setClassifier(self, classifier):
        self.classifier = classifier
        self._data = self.classifier.engine.features
        self.reset()

    def columnCount(self, parent=None):
        return self.counter.cnt

    def rowCount(self, parent=None):
        return len(self._data)

    def get(self, viewIdx):
        return self._data[viewIdx]

    def data(self, idx, role=Qt.DisplayRole):
        col = idx.column()

        e = self.get(idx.row())
        if self.classifier.has_data:
            value = self.classifier.features[e]
        else:
            value = None

        if role != Qt.DisplayRole:
            return QVariant()

        if col == self.COL_NAME:
            return QVariant(e)
        if col == self.COL_VALUE:
            return QVariant(value)
        else:
            raise ValueError("Bad column: " + ` col `)

    def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            if col == self.COL_NAME:
                return QVariant("Name")
            elif col == self.COL_VALUE:
                return QVariant("Value")
            else:
                raise ValueError("Bad id: " + ` col `)
        else:
            return QVariant()

    def selectedData(self):
        return self.get(self.view.currentIndex().row())
Exemplo n.º 2
0
class Model(QAbstractTableModel):

    counter = Counter()
    COL_NAME = counter.pp()

    def __init__(self, view, classifiers):
        QAbstractTableModel.__init__(self)

        self._data = list(classifiers)
        self._data.sort(key=lambda x: x.engine.name)

        self.view = view
        self.view.setModel(self)

    def columnCount(self, parent=None):
        return self.counter.cnt

    def rowCount(self, parent=None):
        return len(self._data)

    def idxForName(self, name):
        for i, c in enumerate(self._data):
            if c.engine.name == name:
                return i
        raise ValueError("No entry for " + ` name ` + " in " + ` self._data `)

    def get(self, viewIdx):
        return self._data[viewIdx]

    def data(self, idx, role=Qt.DisplayRole):
        col = idx.column()

        e = self.get(idx.row())

        if role != Qt.DisplayRole:
            return QVariant()

        if col == self.COL_NAME:
            return QVariant(e.engine.name)
        else:
            raise ValueError("Bad column: " + ` col `)

    def headerData(self, col, orientation, role):
        if orientation == Qt.Horizontal and role == Qt.DisplayRole:
            if col == self.COL_NAME:
                return QVariant("Name")
            else:
                raise ValueError("Bad id: " + ` col `)
        else:
            return QVariant()

    def selectedData(self):
        return self.get(self.view.currentIndex().row())
Exemplo n.º 3
0
from PyQt4.QtCore import Qt, QAbstractTableModel, QVariant
from math import exp
from qt_utils import Counter
from confusion_matrix import ConfusionMatrix
counter = Counter()

COL_ESDC_TYPE = counter.pp()
COL_TEXT = counter.pp()
COL_ASSIGNMENT_ID = counter.pp()
COL_LOG_PROBABILITY = counter.pp()
COL_PROBABILITY = counter.pp()
COL_ACTUAL_CLASS = counter.pp()
COL_PREDICTED_CLASS = counter.pp()
COL_TP = counter.pp()
COL_FP = counter.pp()
COL_TN = counter.pp()
COL_FN = counter.pp()
COL_CORRECT = counter.pp()


class Entry:
    def __init__(self, i, crf, obs, threshold=0.5):
        self.i = i
        self.crf = crf
        obs = self.crf.dataset.convert_observation(obs)
        self.obs = obs
        self.threshold = threshold
        self.node = self.obs.node
        self.annotation = self.obs.annotation
        if obs.sdcs != None:
            self.esdc = obs.sdcs[0]
Exemplo n.º 4
0
from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qt_utils import Counter

c = Counter()

COL_FIGURE_TEXT = c.pp()
COL_VERB_TEXT = c.pp()
COL_SPATIAL_RELATION_TEXT = c.pp()
COL_LANDMARK_TEXT = c.pp()
COL_LANDMARK2_TEXT = c.pp()


class Model(QAbstractTableModel):
    def __init__(self, view):
        QAbstractTableModel.__init__(self)
        self.view = view
        self.setAnnotations([])
        view.setModel(self)

    def setAnnotations(self, annotations):
        self._data = annotations
        self.reset()

    def addAnnotation(self, annotation):
        self._data.append(annotation)
        self.reset()

    def deleteAnnotation(self, idx):
        del self._data[idx]