使用命名实体识别的问题

问题描述

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 (将#修改为@)