Skip to main content

Lattice

Struct Lattice 

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

Lattice 구조

입력 텍스트의 모든 형태소 분석 후보를 담는 격자 구조입니다.

§메모리 최적화

  • nodes 벡터는 재사용을 위해 clear() 시 용량 유지
  • ends_at, starts_at도 용량 유지하여 재할당 최소화

Implementations§

Source§

impl Lattice

Source

pub fn new(text: &str) -> Self

새 Lattice 생성

§Arguments
  • text - 분석할 텍스트
§Example
use mecab_ko_core::lattice::Lattice;

let lattice = Lattice::new("안녕하세요");
assert_eq!(lattice.text(), "안녕하세요");
Source

pub fn text(&self) -> &str

분석용 텍스트 반환 (공백 제거됨)

Source

pub fn original_text(&self) -> &str

원본 텍스트 반환

Source

pub fn original_byte_pos(&self, stripped_char_pos: usize) -> usize

Map a stripped-text char position to the corresponding byte offset in the original (space-included) text.

Source

pub fn char_len(&self) -> usize

문자 개수

Source

pub fn char_pos_from_start_and_byte_len( &self, start_pos: usize, byte_len: usize, ) -> usize

특정 위치에서 시작하는 바이트 오프셋을 주어진 바이트 길이만큼 더한 뒤 해당 위치의 문자 인덱스를 반환합니다.

start_pos의 바이트 시작 위치에 byte_len을 더한 결과에 대응하는 문자 인덱스를 binary search로 빠르게 구합니다. 이를 통해 entry.surface.chars().count() 비용을 줄일 수 있습니다.

Source

pub const fn byte_len(&self) -> usize

바이트 길이

Source

pub fn node_count(&self) -> usize

노드 개수 (BOS, EOS 포함)

Source

pub fn bos(&self) -> &Node

BOS 노드 참조

Source

pub fn eos(&self) -> &Node

EOS 노드 참조

Source

pub fn eos_mut(&mut self) -> &mut Node

EOS 노드 가변 참조

Source

pub fn node(&self, id: NodeId) -> Option<&Node>

ID로 노드 참조

Source

pub fn node_mut(&mut self, id: NodeId) -> Option<&mut Node>

ID로 노드 가변 참조

Source

pub fn nodes(&self) -> impl Iterator<Item = &Node>

모든 노드 반복자

Source

pub fn nodes_ending_at(&self, pos: usize) -> impl Iterator<Item = &Node>

특정 위치에서 끝나는 노드들

Source

pub fn nodes_starting_at(&self, pos: usize) -> impl Iterator<Item = &Node>

특정 위치에서 시작하는 노드들

Source

pub fn add_node(&mut self, builder: NodeBuilder) -> NodeId

노드 추가

§Arguments
  • builder - NodeBuilder로 구성된 노드 정보
§Returns

추가된 노드의 ID

Source

pub fn substring(&self, start: usize, end: usize) -> &str

문자 위치에서 부분 문자열 추출

Source

pub fn has_space_at(&self, char_pos: usize) -> bool

특정 위치에 띄어쓰기가 있는지 확인

Source

pub fn clear(&mut self)

Lattice 초기화 (노드 재사용)

Source

pub fn reset(&mut self, text: &str)

새 텍스트로 Lattice 재설정

Source

pub fn best_path(&self) -> Vec<&Node>

최적 경로 추출 (Viterbi 실행 후 호출)

EOS에서 BOS까지 역추적하여 최적 경로의 노드들을 반환합니다.

Source§

impl Lattice

Source

pub fn stats(&self) -> LatticeStats

통계 정보 계산

Source

pub fn memory_usage(&self) -> usize

메모리 사용량 추정 (바이트)

Lattice가 사용하는 대략적인 메모리 크기를 반환합니다.

Trait Implementations§

Source§

impl Debug for Lattice

Source§

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

Formats the value using the given formatter. 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> 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, 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.