Esempio n. 1
0
    def test_gematria_filter(self):
        """Expected to filter words based on gematria."""
        value = 10
        query = search.search(self.session, gematria=value)
        for test in query:
            self.assertTrue(test.gematria, hebrew.gematria(test.hebrew))

        value = [10, 20]
        query = search.search(self.session, gematria=value)
        for test in query:
            gematria = hebrew.gematria(test.hebrew)
            self.assertTrue(10 == gematria or
                            20 == gematria)
Esempio n. 2
0
    def test_gematria(self):
        """Expected to compute gematria."""
        test = hebrew.gematria(u'בְּ/רֵאשִׁית')
        expected = 2 + 200 + 1 + 300 + 10 + 400
        self.assertEqual(test, expected)

        test = hebrew.gematria(u'מַת')
        expected = 40 + 400
        self.assertEqual(test, expected)

        test = hebrew.gematria(u'מִי')
        expected = 40 + 10
        self.assertEqual(test, expected)
Esempio n. 3
0
def save(session, name, counts):
    """Saves the contents of a book.

    Args:
        session (session): database session
        name (str): the name of the book
        counts (dict): unparsed words mapped to frequency counts
    """
    logger.info(MSG_SAVING, name)

    db_book = db.Book(name=name)

    progress = Progress(len(counts)).start()
    for i, (stripped, (frequency, uni_word)) in enumerate(counts.iteritems()):
        progress.update(i)

        # check if word appeared in different book
        db_word = session.query(db.Word)\
                         .filter_by(hebrew=stripped)\
                         .first()

        if not db_word:  # first occurrence of word ever
            groups = hebrew.clusters(uni_word)
            syllables = hebrew.syllabify(groups=groups, strict=True)
            syllables_hatafs = hebrew.syllabify(groups=groups, strict=False)
            db_word = db.Word(hebrew=stripped,
                              shemot=hebrew.isshemot(uni_word),
                              gematria=hebrew.gematria(stripped),
                              syllables=str(syllables),
                              syllen=len(syllables),
                              syllen_hatafs=len(syllables_hatafs))

        db_rel = db.Occurrence(frequency=frequency)
        db_rel.word = db_word
        db_book.words.append(db_rel)  # pylint: disable=E1101

    session.add(db_book)
    session.commit()

    progress.end()
    logger.info(MSG_SAVED, name)