在Android中读取POS标签模型 [英] Reading POS tag models in Android

查看:65
本文介绍了在Android中读取POS标签模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在普通的Java应用程序上使用 openNLP POS模型进行POS标记.现在,我想在Android平台上实现它.我不确定Android的要求或限制是什么,因为我无法读取模型(二进制文件)并无法正确执行POS标记.

I have tried doing POS tagging using openNLP POS Models on a normal Java application. Now I would like to implement it on Android platform. I am not sure what is the Android requirement or restrictions as I am not able to read the models (binary file) and execute the POS tagging properly.

我尝试从外部存储中获取.bin文件并将其放入外部库中,但仍然无法正常工作.这些是我的代码:

I tried getting the .bin file from external storage as well as putting it in an external libraries but still it couldn't work. These are my codes:

InputStream modelIn = null;
POSModel model = null;

String path = Environment.getExternalStorageDirectory().getPath() + "/TextSumIt/en-pos-maxent.bin";

modelIn = new BufferedInputStream( new FileInputStream(path));
model = new POSModel(modelIn);

我得到的错误:

11-15 06:39:35.072: W/System.err(565): opennlp.tools.util.InvalidFormatException: The profile data stream has an invalid format!
11-15 06:39:35.177: W/System.err(565):  at opennlp.tools.dictionary.serializer.DictionarySerializer.create(DictionarySerializer.java:224)
11-15 06:39:35.177: W/System.err(565):  at opennlp.tools.postag.POSDictionary.create(POSDictionary.java:282)
11-15 06:39:35.182: W/System.err(565):  at opennlp.tools.postag.POSModel$POSDictionarySerializer.create(POSModel.java:48)
11-15 06:39:35.182: W/System.err(565):  at opennlp.tools.postag.POSModel$POSDictionarySerializer.create(POSModel.java:44)
11-15 06:39:35.182: W/System.err(565):  at opennlp.tools.util.model.BaseModel.<init>(BaseModel.java:135)
11-15 06:39:35.197: W/System.err(565):  at opennlp.tools.postag.POSModel.<init>(POSModel.java:93)
11-15 06:39:35.197: W/System.err(565):  at com.main.textsumit.SummarizationActivity.postagWords(SummarizationActivity.java:676)
11-15 06:39:35.205: W/System.err(565):  at com.main.textsumit.SummarizationActivity.generateSummary(SummarizationActivity.java:252)
11-15 06:39:35.205: W/System.err(565):  at com.main.textsumit.SummarizationActivity.onCreate(SummarizationActivity.java:127)

是什么原因导致无法正确读取模型?我应该如何解决呢?请帮忙.

What is it that cause it not reading the model properly? And how should I resolve this? Please help.

谢谢.

推荐答案

对于它的价值,如果仍然存在问题:尝试在其他环境(非Android)中使用POS模型时,我遇到了类似的问题,在我的情况下,似乎是从bin文件中提取失败,而不是模型本身.它似乎在存档中的tag.tagdict文件本地(如此处建议 http://sharpnlp.codeplex .com/discussions/263620 ),因此,如果您目前不需要(并且我在简单情况下也不需要),请尝试将其从存档中删除. (但是请保留存档的原样,因为它将以zip格式保存.)

For what it's worth, if this is still an issue: I had a similar issue attempting to use the POS model in a different context (non-Android), and in my case it appeared to be the extraction failing from the bin file, not anything with the model itself. It appears to be local to the tags.tagdict file in the archive (as suggested here http://sharpnlp.codeplex.com/discussions/263620), so if you don't need that currently (and I didn't for my simple scenarios) then try removing it from the archive. (But leave the archive intact as it's expected to arrive in zip'd form.)

这篇关于在Android中读取POS标签模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆