Skip to main content

KeywordExtractor

Struct KeywordExtractor 

Source
pub struct KeywordExtractor;
Expand description

关键字抽取器。

对应 Java: org.ofdrw.reader.keyword.KeywordExtractor

在 OFD 文档的文本内容中搜索关键字,返回匹配位置的页面和矩形区域。

注意:Java 版使用 AWT FontRenderContext 计算精确的字符边界, Rust 版使用简化的文本宽度估算。对于精确排版,需要集成外部字体引擎。

Implementations§

Source§

impl KeywordExtractor

Source

pub fn get_keyword_positions( pages: &[OfdPage], keyword: &str, ) -> Vec<KeywordPosition>

获取关键字在文档中的位置列表。

对应 Java: KeywordExtractor.getKeyWordPositionList(OFDReader, String)

搜索所有页面的文本内容,返回包含关键字的矩形区域。

§参数
  • pages: 已解析的页面列表。
  • keyword: 要搜索的关键字。
Source

pub fn get_keyword_positions_with_fonts( pages: &[OfdPage], keyword: &str, font_sizes: &HashMap<String, f64>, ) -> Vec<KeywordPosition>

获取关键字坐标列表(带字体度量的精确版本)。

对应 Java: KeywordExtractor.getKeyWordPositionList(OFDReader, String)

此方法接受字体大小映射表,用于更精确地计算字符宽度。

§参数
  • pages: 已解析的页面列表。
  • keyword: 要搜索的关键字。
  • font_sizes: 字体大小映射(字体 ID -> 字号,单位毫米)。
Source

pub fn get_keyword_positions_from_text_codes( entries: &[TextCodeEntry], keyword: &str, ) -> Vec<KeywordPosition>

从 TextCode 条目列表中搜索关键字位置(支持跨 TextCode 边界匹配)。

对应 Java: KeywordExtractor.getKeyWordPositionList(OFDReader, String[], int[])

此方法接受按阅读顺序排列的 TextCode 条目列表。当关键字被 TextCode 边界切断时(如“电子印章“分属两个 TextCode),算法会拼接相邻 TextCode 的文本内容来定位完整关键字。

§参数
  • entries: 按阅读顺序排列的 TextCode 条目列表。
  • keyword: 要搜索的关键字。
§匹配模式
  1. 普通匹配:关键字完整包含在单个 TextCode 中。
  2. 前缀匹配:当前 TextCode 的内容是关键字的前缀,向后拼接。
  3. 后缀匹配:当前 TextCode 的末尾匹配关键字的开头,向后拼接。

Trait Implementations§

Source§

impl Debug for KeywordExtractor

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