如何查看 Pocketsphinx 词典中是否存在单词?
How to see if word exists in Pocketsphinx dictionary?
我只是想看看某个字符串是否存在于字典文件中。 (问题底部的字典文件)
我想检查语音识别器是否可以识别单词。例如,识别器将无法识别字符串 ahdfojakdlfafiop
,因为字典中没有定义它。那么,我可以检查一个词是否在 pocktsphinx 词典中吗?
类似于:
if(myString.existsInDictionary){
startListeningBecauseExists();
}else(
//Doesn't exist in dictionary!!!
}
我只是想要一种方法来判断识别器是否可以听我想让它听的内容。
这是词典文件:
谢谢,
鲁奇尔
使用BufferedReader
读取文件并将所有单词存储在ArrayList
中
ArrayList<String> dictionary = new ArrayList<>();
String line;
BufferedReader reader = new BufferedReader(new FileReader(dictionaryFile));
while((line = reader.readLine()) != null) {
if(line.trim().length() <= 0 ) {
continue;
}
String word = line.split(" ")[0].trim();
word = word.replaceAll("[^a-zA-Z]", "");
dictionary.add(word);
}
然后使用
检查dictionary
中是否存在单词
dictionary.contains(yourString);
希望对您有所帮助。
您可以通过逐行读取字典并将其加载到数组列表中,并只获取单词 do
arraylist.add(line.split("\s+")[0]);
然后通过
检查是否存在
if(arraylist.contains(word))
在 C 中有 ps_lookup_word 函数可以让你查找单词:
if (ps_lookup_word(ps, "abc") == NULL) {
// do something
}
在 Java 包装器中它是一个方法 Decoder.lookupWord
:
if(decoder.lookupWord("abc") == null) {
// do something
}
在Android中,您可以从Recognizer
访问解码器:
if(recognizer.getDecoder().lookupWord("abc") == null) {
// do something
}
我只是想看看某个字符串是否存在于字典文件中。 (问题底部的字典文件)
我想检查语音识别器是否可以识别单词。例如,识别器将无法识别字符串 ahdfojakdlfafiop
,因为字典中没有定义它。那么,我可以检查一个词是否在 pocktsphinx 词典中吗?
类似于:
if(myString.existsInDictionary){
startListeningBecauseExists();
}else(
//Doesn't exist in dictionary!!!
}
我只是想要一种方法来判断识别器是否可以听我想让它听的内容。
这是词典文件:
谢谢,
鲁奇尔
使用BufferedReader
读取文件并将所有单词存储在ArrayList
ArrayList<String> dictionary = new ArrayList<>();
String line;
BufferedReader reader = new BufferedReader(new FileReader(dictionaryFile));
while((line = reader.readLine()) != null) {
if(line.trim().length() <= 0 ) {
continue;
}
String word = line.split(" ")[0].trim();
word = word.replaceAll("[^a-zA-Z]", "");
dictionary.add(word);
}
然后使用
检查dictionary
中是否存在单词
dictionary.contains(yourString);
希望对您有所帮助。
您可以通过逐行读取字典并将其加载到数组列表中,并只获取单词 do
arraylist.add(line.split("\s+")[0]);
然后通过
检查是否存在if(arraylist.contains(word))
在 C 中有 ps_lookup_word 函数可以让你查找单词:
if (ps_lookup_word(ps, "abc") == NULL) {
// do something
}
在 Java 包装器中它是一个方法 Decoder.lookupWord
:
if(decoder.lookupWord("abc") == null) {
// do something
}
在Android中,您可以从Recognizer
访问解码器:
if(recognizer.getDecoder().lookupWord("abc") == null) {
// do something
}