我想要实现KrovetzStemmer为我下载的页面整合一个词干。我有最大的问题是我不能简单地用给定的文档使用body().text()
,然后干所有的话。究其原因是因为我需要href
链接不应在所有梗。所以我想,也许如果我能与href
环节得到身体,然后我可以HREF拆分,然后使用一个LinkedHashMap
作为Element
和布尔或会指定Element
无论是文字或链接枚举类型。与Jsoup
所以问题是假设给定的HTML
<!DOCTYPE html>
<html>
<body>
<h1> This is the heading part. This is for testing purposes only.</h1>
<a href="http://www.firstsite.com/this is a sub directory/">First Link</a>
<p>This is the first paragraph to be considered.</p>
<a href="http://www.secondsite.com/it is the correct page/">Second Link</a>
<p>This is the second paragraph to be considered.</p>
<img border="0" src="/images/pulpit.jpg" alt="Pulpit rock" width="304" height="228">
<a href="http://www.thirdsite.com">Third Link</a>
</body>
</html>
我想只能够得到这样的:
This is the heading part. This is for testing purposes only.
<a href="http://www.firstsite.com/this is a sub directory/">First Link</a>
This is the first paragraph to be considered.
<a href="http://www.secondsite.com/it is the correct page/">Second Link</a>
This is the second paragraph to be considered.
<a href="http://www.thirdsite.com">Third Link</a>
然后将它们分割,然后插入到LinkedHashMap
所以如果我做是这样的:
int i = 1;
for (Entry<Element, Boolean> entry : splitedList.getEntry()) {
if(!entry.getValue()) { System.out.println(i + ": " + entry.getKey());}
i++;
}
然后将打印:
1: This is the heading part. This is for testing purposes only.
3: This is the first paragraph to be considered.
5: This is the second paragraph to be considered.
这样我就可以应用词干并保持迭代顺序。
现在,我不知道如何实现这个,因为我不知道如何:
一)获取正文与href
链接仅
B)拆分体(我知道有我们总是可以使用字符串split()
,但我正在谈论的是页面正文的元素)
我将如何能够完成上述两件事?
而且我也不太清楚我的解决方案是一个很好的解决与否。有更好/更简单的方法来做到这一点?
如需更好的帮助,请尝试添加输入示例和预期输出/结果,并附上一些解释,为什么会这样。 – Pshemo
@Pshemo我现在举了一个例子。 –