skillner.matchers.SlidingWindowMatcher#
- class skillner.matchers.SlidingWindowMatcher(query_method: Callable[[str], dict], max_window_size: int = 4, pre_filter: Callable[[Word], str] | None = None)[source]#
Sliding Window matcher class.
A matcher that uses sliding/shrinking window algorithm to find spans in sentence.
- Parameters:
- query_method: Callable[[str], dict]
A function that takes a string as entry, aka. the query, and returns a response as dictionary if the query matches and
None
otherwise.- max_window_size: int, default=4
The maximum number of words to consider when constructing the query.
- pre_filter: Callable[[Word], str], default=None
A function that takes a
Word
as input and returnstr
orFalse
. Thepre_filter
function is applied to everyWord
in the window before building the query. If set toNone
, the query is build using the string form the words in window.
- __init__(query_method: Callable[[str], dict], max_window_size: int = 4, pre_filter: Callable[[Word], str] | None = None) None [source]#
Methods
__init__
(query_method[, max_window_size, ...])enrich_doc
(doc)Find spans in
doc
.find_span
(sentence, idx_word)Find the span in
sentence
given starting index ofWord
.