加载标记器时出错(可能缺少模型文件)

问题描述 投票:0回答:1

我正在 Android Studio 中创建一个 Android 应用程序,其中使用斯坦福核心 NLP 和 Jetpack Compose。我在这个平台上找了几个小时,看看是否有人有像我一样的问题,但我还没有找到。 我使用斯坦福 4.5.4.jar、斯坦福模型 4.5.4.jar 和斯坦福模型西班牙语 4.5.4.jar。我将它们存储在视图项目的应用程序文件夹中名为 libs 的源目录中。

fun analyzeAndDisplayTree(sentence: String): String {
    try {
        // Configurar el pipeline
        val props = Properties()
        props.setProperty("annotators", "tokenize, ssplit, pos, parse")
        props.setProperty("tokenize.language", "es")
        props.setProperty("pos.model", "libs/stanford-corenlp-4.5.4-models.jar")
        props.setProperty("parse.model", "libs/stanford-corenlp-4.5.4-models-spanish.jar")
        val pipeline = StanfordCoreNLP(props)

        // Procesar la oración y mostrar el resultado
        val document = pipeline.process(sentence)
        val parsedSentence = document.get(CoreAnnotations.SentencesAnnotation::class.java)[0]
        val tree: Tree = parsedSentence.get(TreeCoreAnnotations.TreeAnnotation::class.java)

        return "Sentence: $parsedSentence\nParse Tree: ${tree.pennString()}"
    } catch (e: Exception) {
        return "Error: ${e.message}"
    }
}

这是我使用 Jetpack Compose 显示它的地方

val analysedSentence = Syntax().analyzeAndDisplayTree(text!!)
Text(text = analysedSentence, modifier = Modifier.size(50.dp).weight(0.25f))

尽管我没有任何内部错误,但当我运行应用程序并按下触发斯坦福操作的按钮时,我收到此错误 -> 加载标记器时出错(可能缺少模型文件)

如果有人能帮助我,我会很高兴!谢谢。

android android-jetpack-compose stanford-nlp
1个回答
0
投票

几乎可以肯定,这意味着标记器模型文件在运行时不存在于指定的路径上。在运行时,您给出的路径:

libs/stanford-corenlp-4.5.4-models.jar
是否可以访问 POS 标注器模型文件?也许你可以尝试先用输出
new File("libs/stanford-corenlp-4.5.4-models.jar").canRead()
之类的东西来检查一下?

© www.soinside.com 2019 - 2024. All rights reserved.