Struct jieba_rs::TextRank

source ·
pub struct TextRank { /* private fields */ }
Expand description

Text rank keywords extraction.

Requires textrank feature to be enabled.

Implementations§

source§

impl TextRank

source

pub fn new(span: usize, config: KeywordExtractConfig) -> Self

Creates an TextRank.

§Examples

New instance with custom stop words. Also uses hmm for unknown words during segmentation.

   use std::collections::BTreeSet;
   use jieba_rs::{TextRank, KeywordExtractConfig};

   let stop_words : BTreeSet<String> =
       BTreeSet::from(["a", "the", "of"].map(|s| s.to_string()));
   TextRank::new(
       5,
       KeywordExtractConfig::default());

Trait Implementations§

source§

impl Debug for TextRank

source§

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

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

impl Default for TextRank

source§

fn default() -> Self

Creates TextRank with 5 Unicode Scalar Value spans

source§

impl KeywordExtract for TextRank

source§

fn extract_keywords( &self, jieba: &Jieba, sentence: &str, top_k: usize, allowed_pos: Vec<String> ) -> Vec<Keyword>

Uses TextRank algorithm to extract the top_k keywords from sentence.

If allowed_pos is not empty, then only terms matching those parts if speech are considered.

§Examples
   use jieba_rs::{Jieba, KeywordExtract, TextRank};

   let jieba = Jieba::new();
   let keyword_extractor = TextRank::default();
   let mut top_k = keyword_extractor.extract_keywords(
       &jieba,
       "此外,公司拟对全资子公司吉林欧亚置业有限公司增资4.3亿元,增资后,吉林欧亚置业注册资本由7000万元增加到5亿元。吉林欧亚置业主要经营范围为房地产开发及百货零售等业务。目前在建吉林欧亚城市商业综合体项目。2013年,实现营业收入0万元,实现净利润-139.13万元。",
       6,
       vec![String::from("ns"), String::from("n"), String::from("vn"), String::from("v")],
   );
   assert_eq!(
       top_k.iter().map(|x| &x.keyword).collect::<Vec<&String>>(),
       vec!["吉林", "欧亚", "置业", "实现", "收入", "子公司"]
   );

   top_k = keyword_extractor.extract_keywords(
       &jieba,
       "It is nice weather in New York City. and今天纽约的天气真好啊,and京华大酒店的张尧经理吃了一只北京烤鸭。and后天纽约的天气不好,and昨天纽约的天气也不好,and北京烤鸭真好吃",
       3,
       vec![],
   );
   assert_eq!(
       top_k.iter().map(|x| &x.keyword).collect::<Vec<&String>>(),
       vec!["纽约", "天气", "不好"]
   );

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.