def test(self, model):
        self.model = model

        self.beliefs = []
        self.partitions = util.generatePossiblePartitions(self.word, self.pronunciation)
        for p in self.partitions:
            prop = 1.0
            for k, f in p:
                if k in model:
                    prop *= model[k].prob(f)
            self.beliefs.append(prop)
        util.normalize_vector(self.beliefs)

        heuritics = util.omegaHeuristics(self.partitions)

        beliefMatrix = sorted([(belief, heuritics[i], i) for i, belief in enumerate(self.beliefs)], reverse=True)
        self.bestPartition = self.partitions[beliefMatrix[0][2]]
        if len(beliefMatrix) == 1:
            self.confidence = 10.0
        else:
            self.confidence = beliefMatrix[0][0] - beliefMatrix[1][0]

        self.correctAnswer = True
        for k, f in self.bestPartition:
            if self.mapping[k] != f:
                self.correctAnswer = False
                break
    def __init__(self, kanji, furigana, verticesMap):
        self.word = kanji
        self.pronunciation = furigana

        self.partitions = util.generatePossiblePartitions(kanji, furigana)
        self.allKanji = []
        for k, _ in self.partitions[0]:
            self.allKanji.append(k)

        self._verticesMap = verticesMap  # store a pointer to the the map of all vertices 
        self.omegas = []
        # self.omegas = util.omegaHeuristics(self.partitions)
        self.bestPartition = None
def testWordPartition():
    alltuples = []

    with codecs.open('tuples.txt', 'r', encoding='utf-8') as f:
        def _converter(line):
            kanji, furigana = line.split()
            return (kanji, furigana)
        alltuples = map(_converter, f.readlines())

    for kanji, furigana in alltuples:
        partitions = util.generatePossiblePartitions(kanji, furigana)
        print u'--- (%s %s) ---' % (kanji, furigana)
        for p in partitions:
            print ' '.join(map(lambda t: '%s:%s' % (t[0], t[1]), p))
        print
    def baseline_test(self):
        self.partitions = util.generatePossiblePartitions(self.word, self.pronunciation)
        self.beliefs = util.omegaHeuristics(self.partitions)
        util.normalize_vector(self.beliefs)

        beliefMatrix = sorted([(belief, i) for i, belief in enumerate(self.beliefs)], reverse=True)
        self.bestPartition = self.partitions[beliefMatrix[0][1]]
        if len(beliefMatrix) == 1:
            self.confidence = 10.0
        else:
            self.confidence = beliefMatrix[0][0] - beliefMatrix[1][0]

        self.correctAnswer = True
        for k, f in self.bestPartition:
            if self.mapping[k] != f:
                self.correctAnswer = False
                break