コード例 #1
0
ファイル: TestSearch.py プロジェクト: metaist/hebphonics
    def test_shemot_filter(self):
        """Expected to filter out shemot."""
        query = search.search(self.session, shemot=False)
        for test in query:
            self.assertFalse(hebrew.isshemot(test.hebrew))

        query = search.search(self.session, shemot=True)
        expected = [hebrew.isshemot(test.hebrew) for test in query]
        self.assertTrue(sum(expected) > 0, 'expected at least one name of G-d')
コード例 #2
0
ファイル: TanachParser.py プロジェクト: metaist/hebphonics
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)
コード例 #3
0
ファイル: TestHebrew.py プロジェクト: metaist/hebphonics
    def test_isshemot(self):
        """Expected to correctly identify names of G-d."""
        test = u'אֱלֹהִים'
        self.assertTrue(hebrew.isshemot(test))

        test = u'בֵאלֹהִים'
        self.assertTrue(hebrew.isshemot(test))

        test = u'אֱלוֹהֵי'
        self.assertTrue(hebrew.isshemot(test))

        test = u'אֱלוֹהַי'
        self.assertTrue(hebrew.isshemot(test))

        test = u'אֵל'
        self.assertTrue(hebrew.isshemot(test))

        test = u'אֵלַי'
        self.assertFalse(hebrew.isshemot(test), 'should not match')