如何解决使用命名实体识别的问题
if (valid) {
speechFinalResult = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION).get(0);
InputStream inputStream = null;
TokenizerModel tokenModel = null;
try {
inputStream = getAssets().open("en-token.bin");
tokenModel = new TokenizerModel(inputStream);
inputStream.close();
} catch (IOException e) {
e.printstacktrace();
}
if (tokenModel != null) {
TokenizerME tokenizer = new TokenizerME(tokenModel);
String paragraph = speechFinalResult;
String tokens[] = tokenizer.tokenize(paragraph);
InputStream locationInputStream = null;
TokenNameFinderModel locationModel = null;
try {
locationInputStream = getAssets().open("en-ner-location.bin");
locationModel = new TokenNameFinderModel(locationInputStream);
} catch (IOException e) {
e.printstacktrace();
}
if (locationModel != null) {
NameFinderME nameFinder = new NameFinderME(locationModel);
Span nameSpans[] = nameFinder.find(tokens);
String result = null;
for (Span s: nameSpans)
//result= s.toString()+" "+tokens[s.getStart()];
result += s.toString();
textView1.setText(result);
setRecognitionProgressMsg(speechFinalResult);
try {
Uri uri = null;
uri = Uri.parse("google.navigation:q=" + result + "&mode=l");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setPackage("com.google.android.apps.maps");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException e) {
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.google.android.apps.maps");
Intent intent = new Intent(Intent.ACTION_VIEW,uri);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
}
}
在这里,我将语音识别器与命名实体识别一起使用,例如:如果我说“我想去金奈” 我的代码必须从给定的句子中识别位置名称,然后导航到该位置。 根据我的代码,我将标记该句子并标识位置名称并将其分配给结果。 并传递该结果进行导航,但是我的代码始终在Google Maps Destination框中显示为null。 请帮助我提供您的见解。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。