mirror of
https://github.com/qurator-spk/dinglehopper.git
synced 2025-06-14 06:09:59 +02:00
🚧 dinglehopper: WIP data structure for extracted text
This commit is contained in:
parent
bc630233d0
commit
4bd30e6686
2 changed files with 19 additions and 16 deletions
|
@ -43,19 +43,3 @@ class ExtractedTextSegment:
|
||||||
if normalize(value, self.normalization) != value:
|
if normalize(value, self.normalization) != value:
|
||||||
raise ValueError('String "{}" is not normalized.'.format(value))
|
raise ValueError('String "{}" is not normalized.'.format(value))
|
||||||
normalization = attr.ib(default=NORM_NFC)
|
normalization = attr.ib(default=NORM_NFC)
|
||||||
|
|
||||||
|
|
||||||
test1 = ExtractedText([
|
|
||||||
ExtractedTextSegment('s0', 'foo'),
|
|
||||||
ExtractedTextSegment('s1', 'bar'),
|
|
||||||
ExtractedTextSegment('s2', 'bazinga')
|
|
||||||
], ' ')
|
|
||||||
|
|
||||||
|
|
||||||
assert test1.text == 'foo bar bazinga'
|
|
||||||
assert test1.segment_id_for_pos(0) == 's0'
|
|
||||||
assert test1.segment_id_for_pos(3) == None
|
|
||||||
assert test1.segment_id_for_pos(10) == 's2'
|
|
||||||
|
|
||||||
# ExtractedTextSegment('foo', unicodedata.normalize('NFD', 'Schlyñ'))
|
|
||||||
ExtractedTextSegment('foo', unicodedata.normalize('NFC', 'Schlyñ'))
|
|
||||||
|
|
19
extracted_text_test.py
Normal file
19
extracted_text_test.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from extracted_text import *
|
||||||
|
|
||||||
|
def test_text():
|
||||||
|
test1 = ExtractedText([
|
||||||
|
ExtractedTextSegment('s0', 'foo'),
|
||||||
|
ExtractedTextSegment('s1', 'bar'),
|
||||||
|
ExtractedTextSegment('s2', 'bazinga')
|
||||||
|
], ' ')
|
||||||
|
|
||||||
|
|
||||||
|
assert test1.text == 'foo bar bazinga'
|
||||||
|
assert test1.segment_id_for_pos(0) == 's0'
|
||||||
|
assert test1.segment_id_for_pos(3) is None
|
||||||
|
assert test1.segment_id_for_pos(10) == 's2'
|
||||||
|
|
||||||
|
# TODO handle grapheme cluster positions?
|
||||||
|
|
||||||
|
# ExtractedTextSegment('foo', unicodedata.normalize('NFD', 'Schlyñ'))
|
||||||
|
ExtractedTextSegment('foo', unicodedata.normalize('NFC', 'Schlyñ'))
|
Loading…
Add table
Add a link
Reference in a new issue