- 浏览: 343960 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
pacoson:
感谢楼主。请受小生一拜。
ANT预编译JSP -
zhuhongming123:
一楼的同学Lucene4.* 以上的 已经改成了Numeric ...
Lucene日期排序及组合查询 -
ywjk520:
RangeQuery在哪个包里?
Lucene日期排序及组合查询 -
willwen:
有个疑问,楼主,为何初始化bits 从txt读取已有的网址是直 ...
布隆过滤器(Bloom Filter)之java实例 -
yu_226528:
还不如没有呢
jFreeChart 在jsp页上实现简单的折线图、柱状图
注明:该类主要是符合本人项目的需求,内容摘要的高亮点实现没这么复杂,此类中不仅仅包含了内容的高亮点实现,还包含了获取xml内容和html纯文本的提取。注意一点的是在对内容进行高亮度化的过程中,其实也就是进行全文检索的过程,所以对文本内容进行分词是必不可少的。否则将无法找到文本中对应的关键词。详细请看类的实现
/* * @(#)SummaryHighlighter.java * Copyright(c) */ package com.chengyi.util; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringReader; import javax.swing.ListCellRenderer; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.SimpleAnalyzer; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.cw.Segmenter; import org.apache.lucene.analysis.cw.SegmenterUtils; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.Query; import org.apache.lucene.search.highlight.Highlighter; import org.apache.lucene.search.highlight.QueryScorer; import org.apache.lucene.search.highlight.SimpleHTMLFormatter; import org.htmlparser.util.ParserException; import org.w3c.dom.CDATASection; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; /** * 用lucene实现搜索结果的高亮度 * * @version 1.0 2009.02.03 * @author zhx * */ public class SummaryHighlighter { /** 高亮度内容属性,只是有标识作用,没有具体意义*/ private static String CONTENT = "content"; /** * 实现内容摘要的高亮点 * 此方法传入的xmlContent内容是一个xml文本(格式见测试文件2.txt),我们需根据该xml的结构进行 * 分析,并提取该xml中的文本,特殊的是从xml中提取出来的文本又是html格式,所以又得做第二次提取, * 才能获取到纯文本 * * @param content * 需高亮度内容 * @param keyWord * 高亮度关键字 * @return 高亮度摘要 */ public static String getHighlighterSummary(String xmlContent, String keyWord) { // TODO Auto-generated method stub String hightContent = ""; String segmenterContent = ""; String htmlContent = ""; String content = ""; // 获取html内容 htmlContent = SummaryHighlighter.getHtmlContentFromXML(xmlContent); // 从html中提取纯文本 content = SummaryHighlighter.getTextFromHtml(htmlContent); //System.out.println("提取到的纯文本:" + content); // 对内容进行分词 segmenterContent = SummaryHighlighter.segmentString(content); // Analyzer analyzer = new CWordAnalyzer(); Analyzer analyzer = new SimpleAnalyzer(); QueryParser queryParser = new QueryParser(CONTENT, analyzer); // 设置相似度 queryParser.setFuzzyMinSim(0.9f); try { //分析关键词 Query query = queryParser.parse(segmentString(keyWord)); // Term term=new Term(CONTENT,keyWord); // Query query = new TermQuery(term); QueryScorer scorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter( "<font color=\"#cc0033\">", "</font>"), scorer); Reader reader = new StringReader(segmenterContent); TokenStream tokenStream = analyzer.tokenStream(CONTENT, reader); //获取高亮点后的内容 hightContent = highlighter.getBestFragments(tokenStream, segmenterContent, 0, "..."); //去除内容中的空格 hightContent = hightContent.replace(" ", "").replace( "<fontcolor=\"#cc0033\">", "<font color=\"#cc0033\">"); //System.out.println(hightContent); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (org.apache.lucene.queryParser.ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return hightContent; } /** * 分词处理 * * @param in * 处理内容 * @return 分词后的内容 */ public static String segmentString(String in) { String ret = null; Segmenter mainsegmenter; try { mainsegmenter = SegmenterUtils.getSegmenter(System .getProperty("java.io.tmpdir") + "/zword.obj"); StringBuffer buffer = null; if (mainsegmenter != null) { BufferedReader bin = new BufferedReader(new StringReader(in)); buffer = new StringBuffer(); String dataline; String processed; try { while ((dataline = bin.readLine()) != null) { processed = mainsegmenter.segmentLine(dataline, " "); buffer.append(processed).append("\n"); } } catch (IOException ioe) { // ignored } finally { try { bin.close(); } catch (Exception e) { } } } else { } if (buffer != null) { ret = buffer.toString(); } } catch (ClassCastException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // System.out.println(buffer.toString()); return ret; } /** * 读取一个文件到字符串里. * * @param sFileName * 文件名 * @param sEncode * String * @return 文件内容 */ public static String readTextFile(String sFileName, String sEncode) { StringBuffer sbStr = new StringBuffer(); try { File ff = new File(sFileName); InputStreamReader read = new InputStreamReader(new FileInputStream( ff), sEncode); BufferedReader ins = new BufferedReader(read); String dataLine = ""; while (null != (dataLine = ins.readLine())) { sbStr.append(dataLine); // sbStr.append("\r\n"); } ins.close(); } catch (Exception e) { e.printStackTrace(); } //System.out.println("读入的文章内容:" + sbStr.toString()); return sbStr.toString(); } /** * 从xml中获取内容,此方法对应测试文件2.txt的节点结构,目的是获取<![cdata[.....]]>中的内容 * * @param xmlContent * xml内容 * @return 提取出来的内容 */ public static String getHtmlContentFromXML(String xmlContent) { xmlContent = xmlContent.replaceAll("UTF-8", "GBK"); String content = ""; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; try { builder = factory.newDocumentBuilder(); org.w3c.dom.Document doc = builder.parse(new ByteArrayInputStream( xmlContent.getBytes())); // normalize text representation doc.getDocumentElement().normalize(); NodeList listOfContents = doc .getElementsByTagName("static-content"); int totalContents = listOfContents.getLength(); // System.out.println("Total no of people : " + totalContents); for (int s = 0; s < listOfContents.getLength(); s++) { Node contentNode = listOfContents.item(s); NodeList listOfCdata = contentNode.getChildNodes(); int totalCdata = listOfCdata.getLength(); for (int i = 0; i < totalCdata; i++) { Node cdataNode = listOfCdata.item(i); if (cdataNode.getNodeType() == Node.CDATA_SECTION_NODE) { CDATASection cdataSection = (CDATASection) cdataNode; content = cdataSection.getWholeText(); // System.out.print(content); } /* * if (node1.getNodeType() == Node.TEXT_NODE) { n++; String * type = node1.getNodeName(); System.out.println("第" + n + * "个是" + type + "节点,内容:"); Text textNode = (Text) node1; * String content = textNode.getWholeText(); * System.out.print(content); } */ }// end of if clause }// end of for loop with s var } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (org.xml.sax.SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return content; } /** * 提取html中的纯文本内容 * * @param htmlContent html内容 * @return 纯文本内容 */ public static String getTextFromHtml(String htmlContent) { boolean bContent = true; StringBuffer sBuffer = new StringBuffer(8096 * 2); char[] cBuffer = htmlContent.toCharArray(); int nCount = cBuffer.length; for (int i = 0; i < nCount; i++) { if (bContent == false) { if (cBuffer[i] == '>') bContent = true; else continue; } else { if (cBuffer[i] == '<') { bContent = false; continue; } else if (cBuffer[i] == '\n' || cBuffer[i] == ' ' || cBuffer[i] == ' ' || cBuffer[i] == ' ') { continue; } else if (cBuffer[i] == '&' && cBuffer[i + 1] == 'n' && cBuffer[i + 2] == 'b' && cBuffer[i + 3] == 's' && cBuffer[i + 4] == 'p' && cBuffer[i + 5] == ';') { i = i + 5; continue; } sBuffer.append(cBuffer[i]); } } return sBuffer.toString(); } /** * test * * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String content = SummaryHighlighter.readTextFile("d:/2.txt", "gbk"); String keyWord = "中国"; SummaryHighlighter.getHighlighterSummary(content, keyWord); } }
测试文件2.txt的内容:
<?xml version='1.0' encoding='UTF-8'?>
<root available-locales="en_US," default-locale="en_US">
<static-content language-id="en_US">
<![CDATA[<p> 凡中国产业集群网在<a href="http://www.csic99.com">www.csic99.com</a>运作的网站明确标示由中国产业集群合作伙伴运营的中国产业集群该城市网页及该城市的相关页面,均由中国产业集群的合作伙伴按照中国产业集群授权书及中国产业集群网的用户协议、使用规则等规定,在其所获得授权范围与授权期限内予以运营中国产业集群在此申明会积极帮助您,以支持您合法权益得到保障。 <br /> 因中国产业集群合作伙伴在其被授权范围与期限内,按照法律法规规定及中国产业集群网的相关规定,所作之行为,如果您认为损害到了您的合法权益,您可以按照中国产业集群网约定的办法予以解决;中国产业集群合作伙伴在其被 授权范围以外或违反 法律法规规定及违反中国产业集群网的规定,所作之行为( 包括网上及非网上行为)而使您(任何中国产业集群网用户或任何第三方)受到的任何损失,或与一名或多名用户发生争议,就上述损失和/或争议产生或在任何方面与上述损失和/或争议有关的每一种类和性质的已知或未知、可疑或非可疑、披露或未披露的索赔、要求和损害,特此申明如下:鉴于中国产业集群合作伙伴之授权范围自其被授权之日起,已在本网站显著位置予以公开,中国产业集群网的用户协议及相关规定与免责申明等也在本网站显著位置予以,且中国产业集群仅作为网上分发信息的渠道,而并非信息的发布方,同时,中国产业集群没有事先审核用户上传的内容,也没有事后参与用户之间的实际联络之义务,故对于因为中国产业集群合作伙伴在其被授权范围以外或违反法律法规规定及中国产业集群网的相关规定,所作之行为(包括网上及非网上行为)而使您受到任何损失,或与一名或多名用户发生争议,就上述损失和/或争议产生或在任何方面与上述损失和/或争议有关的每一种类和性质的已知或未知、可疑或非可疑、披露或未披露的索赔、要求和损害, 特此申明免除中国产业集群(和中国产业集群的高级职员、董事、代理人、关联公司、母公司、子公司和雇员)的任何责任。 <br />请您仔细阅读相关授权文书,本网站用户协议及相关规定与免责申明等,以避免不必要的损失。 中国产业集群网</p>]]>
</static-content>
</root>
发表评论
-
布隆过滤器(Bloom Filter)之java实例
2010-08-26 14:40 6385在日常生活中,包括在设计计算机软件时,我们经常要判断一个 ... -
Lucene查询语法详解
2010-07-16 10:55 1216Lucene提供了丰富的API来 ... -
使用Lucene的Highlighter实现文件摘要的自动提取
2010-07-03 15:19 1408使用Lucene自带的Highlighter就可以实现对原始文 ... -
ICTCLAS 中科院分词系统 代码 注释 中文分词 词性标注
2010-04-16 15:45 1776中科院分词系统概述 这几天看完了中科院分词程序的代码,现在来 ... -
Lucene日期排序及组合查询
2009-11-19 14:31 4874public class SearchUtil { //索 ... -
Lucene中自定义排序的实现
2009-11-07 17:59 950使用Lucene来搜索内容,搜索结果的显示顺序当然是比较重要 ... -
在Lucene中应用poading进行分词
2009-11-07 17:52 12381、下载poading解牛 http://code.googl ... -
Lucene日期索引搜索
2009-11-07 17:42 1423注意使用lucene的版本,调试本例的时候,作者使用的是luc ... -
Lucene 中文引擎,庖丁解牛的辞典参数配置方法
2009-11-07 16:34 2001随机文档指示可以在环境变量里配置。原文如下 庖丁中文分词需要一 ... -
Lucene 2.4更新索引的方法(Update Index)
2009-11-07 16:32 2054在Lucene里面没有update方法,我查了文档,我们只能删 ... -
庖丁解牛的Lucene 2.4的全文搜索代码
2009-11-07 16:30 1392package com.laozizhu.article.ut ... -
Lucene 搜索方式
2009-11-07 16:23 1142Lucene有多种搜索方式, ... -
转一篇lucene的使用的文章,写的比较全
2009-11-07 16:20 9401 lucene简介 1.1 什么是lucene Lucene ...
相关推荐
基于C51单片机Proteu仿真实例及软件源码+文档说明 之-电子琴.zip
均包含代码,文章,部分项目包含ppt
基于java的智乐健身后台管理系统设计与实现.docx
基于java的鲜花销售管理系统设计与实现.docx
内容概要:本文回顾了近年来关于数字孪生(Digital Twin)的概念和技术的发展历程,并详尽介绍了这种技术在未来车间中的潜在应用场景和需克服的难关。数字孪生是一种用于集成物理和虚拟系统的技术手段,它能够在产品设计、智能生产和预防性维护等多个领域发挥作用。 适合人群:研究人员和工程师们希望更好地理解数字孪生的基本理论与具体应用实践。 使用场景及目标:涵盖了从产品的设计、制造过程到服役阶段故障预测的全过程,并探讨了基于DT的具体实施路径。 其他说明:强调了信息物理系统的交互融合是DT成功部署的基础,而建立高准确度的多维虚拟模型、孪生数据驱动和实现动态实时交互将是推进这一前沿概念向前发展的关键。
管理员能够查看、添加、修改和删除景点分类信息,景点分类管理 用户在系统前台可查看系统信息,包括首页、景点信息、酒店信息以及客房信息等 用户要登录界面可输入用户名、密码,点击登录按钮进行登录系统 项目关键技术 开发工具:IDEA 、Eclipse 编程语言: Java 数据库: MySQL5.7+ 后端技术:ssm 前端技术:Vue 关键技术:springboot、SSM、vue、MYSQL、MAVEN 数据库工具:Navicat、SQLyog
关键字:UTM/企业防火墙/NGFW 功能:vpn,sdwan,无线控制器,ldap,双因子认证,nat/透明,终端控制,av防病毒,ips入侵检测,应用控制,web过滤, FortiGate UTM/NGFW产品 ①端口:8口、16口、24口、48口 ②层数:二层(接入层交换机、傻瓜式交换机)、三层(核心交换机、汇聚交换机) ③是否网管 网管: 非网管(傻瓜式交换机,即插即用) WEB网管(S1720GW系列) 全网管(S1720GFR系列,S2700以上的型号都为全网管) ④速率:百兆、千兆、万兆等 1.带机量(支持用户数) 2.端口数 3.吞吐量,并发连接数 4.功能 功能差异须知 NG-xxxx产品特有功能 TG-xxxx&NG-xxxx共有功能 TG-xxxx产品特有功能 FW:网络接入、安全防护、高可用性、身份认证、系统服务、系统管理 ●应用层DDOS攻击防护 负载均衡:多链路负载均衡与备份、多链路智能选路技术、多算法的服务器负载均衡 ●异常行为分析:内置统计只能算法,智能学习
简化设计,轻松管理 一键设计:快速创建和管理SQLite3数据库,简化数据库设计流程。 高效查询:强大的查询功能,帮助您轻松处理复杂的SQL语句。 功能全面,灵活便捷 可视化界面:直观的图形界面,让您无需编写繁琐的SQL代码,即可完成数据库设计。 数据同步:支持实时数据同步,确保您的数据库始终保持最新状态。 高度兼容,广泛适用 跨平台支持:适用于Windows、Mac和Linux等多种操作系统,满足不同开发环境的需求。 多语言集成:与C、C++等主流编程语言无缝对接,提高开发效率。 安全可靠,稳定运行 数据备份:内置数据备份与恢复功能,保障数据安全。 性能优化:优化数据库结构,提升查询速度和存储效率。
小程序-滴滴作业.zip 小程序-滴滴作业.zip 小程序-滴滴作业.zip
地线贴标_复制.ezd
Chrome主题-开阔绿地草地主题
基于java校园兼职平台设计与实现.docx
基于java的旅游管理系统设计与实现.docx
基于java的技术大健康综合咨询问诊平台的设计与实现.docx
均包含代码,文章,部分项目包含ppt
项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
基于java的共享客栈管理系统设计与实现.docx
基于java的车库智能管理平台设计与实现.docx
基于java的学生宿舍管理设计与实现.docx
【C++】项目设计资源 【C++】新手入门教程 包含例子和相关说明