Skip to main content

SpacePenalty

Struct SpacePenalty 

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

띄어쓰기 패널티 설정

mecab-ko의 left-space-penalty-factor 기능을 구현합니다. 띄어쓰기 직후에 특정 품사가 오면 페널티를 부여하여 오분석을 방지합니다.

§Example

use mecab_ko_core::viterbi::SpacePenalty;

// mecab-ko 기본 설정
let penalty = SpacePenalty::korean_default();

// dicrc 형식에서 생성
let penalty = SpacePenalty::from_dicrc("1785,6000;1786,6000");

Implementations§

Source§

impl SpacePenalty

Source

pub fn new() -> Self

빈 페널티 설정 생성

Source

pub fn korean_default() -> Self

한국어 기본 페널티 설정

조사(JK*)와 어미(E*)가 띄어쓰기 직후 나타나면 높은 페널티를 부여합니다. 이는 “아버지가방에” → “아버지가 방에“로 분석하는 데 도움이 됩니다.

Source

pub fn from_dicrc(config: &str) -> Self

mecab-ko의 dicrc 설정에서 생성

§Format

left_id,penalty;left_id,penalty;...

§Example
use mecab_ko_core::viterbi::SpacePenalty;

let penalty = SpacePenalty::from_dicrc("1785,6000;1786,6000;1787,5000");
assert_eq!(penalty.get(1785), 6000);
assert_eq!(penalty.get(1786), 6000);
assert_eq!(penalty.get(9999), 0);  // 미등록
Source

pub fn add(&mut self, left_id: u16, penalty: i32)

페널티 추가

Source

pub fn get(&self, left_id: u16) -> i32

특정 품사 ID에 대한 페널티 조회

§Returns

해당 ID에 설정된 페널티, 없으면 0

Source

pub fn is_empty(&self) -> bool

페널티가 설정되어 있는지 확인

Source

pub fn len(&self) -> usize

설정된 페널티 개수

Trait Implementations§

Source§

impl Clone for SpacePenalty

Source§

fn clone(&self) -> SpacePenalty

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SpacePenalty

Source§

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

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

impl Default for SpacePenalty

Source§

fn default() -> SpacePenalty

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.