生活随笔
收集整理的這篇文章主要介紹了
高亮标红
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
簡單實用,哈哈。
轉載原文地址:點擊這里
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
public class Highlighter {public static void main(String[] args)
throws IOException {String content =
"挖掘頻繁項集的方法可以擴展到挖掘閉頻繁項集(由它們容易導出頻繁項集的集合)。這些方法結合了附加的優化技術,如項合并、子項剪枝和項跳過,以及模式樹中產生的項集的有效子集檢查。"+
"挖掘頻繁項集和關聯已經用不同的方法擴展,包括挖掘多層關聯規則和多維關聯規則。多層關聯規則可以根據每個抽象層的最小支持度閾值如何定義,使用多種策略挖掘。如一致的支持度、遞減的支持度和基于分組的支持度。"+
"冗余的多層(后代)關聯規則可以刪除,如果根據其對應的祖先規則,他們的支持度和置信度接近于期望值的話。挖掘多維關聯規則的技術可以根據對量化屬性的處理分為若干類。第一,量化屬性可以根據預定義的概念分層靜態離散化。"+
"數據立方體非常適合這種方法,因為數據立方體和量化屬性都可以利用概念分層。第二,可以挖掘量化關聯規則,其中量化屬性根據分箱和/或聚類動態離散化,“鄰近的”關聯規則可以用聚類合并,產生更簡潔、更有意義的規則。"+
"基于約束的規則挖掘允許用戶通過提供元規則(即模式模板)和其他挖掘約束對規則搜索聚焦。這種挖掘推動了說明性數據挖掘查詢語言和用戶界面的使用,并對挖掘查詢優化提出了巨大挑戰。"+
"規則約束可以分為五類:反單調的、單調的、簡潔的、可轉變的和不可轉變的。前四類約束可以在頻繁項集挖掘中使用,使挖掘更有功效,更有效率。沒有進一步分析或領域知識,關聯規則不應該直接用于預測。"+
"它們不必指示因果關系。然而,對于進一步探查,它們是有幫助的切入點,使得它們成為理解數據的流行工具。流數據不斷地在計算機系統中流進流出并且具有變化的更新速度,涉及數據流的應用非常廣泛。"+
"大綱提供數據流的匯總,通常用來返回查詢的近似解答。隨機抽樣、滑動窗口、直方圖、多分辨率方法、梗概以及隨機算法都是大綱的形式。傾斜時間框架模型允許數據以多個時間粒度存儲,最近的時間記錄在最細的粒度上,"+
"最遠的時間記錄在最粗的粒度上。流立方體可以存儲壓縮的數據,對時間維度使用傾斜時間框架模型,并且僅在一些關鍵的層上存儲數據,關鍵層反映了分析人員最感興趣的數據層,從而基于到關鍵層的“常用路徑”進行部分物化。";String query =
"數據挖掘";
long start = System.currentTimeMillis();String s =
new Highlighter(query).getBestFragment(content);System.out.println(
"Generate HTML: ");File f =
new File(
"demo.html");OutputStreamWriter osw =
new OutputStreamWriter(
new FileOutputStream(f),
"utf-8");osw.write(
"<pre><b>" + content +
"</pre><br/><br/>" +
"<pre><b>" + s +
"</pre><br/><br/>");osw.close();System.out.println(
"Hightlighter -> " + s);System.out.println(
"cost: " + (System.currentTimeMillis() - start));}
private static String BEGIN =
"<font color=\"red\">";
private static String END =
"</font>";
private Set<Character> set =
new HashSet<Character>();
public Highlighter(String query) {
char[] chars =
null;chars = query.toCharArray();
for (
int i =
0; i < chars.length; i++) {set.add(chars[i]);}}
public String
getBestFragment(String content) {String[] strs = content.replace(
".",
"。").split(
"。");
char[] chars =
null;TreeSet<Sentence> ts =
new TreeSet<Sentence>(
new Comparator<Sentence>() {
public int compare(Sentence o1, Sentence o2) {
if (o1.getIndex() < o2.getIndex()) {
return -
1;}
else if (o1.getIndex() > o2.getIndex()) {
return 1;}
elsereturn 0;}});Sentence sentence =
null;
int score =
0;StringBuilder sb =
null;System.out.println(
"total sentences: " + strs.length);
for (
int i =
0; i < strs.length; i++) {sentence =
new Sentence();sb =
new StringBuilder();sentence.setIndex(i);sentence.setText(strs[i]);chars = strs[i].toCharArray();
for (
int j =
0; j < chars.length; j++) {
if (set.contains(chars[j])) {score++;sb.append(BEGIN);sb.append(chars[j]);sb.append(END);}
else {sb.append(chars[j]);}}sentence.setValue(sb.toString());sentence.setScore(score);ts.add(sentence);score =
0;sb =
new StringBuilder();}Iterator<Sentence> it = ts.iterator();Sentence tmp =
null;
int number =
0;sb =
new StringBuilder();
for (; it.hasNext();) {tmp = it.next();sb.append(tmp.getValue());sb.append(
"。");System.out.println(tmp);number++;}System.out.println(
"After : " + number);
return sb.toString();}class Sentence {String value;
int index;
int score;String text;
public String
getValue() {
return value;}
public void setValue(String value) {
this.value = value;}
public int getIndex() {
return index;}
public void setIndex(
int index) {
this.index = index;}
public int getScore() {
return score;}
public void setScore(
int score) {
this.score = score;}
public String
toString() {
return this.index +
" " +
this.score +
" " +
this.value;}
public String
getText() {
return text;}
public void setText(String text) {
this.text = text;}}
}
本人簡書blog地址:http://www.jianshu.com/u/1f0067e24ff8????
點擊這里快速進入簡書
GIT地址:http://git.oschina.net/brucekankan/
點擊這里快速進入GIT
總結
以上是生活随笔為你收集整理的高亮标红的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。