使用命名实体识别的问题

时间:2020-10-12 05:15:25

标签: java speech-recognition opennlp named-entity-recognition

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。 请帮助我提供您的见解。

0 个答案:

没有答案