Skip to main content

Tagger

Struct Tagger 

Source
pub struct Tagger { /* private fields */ }
Expand description

A Brill-style English part-of-speech tagger.

Each tagger owns its lexicon, so Tagger::extend_lexicon affects only that instance. Construct one with Tagger::new.

use pos_tagger::Tagger;
let tagger = Tagger::new();
let tagged = tagger.tag(&["the", "dog"]);
assert_eq!(tagged, vec![
    ("the".to_string(), "DT".to_string()),
    ("dog".to_string(), "NN".to_string()),
]);

Implementations§

Source§

impl Tagger

Source

pub fn new() -> Self

Create a tagger with the built-in English lexicon.

Source

pub fn tag<S: AsRef<str>>(&self, words: &[S]) -> Vec<(String, String)>

Tag each word in words.

Returns a vector the same length as the input. Each entry pairs the original word with its tag. The input is never modified.

words is any slice whose elements borrow as str, so &[&str], &[String], and the lexer’s Vec<String> output all pass without an intermediate Vec<&str>. Write tagger.tag(&lexer.lex(text)) directly.

Each result pair owns its word as a fresh String. The pair shape is the public contract, so the word is copied out of the borrowed input. Callers that only need tags can read the second field and drop the first.

An empty token tags as NN. It is a lexicon key with an empty tag list, and the empty list falls back to NN instead of panicking.

Source

pub fn word_in_lexicon(&self, word: &str) -> bool

Report whether word is in the lexicon.

Returns true when the exact word is a key or when its lowercase form is a key. The empty string is a key with an empty tag list, so word_in_lexicon("") returns true.

The lexicon is a HashMap, so object member names such as constructor, valueOf, hasOwnProperty, toString, and __proto__ return false unless they are real keys. None of them are. A lookup over a plain object would inherit these names and report true. This crate keeps the HashMap result on purpose.

Source

pub fn extend_lexicon<I>(&mut self, entries: I)
where I: IntoIterator<Item = (String, Vec<String>)>,

Add entries from entries, keeping existing keys untouched.

Only keys absent from the current lexicon are inserted. Existing entries are never overwritten.

entries is any iterable of (word, tags) pairs. A HashMap, a BTreeMap, a Vec, an array, or a map adaptor all work, so callers do not build a HashMap first.

Trait Implementations§

Source§

impl Clone for Tagger

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tagger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tagger

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.