⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spellchecker.java

📁 拼写检查器用来拼写检查一个字典中是否有这个词
💻 JAVA
字号:
package 拼写检查器;

import java.util.*;

public class SpellChecker {
	static TreeSet words,dictionary;
	public SpellChecker(){
		words=new TreeSet();
		dictionary=new TreeSet();
	}
	public void addToDictionary(String word){
		final String DELIMITERS="\n\t\r;:,.!?() ";
		StringTokenizer tokens=new StringTokenizer(word,DELIMITERS);
		String wor;
		while(tokens.hasMoreTokens()){
			wor=tokens.nextToken().toLowerCase();
			dictionary.add(wor);
		}
		
	}
	public void addToWordSet(String line){
		final String DELIMITERS="\n\t\r;:,.!?() ";
		StringTokenizer tokens=new StringTokenizer(line,DELIMITERS);
		String word;
		while(tokens.hasMoreTokens()){
			word=tokens.nextToken().toLowerCase();
			words.add(word);
		}
	}
	public LinkedList compare(){
		LinkedList misspelled=new LinkedList();
		String word;
		Iterator itr=words.iterator();
		while(itr.hasNext()){
			word=(String)itr.next();
			if(!dictionary.contains(word))
				misspelled.add(word);
		}
		return misspelled;
	}
	public String outputDictionary(){
		String s="";
		Iterator itr=dictionary.iterator();
		while(itr.hasNext()){
			s+=itr.next()+"\n";
		}
		return s;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -