📄 interaction.java
字号:
import java.io.*;
import java.util.ArrayList;
public class Interaction{
public static void main(String[] args){
// Indexer indexer=new Indexer();
// indexer.generateIndex();
IndexTree indexTree=new IndexTree();
indexTree.genarateTree(new File("index.txt"));
System.out.println("输入一个英文单词,/exit退出");
try{
String myWord="";
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
while(!(myWord=br.readLine().trim()).equals("/exit")){
boolean found=false;
ArrayList prototypeList=new WordRevertion().reverse(myWord);
// for(int i=0;i<prototypeList.size();i++)
// System.out.print(prototypeList.get(i)+" ");
for(int i=0;i<prototypeList.size();i++){
int wordIndex=indexTree.GetIndex(prototypeList.get(i).toString());
if(wordIndex>=0){
found=true;
if(i==0){
// System.out.println("在词典中发现该词");
indexTree.lookUp(wordIndex);
}
else{
indexTree.lookUp(wordIndex);
if(myWord.endsWith("s"))
System.out.println("注:"+myWord+"是"+prototypeList.get(i).toString()+"的复数形式");
if(myWord.endsWith("ing"))
System.out.println("注:"+myWord+"是"+prototypeList.get(i).toString()+"的现在分词形式");
if(myWord.endsWith("ed"))
System.out.println("注:"+myWord+"是"+prototypeList.get(i).toString()+"的过去式和过去分词");
}
}
// continue;
else
{
if(indexTree.lookUpInExtra(prototypeList.get(i).toString())){
if(i>0){
if(myWord.endsWith("s"))
System.out.println("注:"+myWord+"是"+prototypeList.get(i).toString()+"的复数形式");
if(myWord.endsWith("ing"))
System.out.println("注:"+myWord+"是"+prototypeList.get(i).toString()+"的现在分词形式");
if(myWord.endsWith("ed"))
System.out.println("注:"+myWord+"是"+prototypeList.get(i).toString()+"的过去式和过去分词");
}
found=true;
// System.out.println("在词典中发现该词");
}
}
}
if(found==false){
System.out.println("未发现该词,准备添加进词库...");
System.out.print("单词:");
String newWord=br.readLine();
System.out.print("音标:");
String phoneticSymbol=br.readLine();
System.out.print("词性: ");
String part=br.readLine();
System.out.print("解释:");
String explanation=br.readLine();
String item=newWord+"["+phoneticSymbol+"]"+part+"."+explanation+"\n";
File extraFile=new File("extra.txt");
RandomAccessFile raf=new RandomAccessFile(extraFile,"rw");
raf.seek(extraFile.length());
raf.writeBytes(new String(item.getBytes("GB2312"),"ISO8859-1"));
System.out.println("已经添加进词库");
raf.close();
System.out.println();
System.out.println("请输入下一个单词");
continue;
}
System.out.println();
System.out.println("请输入下一个单词");
continue;
}
}catch(IOException e){
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -