java英文分词工具
1. 基本分词方式,速度快;官方示例:Listparse = BaseAnalysis.parse("让战士们过一个欢乐祥和的新春佳节。
"); System.out.println(parse); result:[让/v, 战士/n, 们/k, 过/ug, 一个/m, 欢乐/a, 祥和/a, 的/uj, 新春/t, 佳节/n, 。
/w] 2. 精准分词方式兼顾精度与速度,比较均衡;官方示例:Listparse = ToAnalysis.parse("让战士们过一个欢乐祥和的新春佳节。
"); System.out.println(parse); 3. NLP分词方式可是未登录词,但速度较慢;
word分词器分的词怎么都是一个词
我们知道,Word中的words对象是Word可以识别的词语,对于汉语词语来说,有的词语和我们的习惯并不完全相符。
简单的说就是有的词语在Word中被认为是一个词语,如 阿波罗 ,有的词语被识别为多个词语,如 一字之差 。
这样的差别就是Word在分词方面的bug。
下面就谈谈如何实现对Word汉语分词自定义。
首先特别要感谢Excelhome论坛sylun兄。
之前我还一直固执地认为Word只支持导入英文词典,对于中文词语不支持自定义,是这位哥哥告诉我,可以通过导入微软拼音输入法自造词实现自定义分词效果。
我的工作其实就是想办法把这个效果的实现更简单一些:不再必须安装庞大的微软拼音输入法,且一经导入制作的自造词在用户间可以简单实现通用。
效果如下:1、 首先不做任何操作,打开测试文档,点击“统计每段词语数”看看结果。
不保存关闭文档。
2、 运行Word自造词工具.exe,点击修改按钮。
3、 再次打开测试文档,点击“统计每段词语数”看看结果。
两次结果是否相同。
原来每一段都被自定义成了一个词语。
(回车符除外)
Java如何操作Word,Excel,PDF文档?
Java Excel API 文档 http://www.andykhan.com/jexcelapi/ 1、一个jacob操作Word的例子,其他操作excel,pdf的sample里都有 import java.io.File; import com.jacob.com.*; import com.jacob.activeX.*; public class WordTest { public static void main(String[] args) { WordBean word=new WordBean(); word.openWord(true); word.createNewDocument(); word.insertText("Hello word."); } } import com.jacob.activeX.*; import com.jacob.com.*; public class WordBean extends java.awt.Panel { private ActiveXComponent MsWordApp = null; private Dispatch document = null; public WordBean() { super(); } public void openWord(boolean makeVisible) { //Open Word if we've not done it already if (MsWordApp == null) { MsWordApp = new ActiveXComponent("Word.Application"); } //Set the visible property as required. Dispatch.put(MsWordApp, "Visible", new Variant(makeVisible)); } public void createNewDocument() { //Find the Documents collection object maintained by Word Dispatch documents = Dispatch.get(MsWordApp,"Documents").toDispatch(); //Call the Add method of the Documents collection to create //a new document to edit document = Dispatch.call(documents,"Add").toDispatch(); } public void insertText(String textToInsert) { // Get the current selection within Word at the moment. If // a new document has just been created then this will be at // the top of the new doc Dispatch selection = Dispatch.get(MsWordApp,"Selection").toDispatch(); //Put the specified text at the insertion point Dispatch.put(selection,"Text",textToInsert); } public void saveFileAs(String filename) { Dispatch.call(document,"SaveAs",filename); } public void printFile() { //Just print the current document to the default printer Dispatch.call(document,"PrintOut"); } public void closeDocument() { // Close the document without saving changes // 0 = wdDoNotSaveChanges // -1 = wdSaveChanges // -2 = wdPromptToSaveChanges Dispatch.call(document, "Close", new Variant(0)); document = null; } public void closeWord() { Dispatch.call(MsWordApp,"Quit"); MsWordApp = null; document = null; } }
JAVA读取WORD,EXCEL,PDF文件的方法是什么呢?
JAVA读取WORD,EXCEL,POWERPOINT,PDF文件的方法 OFFICE文档使用POI控件,PDF可以使用PDFBOX0.7.3控件,完全支持中文,用XPDF也行,不过感觉PDFBOX比较好,而且作者也在更新。
水平有限,万望各位指正 WORD: import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.poi.hwpf.extractor.WordExtractor; import java.io.File; import java.io.InputStream; import java.io.FileInputStream; import com.search.code.Index; public Document getDocument(Index index, String url, String title, InputStream is) throws DocCenterException { String bodyText = null; try { WordExtractor ex = new WordExtractor(is);//is是WORD文件的InputStream bodyText = ex.getText(); if(!bodyText.equals("")){ index.AddIndex(url, title, bodyText); } }catch (DocCenterException e) { throw new DocCenterException("无法从该Mocriosoft Word文档中提取内容", e); }catch(Exception e){ e.printStackTrace(); } } return null; } Excel: import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.poi.hwpf.extractor.WordExtractor; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFCell; import java.io.File; import java.io.InputStream; import java.io.FileInputStream; import com.search.code.Index; public Document getDocument(Index index, String url, String title, InputStream is) throws DocCenterException { StringBuffer content = new StringBuffer(); try{
求教用java 生成word!!!
1-apache的POI,此方法对Excel的导出做的很好,目前对Word的导出方面的功能尚未完全。
2-纯JavaScript脚本实现。
主要通过客户端调用本机Office组件来实现。
3-在JSP页面引入头文件实现。
纯JavaScript脚本实现细节方面大体是创建一个word组件ActiveXObject('Word.Application'),用js通过表ID取得表内容然后保存到word,要注意的是js实现有很多不好的地方,例如Internet选项需要把ActiveX空间全部启用,安全级别设置为中。
这样的话岂不是每台机器都要配置一下。
其次每次生成word文档以后弹出对话框(无法保存此文件,因为它已在别处打开(C:\...\STARTUP\Powerword.dot)),出现此问题就需要把C:\Documents and Settings\当前用户名\Application Data\Microsoft\Word\STARTUP下的Powerword.dot文件删除,每次遇到此问题就需要删除文件来解决,十分不方便。
JSP页面引入来实现Word保存就方便多了,但是也有不足的地方,首先如果需要引入如果需要下载的话就引入其实如果大家用框架做就方便多了,比如Struts2。
在Action里直接写如下代码:if(out!=null){String fileName="";fileName+="评价报告.doc";try {HttpServletResponse response = ServletActionContext.getResponse();response.setHeader("Content-disposition","attachment; filename="+new String(fileName.getBytes("GB2312"), "8859_1"));} catch (UnsupportedEncodingException e) {e.printStackTrace();}out是jsp页面表单元素,一个button,用于提交表单到相应Action进行Word下载。
Action设置jsp页面头文件。
这样每次点击button就可以把相应jsp页面的内容保存到Word中并且支持下载,Word中内容并且是可编辑状态。
不足的地方在于由于表内容是动态生成,有的需要先查看在下载Word,就需要另外建立一个新JSP页面进行Word下载,当然首先要在struts.xml里配置好页面转向。
新建立的页面传值同查看页面要保持一样。
用结巴分词的Java版本出现空指针异常错误,不知道该怎么解决?为什...
没自动的..你可以把软件安装好了点文件-导入\导出 来转换成PDF文件 也可以用WPS, 这是我自己下载了在用的,很好用的版本: Office.2003.SP2.龙卷风大企业版 V2.2 2.2 658M ISO 此ISO整合SP2升级包,免激活,免序列号,支持在线更新 包含下列组件: Microsoft Office Word 2003 Microsoft Office Excel 2003 Microsoft Office PowerPoint 2003 Microsoft Office FrontPage 2003 Microsoft Office Access 2003 Microsoft Office Outlook 2003 Microsoft Office OneNote 2003 Microsoft Office Visio 2003 Microsoft Office InfoPath 2003 Microsoft Office Publisher 2003 Microsoft Office Project 2003 安装说明:先卸载你原来的版本,然后全新安装此版即可
java编个中文分词的程序
import java.io.Reader;import java.io.StringReader;import org.apache.lucene.analysis.*;import org.apache.lucene.analysis.cjk.CJKAnalyzer;import org.apache.lucene.analysis.cn.ChineseAnalyzer;import org.apache.lucene.analysis.standard.StandardAnalyzer;import org.mira.lucene.analysis.MIK_CAnalyzer;public class JeAnalyzer { public static void testStandard(String testString) { try { Analyzer analyzer = new StandardAnalyzer(); Reader r = new StringReader(testString); StopFilter sf = (StopFilter) analyzer.tokenStream("", r); System.err.println("=====standard analyzer===="); Token t; while ((t = sf.next()) != null) { System.out.println(t.termText()); } } catch (Exception e) { e.printStackTrace(); } } public static void testCJK(String testString) { try { Analyzer analyzer = new CJKAnalyzer(); Reader r = new StringReader(testString); StopFilter sf = (StopFilter) analyzer.tokenStream("", r); System.err.println("=====cjk analyzer===="); Token t; while ((t = sf.next()) != null) { System.out.println(t.termText()); } } catch (Exception e) { e.printStackTrace(); } } public static void testChiniese(String testString) { try { Analyzer analyzer = new ChineseAnalyzer(); Reader r = new StringReader(testString); TokenFilter tf = (TokenFilter) analyzer.tokenStream("", r); System.err.println("=====chinese analyzer===="); Token t; while ((t = tf.next()) != null) { System.out.println(t.termText()); } } catch (Exception e) { e.printStackTrace(); } } public static String transJe(String testString, String c1, String c2) { String result = ""; try { Analyzer analyzer = new MIK_CAnalyzer(); Reader r = new StringReader(testString); TokenStream ts = (TokenStream) analyzer.tokenStream("", r); Token t; while ((t = ts.next()) != null) { result += t.termText() + ","; } } catch (Exception e) { e.printStackTrace(); } return result; } public static void main(String[] args) { try { String testString = "中文分词的方法其实不局限于中文应用,也被应用到英文处理,如手写识别,单词之间的空格就很清楚,中文分词方法可以帮助判别英文单词的边界"; System.out.println("测试的语句 "+testString); String sResult[] = transJe(testString, "gb2312", "utf-8").split(","); for (int i = 0; i < sResult.length; i++) { System.out.println(sResult[i]); } } catch (Exception e) { e.printStackTrace(); } }}jar包 lucene-analyzers-2.4.1.jarlucene-core-2.4.1.jarIKAnalyzer2.0.2OBF.jar
转载请注明出处51数据库 » java word分词器