Spaces:
Running
Running
File size: 2,330 Bytes
c07b97b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
from document_qa.document_qa_engine import TextMerger
def test_merge_passages_small_chunk():
merger = TextMerger()
passages = [
{
'text': "The quick brown fox jumps over the tree",
'coordinates': '1'
},
{
'text': "and went straight into the mouth of a bear.",
'coordinates': '2'
},
{
'text': "The color of the colors is a color with colors",
'coordinates': '3'
},
{
'text': "the main colors are not the colorw we show",
'coordinates': '4'
}
]
new_passages = merger.merge_passages(passages, chunk_size=10, tolerance=0)
assert len(new_passages) == 4
assert new_passages[0]['coordinates'] == "1"
assert new_passages[0]['text'] == "The quick brown fox jumps over the tree"
assert new_passages[1]['coordinates'] == "2"
assert new_passages[1]['text'] == "and went straight into the mouth of a bear."
assert new_passages[2]['coordinates'] == "3"
assert new_passages[2]['text'] == "The color of the colors is a color with colors"
assert new_passages[3]['coordinates'] == "4"
assert new_passages[3]['text'] == "the main colors are not the colorw we show"
def test_merge_passages_big_chunk():
merger = TextMerger()
passages = [
{
'text': "The quick brown fox jumps over the tree",
'coordinates': '1'
},
{
'text': "and went straight into the mouth of a bear.",
'coordinates': '2'
},
{
'text': "The color of the colors is a color with colors",
'coordinates': '3'
},
{
'text': "the main colors are not the colorw we show",
'coordinates': '4'
}
]
new_passages = merger.merge_passages(passages, chunk_size=20, tolerance=0)
assert len(new_passages) == 2
assert new_passages[0]['coordinates'] == "1;2"
assert new_passages[0][
'text'] == "The quick brown fox jumps over the tree and went straight into the mouth of a bear."
assert new_passages[1]['coordinates'] == "3;4"
assert new_passages[1][
'text'] == "The color of the colors is a color with colors the main colors are not the colorw we show"
|