net.sf.jabb.util.text
Class KeywordMatcher

java.lang.Object
  extended by net.sf.jabb.util.text.KeywordMatcher
All Implemented Interfaces:
Serializable

public class KeywordMatcher
extends Object
implements Serializable

To check which keywords a text matches, and for each matched keyword how many occurrences are found.
检查文本当中匹配了哪些关键词,以及每个被匹配到的关键词出现了多少次。

Author:
Zhengmao HU (James)
See Also:
Serialized Form

Field Summary
protected  StringStartWithMatcher matcher
           
 
Constructor Summary
KeywordMatcher(KeywordMatcher toBeCopied)
          Constructs a copy which has exactly the same matching definition as the original one.
创建一个副本,这个副本与原先的对象具有完全相同匹配方式定义。
KeywordMatcher(Map<String,? extends Object> keywordDefinitions)
          Constructs a matcher object with specified keywords; When creating internal data structure, choose to consume more memory for better matching speed.
根据关键词列表,创建一个匹配器; 在创建内部数据结构的时候,选择占用更多内存,而换取速度上的提升。
KeywordMatcher(Map<String,? extends Object> keywordDefinitions, boolean moreSpaceForSpeed)
          Constructs a matcher object with specified keywords.
根据关键词列表,创建一个匹配器。
 
Method Summary
 Map<Object,org.apache.commons.lang.mutable.MutableInt> match(CharSequence text)
          Do the matching test, find out which keywords can be matched, and how many occurrences of each keyword can be found.
进行匹配,返回所匹配上的关键词,以及匹配的次数。
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

matcher

protected StringStartWithMatcher matcher
Constructor Detail

KeywordMatcher

public KeywordMatcher(KeywordMatcher toBeCopied)
Constructs a copy which has exactly the same matching definition as the original one.
创建一个副本,这个副本与原先的对象具有完全相同匹配方式定义。

Parameters:
toBeCopied - original object
原本

KeywordMatcher

public KeywordMatcher(Map<String,? extends Object> keywordDefinitions)
Constructs a matcher object with specified keywords; When creating internal data structure, choose to consume more memory for better matching speed.
根据关键词列表,创建一个匹配器; 在创建内部数据结构的时候,选择占用更多内存,而换取速度上的提升。

Parameters:
keywordDefinitions - Keywords and their associated attachment as identifier.
关键词以及与之对应的结果标识附件对象。

KeywordMatcher

public KeywordMatcher(Map<String,? extends Object> keywordDefinitions,
                      boolean moreSpaceForSpeed)
Constructs a matcher object with specified keywords.
根据关键词列表,创建一个匹配器。

Parameters:
keywordDefinitions - Keywords and their associated attachment as identifier.
关键词以及与之对应的结果标识附件对象。
moreSpaceForSpeed - Whether or not to consume more memory for better matching speed.
是否占用更多内存,而换取速度上的提升。
Method Detail

match

public Map<Object,org.apache.commons.lang.mutable.MutableInt> match(CharSequence text)
Do the matching test, find out which keywords can be matched, and how many occurrences of each keyword can be found.
进行匹配,返回所匹配上的关键词,以及匹配的次数。

Parameters:
text - the text string to be tested
待匹配的文本
Returns:
For all the keywords that can be found in the text, return their attachments (as the Key in the Map) and occurrences count (as the Value in the Map).
返回匹配上的全部关键词所对应的attachment(在Map的Key中),以及它们出现的次数(在Map的Value中)。


Copyright © 2012. All Rights Reserved.