惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
Apple Machine Learning Research
Apple Machine Learning Research
O
OpenAI News
酷 壳 – CoolShell
酷 壳 – CoolShell
The GitHub Blog
The GitHub Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
D
Docker
F
Full Disclosure
AI
AI
罗磊的独立博客
博客园 - 【当耐特】
U
Unit 42
S
SegmentFault 最新的问题
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
P
Palo Alto Networks Blog
博客园_首页
H
Help Net Security
量子位
月光博客
月光博客
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 司徒正美
F
Fortinet All Blogs
D
DataBreaches.Net
B
Blog RSS Feed
Webroot Blog
Webroot Blog
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
爱范儿
爱范儿
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Attack and Defense Labs
Attack and Defense Labs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
CERT Recently Published Vulnerability Notes
Martin Fowler
Martin Fowler
Blog — PlanetScale
Blog — PlanetScale
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Securelist

博客园 - 网际大鱼

大鱼认为好的牛股排名 让所有的实体店成为网店的体验店 QQ机器人小P隆重发布,QQ号:792892125 带强名的.net程序反向工程后汇编中的问题总结 谁是股市上的最大受益者 数据挖掘之web文本自动分类 利用搜索引擎技术抢注域名 推出网站大鱼搜索 网页生成缩略图程序在win2003下IE控件实例超过10个出现错误的问题 oracle 9i以上最有效率的if(exists)update else insert操作 爬虫如何抓取到Asp.Net中__doPostBack获取新页面的数据 goole CodeSearch 的分页bug 关键词与关键词之间的相关度计算 域名注册,抢注工具编写 超强的ORC控件Asprise OCR补丁发布 QQ存在重大漏洞,用户可以群发小广告,传播病毒 隆重推出PowerDesinger 12.1.0.1913破解补丁 用OCR技术识别验证码---tesseract 用sniffer技术盗取电话银行密码
用开源Carrot2的后缀树算法做Web文本聚类
网际大鱼 · 2006-11-10 · via 博客园 - 网际大鱼

采用基于Java的开源搜索结果聚合引擎,Carrot2 2.0 中的后缀树算法
Carrot2 可以自动的把搜索结果归类到相应的语义类别中,这个功能是通过Carrot2一个现成的组件完成的,除此之外Carrot2 还包括了很多其他的搜索结果聚合聚类算法。

因为没有做中文分词,也没有中文的Stopword,所以我们用英文测试,实现代码

 1SnippetTokenizer snippetTokenizer = new SnippetTokenizer(); 
 2        List<DocReference> documentReferences = new ArrayList<DocReference>();       
 3        List<TokenizedDocument> documents = new ArrayList<TokenizedDocument>();        
 4        TokenizedDocument doc = null;
 5        DocReference documentReference =  null;
 6        
 7        //从搜索引擎google获取100篇数据
 8        {
 9            String url = "http://www.google.com/search?as_q=phone&num=100&hl=en&newwindow=1&btnG=Google+Search&as_epq=&as_oq=&as_eq=&lr=&as_ft=i&as_filetype=&as_qdr=all&as_nlo=&as_nhi=&as_occt=any&as_dt=i&as_sitesearch=&as_rights=&safe=images";
10            byte[] pageHtml = HttpUtil.getPage(url);
11            if(pageHtml == null ) return ;            
12            try {
13                String strHtml = new String(pageHtml, "utf-8");
14                String[][] result = StringUtil.splitByReg(strHtml,"<td class=j>(.*?)<br>");
15                 
16                if(result != null)
17                {      for(int i=0;i<result.length;i++)
18                        
19                         for(int j=0;j<result[i].length;j++)
20                         {
21                             doc = snippetTokenizer
22                                .tokenize(new RawDocumentSnippet(i+"sen"+j,result[i][j].replaceAll("<[^<>]+>",""), "en"));
23                                documentReference = new DocReference(doc);
24                                documentReferences.add(documentReference);
25                                documents.add(doc);                           
26                         }

27                        }

28                }

29            }
 catch (UnsupportedEncodingException e) 
30                e.printStackTrace();
31            }

32        }

33
34        
35        //构建后缀树
36        final STCEngine stcEngine = new STCEngine(documentReferences);
37        stcEngine.createSuffixTree();
38        HashMap<String,String> defaults = new HashMap<String,String>(); 
39        defaults.put("lsi.threshold.clusterAssignment""0.150");
40        defaults.put("lsi.threshold.candidateCluster""0.775"); 
41        final StcParameters params = StcParameters.fromMap(defaults);
42        stcEngine.createBaseClusters(params);
43        stcEngine.createMergedClusters(params);
44
45        final List clusters = stcEngine.getClusters();
46        int max = params.getMaxClusters();
47
48        // Convert STC's clusters to the format required by local interfaces.
49        final List rawClusters = new ArrayList();
50        for (Iterator i = clusters.iterator(); i.hasNext() && (max > 0); max--)
51        {
52            final MergedCluster b = (MergedCluster) i.next();
53            final RawClusterBase rawCluster = new RawClusterBase();
54
55            int maxPhr = 3// TODO: This should be a configuration parameter moved to STCEngine perhaps.
56            final List phrases = b.getDescriptionPhrases();
57            for (Iterator j = phrases.iterator(); j.hasNext() && (maxPhr > 0); maxPhr--)
58            {
59                Phrase p = (Phrase) j.next();
60                rawCluster.addLabel(p.userFriendlyTerms().trim());
61            }

62
63            for (Iterator j = b.getDocuments().iterator(); j.hasNext();)
64            {
65                final int docIndex = ((Integer) j.next()).intValue();
66                final TokenizedDocument tokenizedDoc = (TokenizedDocument) documents.get(docIndex);
67                final RawDocument rawDoc = (RawDocument) tokenizedDoc.getProperty(TokenizedDocument.PROPERTY_RAW_DOCUMENT);
68                rawCluster.addDocument(rawDoc);
69            }

70
71            rawClusters.add(rawCluster);
72        }

73        
74        //得到结果,输出
75        for (Iterator iter = rawClusters.iterator(); iter.hasNext();)
76        {
77            RawCluster cluster = (RawCluster) iter.next();
78            final List phrases = cluster.getClusterDescription();
79            for(int i=0;i<phrases.size();i++)
80                System.out.print("#"+phrases.get(i)); 
81            System.out.println();
82            
83        }

下面是输出聚类phone的结果,还不错
#phone
#Phone Number
#yellow pages
#mobile phone
#cell phone
#Phone Book
#area code
#Business
#services
#Wireless
#people
#directory
#telephone
#address
#online