?? wordsfactory.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 + -