/** * Reads all possible derivations of the word at the position "currentWordIndex" in the BigList * "in" and puts them into the List "derivations". * * @return the index of the next line containing a different word */ private final long findEquals(long currentWordIndex, BigList in, List<Derivation> derivations) throws IOException { String s1 = in.getLine(currentWordIndex); Word w1 = (Word) mapper.toSymbolSequence(s1); derivations.add(w1.getDerivation()); long pos = currentWordIndex + 1; long length = in.size(); while (pos < length) { Word w2 = getWord(in, pos); if (w1.equals(w2)) { derivations.add(w2.getDerivation()); } else { return pos; } pos++; } return pos; }
/** * @param from * @param line * @return * @throws IOException */ private Word getWord(BigList from, long line) throws IOException { String s1 = from.getLine(line); Word word = (Word) mapper.toSymbolSequence(s1); return word; }
/** * @param to * @param w * @param soa * @throws IOException */ private final void writeOut(BigList to, Word w, Derivation soa) throws IOException { Word w2 = new Word(w, soa); String s2 = mapper.toString(w2); to.append(s2); }
public PermutationReducer(Grammar g) { mapper = StringMapper.getInstance(g); }