示例#1
0
 def contiguous_verses():
     assert passage.init(
         [reference.init('Genesis', 1, 2),
          reference.init('Genesis', 1, 1)]) == [
              passage.Data('Genesis 1:1-2', [
                  reference.init('Genesis', 1, 1),
                  reference.init('Genesis', 1, 2)
              ], None)
          ]
示例#2
0
 def single_verse():
     assert passage.text([
         passage.Data('Genesis 1:2', [reference.init('Genesis', 1, 2)],
                      None)
     ]) == [
         passage.Data(
             'Genesis 1:2', [reference.init('Genesis', 1, 2)],
             'The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters.'
         )
     ]
示例#3
0
 def duplicates():
     assert passage.init([
         reference.init('Genesis', 1, 2),
         reference.init('Genesis', 1, 2),
         reference.init('Genesis', 1, 1)
     ]) == [
         passage.Data('Genesis 1:1-2', [
             reference.init('Genesis', 1, 1),
             reference.init('Genesis', 1, 2)
         ], None)
     ]
示例#4
0
 def multiple_verses():
     assert passage.text([
         passage.Data('Genesis 1:2-3', [
             reference.init('Genesis', 1, 2),
             reference.init('Genesis', 1, 3)
         ], None)
     ]) == [
         passage.Data(
             'Genesis 1:2-3', [
                 reference.init('Genesis', 1, 2),
                 reference.init('Genesis', 1, 3)
             ],
             '2 The earth was without form and void, and darkness was over the face of the deep. And the Spirit of God was hovering over the face of the waters.\n3 And God said, "Let there be light," and there was light.'
         )
     ]
示例#5
0
 def multiple_chapters():
     assert passage.init([
         reference.init('Genesis', 1, 5),
         reference.init('Genesis', 1, 2),
         reference.init('Genesis', 3, 12),
         reference.init('Genesis', 3, 10),
         reference.init('Genesis', 1, 1)
     ]) == [
         passage.Data('Genesis 1:1-2,5', [
             reference.init('Genesis', 1, 1),
             reference.init('Genesis', 1, 2),
             reference.init('Genesis', 1, 5)
         ], None),
         passage.Data('Genesis 3:10,12', [
             reference.init('Genesis', 3, 10),
             reference.init('Genesis', 3, 12)
         ], None),
     ]
示例#6
0
    def describe_tf_idf():
        blank = None

        topic_1_id = 'topic_1_id'
        topic_2_id = 'topic_2_id'

        passage1 = passage.init([reference.init('Genesis', 1, 2)])[0]
        passage2 = passage.init([reference.init('Exodus', 5, 1)])[0]
        passage3 = passage.init([reference.init('John', 3, 16)])[0]

        sample = [
            cluster_result.ClusterResult(0.5, 'sd281x', blank, blank,
                                         [passage1]),
            cluster_result.ClusterResult(0.25, 'ds432a', blank, blank,
                                         [passage2, passage3])
        ]

        passage_to_topic_ids = {
            passage1.name: [topic_1_id],
            passage2.name: [topic_1_id, topic_2_id],
            passage3.name: [topic_2_id]
        }

        def to_tf_idf_topics():
            result = cluster_result.to_tf_idf_topics(sample,
                                                     passage_to_topic_ids)

            assert result == [[(topic_1_id, 1 * math.log(3 / 2))],
                              [(topic_1_id, 1 * math.log(3 / 2)),
                               (topic_2_id, 2 * math.log(3 / 2))]]

        def to_mean_weighted_tf_idf_topics():
            result = cluster_result.to_mean_weighted_tf_idf_topics(
                sample, passage_to_topic_ids)
            mean = lambda values: sum(values) / float(len(values))
            print(result)

            assert result == [
                (topic_2_id, 0.25 * 2 * math.log(3 / 2)),
                (topic_1_id,
                 mean([0.5 * 1 * math.log(3 / 2), 0.25 * 1 * math.log(3 / 2)]))
            ]
示例#7
0
 def mixed_verses():
     assert passage.init([
         reference.init('Genesis', 1, 5),
         reference.init('Genesis', 1, 2),
         reference.init('Genesis', 1, 1)
     ]) == [
         passage.Data('Genesis 1:1-2,5', [
             reference.init('Genesis', 1, 1),
             reference.init('Genesis', 1, 2),
             reference.init('Genesis', 1, 5)
         ], None)
     ]
示例#8
0
 def _from_chapters(pair):
     chapter, verses = pair
     return map(lambda verse: to_maybe(ref.init(book, chapter, verse)),
                verses)
示例#9
0
 def multiple_books():
     assert passage.init([
         reference.init('Genesis', 1, 5),
         reference.init('Genesis', 1, 2),
         reference.init('Exodus', 5, 3),
         reference.init('Genesis', 3, 12),
         reference.init('Revelation', 1, 1),
         reference.init('Genesis', 3, 10),
         reference.init('Genesis', 1, 1)
     ]) == [
         passage.Data('Genesis 1:1-2,5', [
             reference.init('Genesis', 1, 1),
             reference.init('Genesis', 1, 2),
             reference.init('Genesis', 1, 5)
         ], None),
         passage.Data('Genesis 3:10,12', [
             reference.init('Genesis', 3, 10),
             reference.init('Genesis', 3, 12)
         ], None),
         passage.Data('Exodus 5:3', [reference.init('Exodus', 5, 3)], None),
         passage.Data('Revelation 1:1',
                      [reference.init('Revelation', 1, 1)], None)
     ]