コード例 #1
0
ファイル: dataset.py プロジェクト: Pinafore/qb
    def all_questions(self) -> Dict[int, BonusQuestion]:
        questions = {}
        c = self._conn.cursor()
        c.execute('select * from text where page != ""')
        question_parts = defaultdict(dict)
        for qid, number, _, text, page, answer, _ in c:
            question_parts[int(qid)][int(number)] = (text, page, answer)
        bonus_questions = dict()
        for qnum, parts in question_parts.items():
            if not set(parts.keys()) == {0,1,2}:
                # log.info('skipping {}, missing question parts'.format(qnum))
                continue
            # transpose
            parts = list(zip(*[parts[i] for i in [0,1,2]]))
            bonus_questions[qnum] = BonusQuestion(qnum, parts[0], parts[1], parts[2])

        c = self._conn.cursor()
        c.execute('select * from questions')
        extra_parts = dict()
        for qnum, tour, leadin, _, fold in c:
            qnum = int(qnum)
            if qnum not in bonus_questions:
                continue
            bonus_questions[qnum].leadin = leadin
            bonus_questions[qnum].fold = fold
        return bonus_questions
コード例 #2
0
    def all_questions(self) -> Dict[int, BonusQuestion]:
        questions = {}
        c = self._conn.cursor()
        c.execute('select * from text where page != ""')
        question_parts = defaultdict(dict)
        for qid, number, _, text, page, answer, _ in c:
            question_parts[int(qid)][int(number)] = (text, page, answer)
        bonus_questions = dict()
        for qnum, parts in question_parts.items():
            if not set(parts.keys()) == {0, 1, 2}:
                # log.info('skipping {}, missing question parts'.format(qnum))
                continue
            # transpose
            parts = list(zip(*[parts[i] for i in [0, 1, 2]]))
            bonus_questions[qnum] = BonusQuestion(qnum, parts[0], parts[1],
                                                  parts[2])

        c = self._conn.cursor()
        c.execute('select * from questions')
        extra_parts = dict()
        for qnum, tour, leadin, _, fold in c:
            qnum = int(qnum)
            if qnum not in bonus_questions:
                continue
            bonus_questions[qnum].leadin = leadin
            bonus_questions[qnum].fold = fold
        return bonus_questions
コード例 #3
0
    def answer_map(self):
        c = self._conn.cursor()
        command = 'select answer, page from questions ' + \
            'where page != ""'
        c.execute(command)

        d = defaultdict(Counter)
        for answer, page in c:
            d[answer][page] += 1

        return d
コード例 #4
0
    def normalized_answers(self):
        """
        Return a dictionary with the most unmatched pages
        """

        c = self._conn.cursor()
        command = 'select answer, page from questions '
        c.execute(command)

        answers = defaultdict(list)
        for aa, page in c:
            normalized = self.normalize_answer(aa)
            answers[normalized].append((aa, page))
        return answers
コード例 #5
0
    def all_answers(self):
        """
        Return a lookup from IDs to pages
        """
        answers = {}
        c = self._conn.cursor()
        command = "select id, page from questions where page != ''"
        c.execute(command)

        for qid, page in c:
            answers[int(qid)] = page

        for q in self.expo_questions:
            answers[q.qnum] = q.page
        return answers
コード例 #6
0
ファイル: quiz_bowl.py プロジェクト: Agnon1573/qb
    def query(self, command: str, arguments) -> Dict[str, Question]:
        questions = {}
        c = self._conn.cursor()
        command = 'select id, page, category, answer, ' + \
            'tournament, naqt, protobowl, fold ' + command
        c.execute(command, arguments)

        for qnum, page, _, answer, tournaments, naqt, protobowl, fold in c:
            questions[qnum] = Question(qnum, answer, None, naqt, protobowl, tournaments, page, fold)

        for q in self.expo_questions:
            questions[q.qnum] = q

        for qnum in questions:
            command = 'select sent, raw from text where question=? order by sent asc'
            c.execute(command, (qnum, ))
            for sentence, text in c:
                questions[qnum].add_text(sentence, text)

        return questions
コード例 #7
0
ファイル: quiz_bowl.py プロジェクト: Agnon1573/qb
    def prune_text(self):
        """
        Remove sentences that do not have an entry in the database
        """

        c = self._conn.cursor()
        command = 'select id from questions group by id'
        c.execute(command)
        questions = set(x for x in c)

        c = self._conn.cursor()
        command = 'select question from text group by question'
        c.execute(command)
        text = set(x for x in c)

        orphans = text - questions

        c = self._conn.cursor()
        for ii in orphans:
            command = 'delete from text where question=%i' % ii
            c.execute(command)
        log.info("Keeping %i Pruning %i" % (len(questions - orphans), len(orphans)))
        self._conn.commit()