Public API
The public API is organized around two Polars expression namespaces plus configurable clinical-context algorithms.
Contents
[!IMPORTANT] Import
polars_cnlpbefore using.cnlpor.rdw. The import registers these Polars expression namespaces and may appear unused to editors or linters.import polars as pl import polars_cnlp # noqa: F401 # registers .cnlp and .rdw namespaces
Clinical NLP expressions
| Method | Input | Output | Typical use |
|---|---|---|---|
cnlp.contains |
regex | Boolean |
Does the note mention a pattern? |
cnlp.count |
regex | UInt32 |
Count one concept |
cnlp.count_all |
mapping | Struct[UInt32] |
Count named concepts |
cnlp.affirmed |
regex | Boolean/null |
Is one concept affirmed? |
cnlp.affirmed_any |
sequence or mapping | Boolean/null |
Is any requested concept affirmed? |
cnlp.affirmed_all |
sequence or mapping | Boolean/null |
Are all requested concepts affirmed? |
cnlp.affirmed_each |
mapping | Struct[Boolean] |
Status for every named concept |
cnlp.find_best |
regex or mapping | Struct/null |
Best contextualized finding |
cnlp.find_all |
regex or mapping | List[Struct]/null |
All contextualized findings |
Algorithms and rules
| Class | Purpose |
|---|---|
ConText |
Default multi-dimensional contextual interpretation |
NegEx |
NegEx-style fixed-window contextual interpretation |
RuleBased |
Custom rule-based algorithm |
ContextEffect |
Assertion, temporality, and/or experiencer change |
ContextRule |
Directional contextual modifier |
TerminateRule |
Stop modifier scope |
PseudoRule |
Suppress an overlapping modifier |
RuleSet |
Immutable collection of rules |
Research-data-wrangling expressions
| Method | Input | Output | Typical use |
|---|---|---|---|
rdw.starts_with_any |
literal prefixes | Boolean |
Match code or identifier families |
rdw.ends_with_any |
literal suffixes | Boolean |
Match suffix families or file types |
Import
import polars as pl
import polars_cnlp
Algorithm configuration classes are imported separately:
from polars_cnlp.algorithms import (
ConText,
ContextEffect,
ContextRule,
NegEx,
PseudoRule,
RuleBased,
RuleSet,
TerminateRule,
)
The .cnlp and .rdw namespaces are expression APIs, so their methods compose with ordinary Polars select,
with_columns, filter, and lazy pipelines.