Apache Tika 的 GUI 实用程序提供了一个选项,用于获取给定文档或 URL 的主要内容(格式文本和结构化文本除外)。我只想知道哪个方法负责提取docs/url的主要内容。这样我就可以将该方法合并到我的程序中。还有他们在从 HTML 页面中提取数据时是否使用任何启发式算法。因为有时在提取的内容中,我看不到广告。
更新:我发现BoilerPipeContentHandler对此负责。
Apache Tika 的 GUI 实用程序提供了一个选项,用于获取给定文档或 URL 的主要内容(格式文本和结构化文本除外)。我只想知道哪个方法负责提取docs/url的主要内容。这样我就可以将该方法合并到我的程序中。还有他们在从 HTML 页面中提取数据时是否使用任何启发式算法。因为有时在提取的内容中,我看不到广告。
更新:我发现BoilerPipeContentHandler对此负责。
Tika GUI 中的“主要内容”功能是使用BoilerpipeContentHandler类实现的,该类依赖于boilerpipe 库来完成繁重的工作。
我相信这是由BodyContentHandler提供的,它只获取文档正文的 HTML 内容。如果需要,这还可以与其他处理程序组合以仅返回正文的纯文本。
public String[] tika_autoParser() {
String[] result = new String[3];
try {
InputStream input = new FileInputStream(new File(path));
ContentHandler textHandler = new BodyContentHandler();
Metadata metadata = new Metadata();
AutoDetectParser parser = new AutoDetectParser();
ParseContext context = new ParseContext();
parser.parse(input, textHandler, metadata, context);
result[0] = "Title: " + metadata.get(metadata.TITLE);
result[1] = "Body: " + textHandler.toString();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (TikaException e) {
e.printStackTrace();
}
return result;
}