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

📄 wordsfactory.java

📁 实现英文的拼写检查
💻 JAVA
字号:
package entity;

import operation.LineAnalysis;
import operation.WordAnalysis;

//单词工厂类
public class WordsFactory {

	private int wordamount; // 单词数

	// 构造函数
	public WordsFactory() {
		wordamount = 0;
	}

	// 获取单词数
	public int getWordamount() {
		return wordamount;
	}

	// 根据给定的文本创建Word集合 并记录单词数目
	// text 创建Word集合的文本
	public Word[] createWordsFromString(String text) {
		int i = 0, j = 0, k = 0, amount = 0, lineamount = 0;
		WordAnalysis wordAnalysis = new WordAnalysis(text); // 分析所有单词
		LineAnalysis lineAnalysis = new LineAnalysis(text); // 分析所有行
		this.wordamount = wordAnalysis.getWordAmount(); // 计算并保存总单词数
		lineamount = lineAnalysis.getLineAmount(); // 计算总行数
		Word[] words = new Word[this.wordamount];
		for (i = 0, k = 0; i < lineamount; i++) { // 逐行分析
			wordAnalysis = new WordAnalysis(lineAnalysis.getLine(i)); // 分析当前行单词
			amount = wordAnalysis.getWordAmount(); // 计算当前行单词数
			for (j = 0; j < amount; j++, k++) { // 生成当前行word
				words[k] = new Word(wordAnalysis.getWord(j), i, wordAnalysis
						.getStart(j)); // 记录word的单词 行号 位置
			}
		}
		return words;
	}
}

⌨️ 快捷键说明

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