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 return str or False. The pre_filter function is applied to every Word in the window before building the query. If set to None, 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 of Word.

enrich_doc(doc: Document) None[source]#

Find spans in doc.

Parameters:
doc: Document

The document in which to find spans.

find_span(sentence: Sentence, idx_word: int) Span[source]#

Find the span in sentence given starting index of Word.

Parameters:
sentence: Sentence

Sentence in which to find span.

idx_word: ind

The index of the word from which to start finding.