in fop-core/src/main/java/org/apache/fop/hyphenation/HyphenationTree.java [631:783]
public static void main(String[] argv) throws Exception {
HyphenationTree ht = null;
int minCharCount = 2;
BufferedReader in
= new BufferedReader(new java.io.InputStreamReader(System.in));
while (true) {
System.out.print("l:\tload patterns from XML\n"
+ "L:\tload patterns from serialized object\n"
+ "s:\tset minimum character count\n"
+ "w:\twrite hyphenation tree to object file\n"
+ "h:\thyphenate\n"
+ "f:\tfind pattern\n"
+ "b:\tbenchmark\n"
+ "q:\tquit\n\n"
+ "Command:");
String token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
if (token.equals("f")) {
System.out.print("Pattern: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
System.out.println("Values: " + ht.findPattern(token));
} else if (token.equals("s")) {
System.out.print("Minimun value: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
minCharCount = Integer.parseInt(token);
} else if (token.equals("l")) {
ht = new HyphenationTree();
System.out.print("XML file name: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
ht.loadPatterns(token);
} else if (token.equals("L")) {
ObjectInputStream ois = null;
System.out.print("Object file name: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
try {
ois = new ObjectInputStream(new FileInputStream(token));
ht = (HyphenationTree)ois.readObject();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
//ignore
}
}
}
} else if (token.equals("w")) {
System.out.print("Object file name: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(new FileOutputStream(token));
oos.writeObject(ht);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (oos != null) {
try {
oos.flush();
} catch (IOException e) {
//ignore
}
try {
oos.close();
} catch (IOException e) {
//ignore
}
}
}
} else if (token.equals("h")) {
System.out.print("Word: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
System.out.print("Hyphenation points: ");
System.out.println(ht.hyphenate(token, minCharCount,
minCharCount));
} else if (token.equals("b")) {
if (ht == null) {
System.out.println("No patterns have been loaded.");
break;
}
System.out.print("Word list filename: ");
token = in.readLine();
if (token == null) {
break;
}
token = token.trim();
long starttime = 0;
int counter = 0;
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(token));
String line;
starttime = System.currentTimeMillis();
while ((line = reader.readLine()) != null) {
// System.out.print("\nline: ");
Hyphenation hyp = ht.hyphenate(line, minCharCount,
minCharCount);
if (hyp != null) {
String hword = hyp.toString();
// System.out.println(line);
// System.out.println(hword);
} else {
// System.out.println("No hyphenation");
}
counter++;
}
} catch (Exception ioe) {
System.out.println("Exception " + ioe);
ioe.printStackTrace();
} finally {
IOUtils.closeQuietly(reader);
}
long endtime = System.currentTimeMillis();
long result = endtime - starttime;
System.out.println(counter + " words in " + result
+ " Milliseconds hyphenated");
} else if (token.equals("q")) {
break;
}
}
}