`
wangshu3000
  • 浏览: 131378 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类
最新评论

从一篇文章中筛选处辞典生词本中没有的单词,导出成txt文件

 
阅读更多
代码些的比较烂,只是从几篇文章中过滤处单词本中没有的单词,导出成单独的一个文件,再手动一个一个录入到单词本中。。小工具。。mark一下。。使用dom4j。
<?xml version="1.0" encoding="UTF-8"?>
<wordbook><item>
		<word>daunting</word>
		<trans><![CDATA[adj. 使人畏缩的;使人气馁的;令人怯步的 
daunting: 令人沮丧 | 使人畏缩的 | 使人气馁的]]></trans>
		<phonetic><![CDATA[['dɔ:ntiŋ]]]></phonetic>
		<tags/>
		<progress>10</progress>
	</item><item>
		<word>informative</word>
		<trans><![CDATA[adj. 教育性的,有益的;情报的;见闻广博的 
informative: 告知性的 | 使知道消息的 | 有益的]]></trans>
		<phonetic><![CDATA[[in'fɔ:mətiv]]]></phonetic>
		<tags/>
		<progress>10</progress>
	</item><item>
		<word>contribute</word>
		<trans><![CDATA[vt. 贡献,出力;投稿;捐献 
vt. 贡献,出力;投稿;捐献 
contribute: 贡献 | 捐助 | 做出贡献]]></trans>
		<phonetic><![CDATA[[kən'tribju:t]]]></phonetic>
		<tags/>
		<progress>10</progress>
	</item>

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

public class WordNewMain {

	/**
	 * @param args
	 * @throws DocumentException
	 * @throws IOException
	 */
	public static void main(String[] args) throws DocumentException, IOException {
		Map<String, Word> listMap = new HashMap<String, Word>();
		SAXReader saxReader = new SAXReader();
		saxReader.setEncoding("utf-8");
		Document whole1Xml = saxReader.read(new BufferedInputStream(new FileInputStream("all_sych.xml")));
		List<Element> whole1List = whole1Xml.selectNodes("//wordbook/item");
		System.out.println("whole1 List Size:" + whole1List.size());
		for (int i = 0; i < whole1List.size(); i++) {
			Element e = whole1List.get(i);
			Node word = e.selectSingleNode("word");
			Node trans = e.selectSingleNode("trans");
			Node phonetic = e.selectSingleNode("phonetic");
			Node tags = e.selectSingleNode("tags");
			Node progress = e.selectSingleNode("progress");
			Word w = listMap.get(word.getStringValue());
			if (w != null && Integer.parseInt(w.getProgress()) < Integer.parseInt(progress.getStringValue())) {
				w.setProgress(progress.getStringValue());
			} else if (w == null) {
				e.detach();
				w = new Word(word.getStringValue(), trans.getStringValue(), phonetic.getStringValue(),
						tags.getStringValue(), progress.getStringValue());
			}
			listMap.put(word.getStringValue().toLowerCase(), w);
		}

		// txt
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("8word.txt"))));
		System.out.println("Ok, find the file!");
		String line = null;
		byte[] wordB = new byte[30];
		Map<String, String> countArea = new HashMap<String, String>();
		int wordBP = 0;
		String theWord = null;
		System.out.println("Start count~");
		FileWriter fw = new FileWriter("result.txt");

		while ((line = br.readLine()) != null) {
			boolean inWord = true;
			byte[] lineB = line.getBytes();
			for (int i = 0; i < lineB.length; i++) {
				// is a character
				if ((lineB[i] < 91 && lineB[i] > 64) || (lineB[i] < 123 && lineB[i] > 96)) {
					wordB[wordBP] = lineB[i];
					wordBP = wordBP + 1;
					inWord = true;
				} else if (inWord) {
					theWord = new String(wordB).trim().toLowerCase();
					if (listMap.get(theWord) == null && theWord.length() > 1) {
						countArea.put(theWord, theWord);
					}
					wordBP = 0;
					inWord = false;
					wordB = new byte[30];
				}
			}
			if (inWord) {
				theWord = new String(wordB).trim().toLowerCase();
				if (listMap.get(theWord) == null && theWord.length() > 1) {
					countArea.put(theWord, theWord);
				}
				wordBP = 0;
				inWord = false;
				wordB = new byte[30];
			}
		}
		br.close();

		// steven txt
		br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("steve_4p.txt"))));
		System.out.println("Ok, find the file!");
		while ((line = br.readLine()) != null) {
			boolean inWord = true;
			byte[] lineB = line.getBytes();
			for (int i = 0; i < lineB.length; i++) {
				// is a character
				if ((lineB[i] < 91 && lineB[i] > 64) || (lineB[i] < 123 && lineB[i] > 96)) {
					wordB[wordBP] = lineB[i];
					wordBP = wordBP + 1;
					inWord = true;
				} else if (inWord) {
					theWord = new String(wordB).trim().toLowerCase();
					if (listMap.get(theWord) == null && theWord.length() > 1) {
						countArea.put(theWord, theWord);
					}
					wordBP = 0;
					inWord = false;
					wordB = new byte[30];
				}
			}
			if (inWord) {
				theWord = new String(wordB).trim().toLowerCase();
				if (listMap.get(theWord) == null && theWord.length() > 1) {
					countArea.put(theWord, theWord);
				}
				wordBP = 0;
				inWord = false;
				wordB = new byte[30];
			}
		}

		// GRE text
		br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("gre.txt"))));
		System.out.println("Ok, find the file!");
		while ((line = br.readLine()) != null) {
			boolean inWord = true;
			byte[] lineB = line.getBytes();
			for (int i = 0; i < lineB.length; i++) {
				// is a character
				if ((lineB[i] < 91 && lineB[i] > 64) || (lineB[i] < 123 && lineB[i] > 96)) {
					wordB[wordBP] = lineB[i];
					wordBP = wordBP + 1;
					inWord = true;
				} else if (inWord) {
					theWord = new String(wordB).trim().toLowerCase();
					if (listMap.get(theWord) == null && theWord.length() > 1) {
						countArea.put(theWord, theWord);
					}
					wordBP = 0;
					inWord = false;
					wordB = new byte[30];
				}
			}
			if (inWord) {
				theWord = new String(wordB).trim().toLowerCase();
				if (listMap.get(theWord) == null && theWord.length() > 1) {
					countArea.put(theWord, theWord);
				}
				wordBP = 0;
				inWord = false;
				wordB = new byte[30];
			}
		}

		// GaoZhong text
		br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("gz.txt"))));
		System.out.println("Ok, find the file!");
		while ((line = br.readLine()) != null) {
			boolean inWord = true;
			byte[] lineB = line.getBytes();
			for (int i = 0; i < lineB.length; i++) {
				// is a character
				if ((lineB[i] < 91 && lineB[i] > 64) || (lineB[i] < 123 && lineB[i] > 96)) {
					wordB[wordBP] = lineB[i];
					wordBP = wordBP + 1;
					inWord = true;
				} else if (inWord) {
					theWord = new String(wordB).trim().toLowerCase();
					if (listMap.get(theWord) == null && theWord.length() > 1) {
						countArea.put(theWord, theWord);
					}
					wordBP = 0;
					inWord = false;
					wordB = new byte[30];
				}
			}
			if (inWord) {
				theWord = new String(wordB).trim().toLowerCase();
				if (listMap.get(theWord) == null && theWord.length() > 1) {
					countArea.put(theWord, theWord);
				}
				wordBP = 0;
				inWord = false;
				wordB = new byte[30];
			}
		}

		// output
		Iterator<String> it = countArea.keySet().iterator();
		while (it.hasNext()) {
			fw.write(it.next() + "\r\n");
		}
		fw.close();
		System.out.println("End count~");
		System.out.println("Sum word of steve is :" + countArea.size());
	}

}
分享到:
评论

相关推荐

    金山词霸生词本生成器

    金山词霸除了单词查词功能,大家用得比较多的是金山词霸的生词本功能。 不可否认,金山词霸是个非常棒的英文单词查询工具,但其它功能还是有很多功能不完善。如生词本功能。 每一个人学单词时,学的顺序和内容都...

    生词本导入系统源码201271

    一个winform的小型软件,从有道词典的生词本中导出xml格式的单词本,然后转换为安卓手机的给力背单词软件的所需要的txt词库文件 技术特点: XmlTextReader读取xml,List泛型,生成txt文件 开发环境为Visual ...

    有道词典单词表导出工具 v1.0.zip

    有道词典单词表导出工具用于导出有道词典生词本中的单词表,输出为文本格式,可以整理打印出来,也可以作为词汇之沙我爱背单词,极速单词等背单词软件的词库使用。

    1300个常用单词,网易词典导出,5年日常积累

    英语水平一般,平时对生词都加入了生词本,5年积累了1300个高频词汇,但是没有最简单的,if,a,the,end,等,可下载bin结构,用于直接导入网易云词典

    文本文件单词的检索与计数

    要求编程建立一个文本文件,每个单词不包含空格且不跨行,单词由字符序列构成且区分大小写;统计给定单词在文本文件中出现的总次数;检索输出某个单词出现在文本中的行号、在该行中出现的次数以及位置。该设计要求可...

    快译通部分功能(查询单词)

    给定文本文件“dict.txt”,该文件用于存储词库。词库为“英-汉”,“汉-英”双语词典,每个单词和其解释的格式固定。每个新单词由“#”开头,解释之间使用“@”隔开。一个词可能有多个解释,解释均存储在一行里,...

    simulink数据字典参数导出

    该文件主要用来实现将simulink数据字典中的parameter参数导出到excel中,以便全面了解simulink模型中各参数的标定值,便于分析模型;并可在导出的excel表格中记录更改参数的历史,并进行对比分析。将文件导入到...

    很全的英文单词字典txt.zip

    用于python脚本字典

    dict.txt文件英英字典

    dict.txt文件英英字典

    中文词典.txt

    中文词典 NLP ,收录45159条中文词语,每行一个用 /n 隔开,方便拆分使用 哀怜 哀鸣 哀戚 ... 曝光 曝光表 曝露

    我从来不怕背单词

    《我从来不怕背单词》是一款专门帮您定做属于自己的生词本的软件,您可以在里面查询不懂的单词,然后系统会自动给出国际音标、翻译等信息,并储存在数据库中,生成生词本。以后您就可以把自己的生词本通过本系统强大...

    10w+中英双语单词词汇.txt

    10W+ 英语单词 TXT格式,已经整理好中英双语翻译。方便导入excel和word和数据库等文档

    Python 快速(查询/整理)单词,数据库基于有道词典

    生词本是一个文件名为 filename.kirisame.pyword.json的数据文件,默认存放在 ./json目录下。 示例 样例输入 contradictory -a 样例输出 adj. 相互矛盾的,对立的;好反驳的,爱争辩的; n. 矛盾命题 与单词...

    (自定义)单词词典dict.txt

    (自定义)单词词典dict.txt

    牛津词典TXT文件, 可轻松转数据库

    自用的牛津词典的TXT文本文件, 可以使用sqlite3数据库的C语言接口, 轻松将其转换为数据库文件, 可用于实现电子词典小项目

    c语言英语词典对应的英语单词文件

    c语言英语词典对应的英语单词文件 c语言英语词典对应的英语单词文件 c语言英语词典对应的英语单词文件 c语言英语词典对应的英语单词文件 c语言英语词典对应的英语单词文件 c语言英语词典对应的英语单词文件 c语言...

    有道欧路词典生词本高亮-crx插件

    语言:English,中文 (简体) ...可以将有道词典或欧路词典导出的生词本中的单词高亮,在鼠标悬浮时显示出单词的意思和音标并将发音读出来,起到在阅读英文文档时加强记忆单词作用使用方法请参考此网站内容:...

    4300单词.bin

    有道词典可导入单词本,基础单词方便学习。直接导入即可使用。

    中文分词词典UserDict.txt

    在使用jiba分词的情况下,使用这个词典有助于提高你的分词准确度,因为这个分词词典包含了众多领域词汇,这些词汇出自某dog的几十个细胞词库。已使用转换器转换成txt,欢迎下载。

    创建并使用词典类

    2、设计一个简单的词典类Dict,每个单词包括英文单词及对应的中文含义,并有一个英汉翻译成员函数,通过查词典的方式将一段英语翻译成对应的汉语 词典类Dict接口:add( )(添加单词)和trans( )(英汉翻译)成员函数...

Global site tag (gtag.js) - Google Analytics