こんにちは、Apache tika を使用していくつかの html ファイルをクロールし、テキスト コンテンツをテキスト ファイルに書き込みます。コンテンツをテキスト ファイルに書き込むと、いくつかの空白といくつかの異なる記号が表示されるため、解析しようとしたときに opennlp チャンキング パーサーを使用します。これらのファイル行は、ParserTool.parseLine
単語以外の行に対して以下のコードでエラーが発生しています。
InputStream is = new FileInputStream("en-parser-chunking.bin");
ParserModel model = new ParserModel(is);
opennlp.tools.parser.Parser parser = ParserFactory.create(model);
File dir = new File("C://htmlmetadata");
File listDir[] = dir.listFiles();
System.out.println("no of files:"+listDir.length);
for (int i = 0; i < listDir.length; i++)
{
String path=listDir[i].getAbsolutePath();
System.out.println("file name"+listDir[i].getName());
Scanner scanner = new Scanner(new FileInputStream(path), "UTF-8");
while (scanner.hasNextLine())
{
String line=scanner.nextLine();
if(line!=null)
{
Parse topParses[] = ParserTool.parseLine(line, parser, 1);
for (Parse p : topParses)
{
p.show();
}
System.out.println("line in if"+line);
System.out.println("line length in if"+line.length());
}
}
}
line.length>0 をチェックしてみましたが、行の長さが 0 より大きいため機能しませんが、いくつかの特殊文字が含まれているため、単語が含まれている行を取得することをお勧めします。
ありがとう