コード例 #1
0
 /**
  * Parse text from reader and write word broken output to writer
  *
  * @param r
  * @param w
  * @throws IOException
  */
 public void parse(BufferedReader r, BufferedWriter w) throws IOException {
   MyanmarParser mp = new MyanmarParser();
   String line = r.readLine();
   Vector<ClusterProperties> syllables = new Vector<ClusterProperties>();
   while (line != null) {
     int offset = 0;
     do {
       if (line.length() == 0) {
         w.newLine();
         continue;
       }
       ClusterProperties cp = mp.getNextSyllable(line, offset);
       syllables.add(cp);
       MyPairStatus status = cp.getBreakStatus();
       if (status == MyPairStatus.MY_PAIR_WORD_BREAK
           || status == MyPairStatus.MY_PAIR_EOL
           || status == MyPairStatus.MY_PAIR_PUNCTUATION) {
         checkAndAppendSyllables(w, line, syllables);
       }
       offset = cp.getEnd();
     } while (offset < line.length());
     w.newLine();
     line = r.readLine();
   }
 }
コード例 #2
0
 /**
  * Constructor
  *
  * @param spacer - char to place in breaks which are found
  * @param dictionary
  * @throws IOException
  */
 public MyanmarBreaker(char spacer, BufferedReader dictionary) throws IOException {
   mSpacer = spacer;
   MyanmarParser mp = new MyanmarParser();
   if (dictionary != null) {
     String word = dictionary.readLine();
     while (word != null) {
       int offset = 0;
       int syllableCount = 0;
       while (offset < word.length()) {
         ClusterProperties cp = mp.getNextLineBreak(word, offset);
         offset = cp.getEnd();
         ++syllableCount;
       }
       mMaxSyllables = Math.max(mMaxSyllables, syllableCount);
       mWordList.add(word);
       word = dictionary.readLine();
     }
   }
 }