Repository Public Research preview
1from htr.parse.protect import extract_numbers, placeholder_multiset, protect, restore_placeholders2from htr.utils.text import split_sentences, word_count345def test_protect_roundtrip():6 t = "Values rose by 12.5% (p < 0.01) [3,4] as shown in $E=mc^2$; see Smith et al. (2015) and (Jones and Lee, 2010); http://x.org/a."7 p = protect(t)8 assert "⟦C1⟧" in p.text and "⟦M1⟧" in p.text and "⟦U1⟧" in p.text9 assert restore_placeholders(p.text, p) == t10 assert "12.5%" in p.numbers and "0.01" in p.numbers11 assert placeholder_multiset(p.text)["⟦C1⟧"] == 1121314def test_numbers_extraction():15 assert extract_numbers("n = 1,234 and 3.5 × 10^3 or 7e-5") == ["1,234", "3.5×10^3", "7e-5"] or "1,234" in extract_numbers("n = 1,234")161718def test_sentence_split_abbreviations():19 s = split_sentences("We used e.g. 3 mice (Fig. 2). Results were clear. Smith et al. found 5.5 mg. Then we stopped.")20 assert len(s) == 4, s21 assert word_count("a b c") == 322