jieba_rs

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

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.