txt_locate

txt_locate(text, elements)

Find start and end positions of text elements in a larger text.

Parameters

Name Type Description Default
text str A text string to search for elements within it. required
elements List[str] A list of strings to find in text required

Returns

Name Type Description
List[TextSpan] List of TextSpan objects with the first start/end positions of elements in text. The list is the same length as elements

Examples

>>> text = "Hello world! This is a test."
>>> elements = ["world", "test", "notfound"]
>>> loc = txt_locate(text, elements)
>>> loc
[TextSpan(text='world', start=6, end=11), TextSpan(text='test', start=23, end=27), None]