我想要實現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我現在舉了一個例子。 –