pub trait DiscontinuousNERTrait: Send + Sync {
// Required method
fn extract_discontinuous(
&self,
text: &str,
entity_types: &[&str],
threshold: f32,
) -> Result<Vec<DiscontinuousEntity>, Error>;
}Expand description
Support for discontinuous entity spans.
§Motivation
Not all entities are contiguous text spans. In coordination structures, entities can be discontinuous - scattered across non-adjacent positions.
§Examples of Discontinuous Entities
"New York and Los Angeles airports"
^^^^^^^^ ^^^^^^^^^^^ ^^^^^^^^
└──────────────────────────┘
LOCATION: "New York airports" (discontinuous!)
^^^^^^^^^^^ ^^^^^^^^
└───────────┘
LOCATION: "Los Angeles airports" (contiguous)
"protein A and B complex"
^^^^^^^^^ ^^^ ^^^^^^^^^
└────────────────────┘
PROTEIN: "protein A ... complex" (discontinuous!)§NER Complexity Hierarchy
| Type | Description | Example |
|---|---|---|
| Flat | Non-overlapping spans | “John works at Google” |
| Nested | Overlapping spans | “[New [York] City]” |
| Discontinuous | Non-contiguous | “New York and LA [airports]” |
§Research Alignment
From W2NER (arXiv:2112.10070):
“Named entity recognition has been involved with three major types, including flat, overlapped (aka. nested), and discontinuous NER… we propose a novel architecture to model NER as word-word relation classification.”
W2NER achieves this by building a handshaking matrix where each cell (i, j) indicates whether tokens i and j are part of the same entity.
§Example
ⓘ
use anno::DiscontinuousNER;
fn extract_complex_entities(ner: &dyn DiscontinuousNER, text: &str) {
let types = &["location", "protein"];
let entities = ner.extract_discontinuous(text, types, 0.5).unwrap();
for e in entities {
if e.is_contiguous() {
println!("Contiguous {}: '{}'", e.entity_type, e.text);
} else {
println!("Discontinuous {}: '{}' spans: {:?}",
e.entity_type, e.text, e.spans);
}
}
}Required Methods§
Sourcefn extract_discontinuous(
&self,
text: &str,
entity_types: &[&str],
threshold: f32,
) -> Result<Vec<DiscontinuousEntity>, Error>
fn extract_discontinuous( &self, text: &str, entity_types: &[&str], threshold: f32, ) -> Result<Vec<DiscontinuousEntity>, Error>
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".