public class Dictionary extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Dictionary.FileLoading |
| Modifier and Type | Method and Description |
|---|---|
static Dictionary |
clear(File path)
从单例缓存中去除
|
static Dictionary |
clear(String path) |
protected void |
finalize() |
static File |
getDefalutPath()
当 words.dic 是从 jar 里加载时, 可能 defalut 不存在
|
File |
getDicPath()
注意:当 words.dic 是从 jar 里加载时,此时 File 可能是不存在的。
|
Map<Character,CharNode> |
getDict()
仅仅用来观察词库.
|
static Dictionary |
getInstance()
从默认目录加载词库文件.
查找默认目录顺序:
从系统属性mmseg.dic.path指定的目录中加载
从classpath/data目录
从user.dir/data目录
|
static Dictionary |
getInstance(File path) |
static Dictionary |
getInstance(String path) |
long |
getLastLoadTime()
最后加载词库的时间
|
CharNode |
head(char ch) |
boolean |
isUnit(Character ch) |
protected File[] |
listWordsFiles()
只要 wordsXXX.dic的文件
|
static int |
load(InputStream fin,
Dictionary.FileLoading loading)
加载词文件的模板
|
boolean |
match(String word)
word 能否在词库里找到
|
int |
maxMatch(char[] sen,
int offset) |
ArrayList<Integer> |
maxMatch(CharNode node,
ArrayList<Integer> tailLens,
char[] sen,
int offset) |
int |
maxMatch(CharNode node,
char[] sen,
int offset) |
static File |
normalizeFile(File file) |
boolean |
reload()
全新加载词库,没有成功加载会回滚。
注意:重新加载时,务必有两倍的词库树结构的内存,默认词库是 50M/个 左右。否则抛出 OOM。
|
int |
search(CharNode node,
char[] sen,
int offset,
int tailLen)
sen[offset] 后 tailLen 长的词是否存在.
|
boolean |
wordsFileIsChange()
词典文件是否有修改过
|
public static Dictionary getInstance()
getDefalutPath()public static Dictionary getInstance(String path)
path - 词典的目录public static Dictionary getInstance(File path)
path - 词典的目录public static Dictionary clear(String path)
clear(File)public static Dictionary clear(File path)
path - public static int load(InputStream fin, Dictionary.FileLoading loading) throws IOException
IOExceptionpublic static File getDefalutPath()
protected void finalize()
throws Throwable
protected File[] listWordsFiles()
public boolean wordsFileIsChange()
public boolean reload()
public boolean match(String word)
public CharNode head(char ch)
public int search(CharNode node, char[] sen, int offset, int tailLen)
CharNode.indexOf(char[], int, int)public int maxMatch(char[] sen,
int offset)
public int maxMatch(CharNode node, char[] sen, int offset)
public ArrayList<Integer> maxMatch(CharNode node, ArrayList<Integer> tailLens, char[] sen, int offset)
public boolean isUnit(Character ch)
public File getDicPath()
public long getLastLoadTime()
Copyright © 2015-2016 Ganshane Developer Team. All Rights Reserved.