사용자 입력을 받아 해당 문자열을 토큰으로 분리 한 다음 사전에서 해당 문자열의 단어를 검색하는 프로그램을 구현하려고합니다. 파싱 된 문자열에 대한 나의 목표는 모든 단일 토큰을 영어 단어로 만드는 것입니다. 예를 들어Java Dictionary Searcher
:
Input:
aman
Split Method:
a man
a m an
a m a n
am an
am a n
ama n
Desired Output:
a man
나는 현재 원하는 출력 부까지 모든 것을 수행이 코드를 가지고 : 나는 그런으로 사전을 (저장하는 더 나은 방법이 알고
import java.util.Scanner;
import java.io.*;
public class Words {
public static String[] dic = new String[80368];
public static void split(String head, String in) {
// head + " " + in is a segmentation
String segment = head + " " + in;
// count number of dictionary words
int count = 0;
Scanner phraseScan = new Scanner(segment);
while (phraseScan.hasNext()) {
String word = phraseScan.next();
for (int i=0; i<dic.length; i++) {
if (word.equalsIgnoreCase(dic[i])) count++;
}
}
System.out.println(segment + "\t" + count + " English words");
// recursive calls
for (int i=1; i<in.length(); i++) {
split(head+" "+in.substring(0,i), in.substring(i,in.length()));
}
}
public static void main (String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.print("Enter a string: ");
String input = scan.next();
System.out.println();
Scanner filescan = new Scanner(new File("src:\\dictionary.txt"));
int wc = 0;
while (filescan.hasNext()) {
dic[wc] = filescan.nextLine();
wc++;
}
System.out.println(wc + " words stored");
split("", input);
}
}
을 이진 검색 트리 또는 해시 테이블),하지만 어쨌든 그 구현하는 방법을 모르겠습니다.
분할 문자열을 검사하여 모든 세그먼트가 사전에있는 단어인지 확인하는 방법을 구현하는 방법에 집착하고 있습니다.
어떤 도움이 좋을 것, 내 대답은 바보 보인다면 당신은 정말 가까이있어, 난 당신이 붙어있어 어디 모르겠어요 때문에, 그것의 당신에게
가능한 중복 [말씀이 사전에인지 (http://stackoverflow.com/questions/5918838/word-is-in-dictionary - 또는 - 아니요) –
예상되는 가장 큰 입력 문자열은 무엇입니까? –
그것은 길이가 될 수 있지만 아마 20 자보다 오래 걸릴 것이라고는 생각하지 않습니다. 저는 50이라고 말합니다. MAX – Brendan