/** * Constructs new text aligner that servers requests for alignment of * sequence of words with the provided database sequence. Sequences are * aligned by tuples comprising one or more subsequent words. * * @param words list of words forming the database * @param tupleSize size of a tuple, must be greater or equal to 1 */ public LongTextAligner(List<String> words, int tupleSize) { assert words != null; assert tupleSize > 0; this.tupleSize = tupleSize; this.refWords = words; int offset = 0; reftup = getTuples(words); tupleIndex = new HashMap<String, ArrayList<Integer>>(); for (String tuple : reftup) { ArrayList<Integer> indexes = tupleIndex.get(tuple); if (indexes == null) { indexes = new ArrayList<Integer>(); tupleIndex.put(tuple, indexes); } indexes.add(offset++); } }
/** * Aligns query sequence with the previously built database. * @param words list words to look for * @param range range of database to look for alignment * * @return indices of alignment */ public int[] align(List<String> words, Range range) { if (range.upperEndpoint() - range.lowerEndpoint() < tupleSize || words.size() < tupleSize) { return alignTextSimple(refWords.subList(range.lowerEndpoint(), range.upperEndpoint()), words, range.lowerEndpoint()); } int[] result = new int[words.size()]; fill(result, -1); int lastIndex = 0; for (Alignment.Node node : new Alignment(getTuples(words), range) .getIndices()) { // for (int j = 0; j < tupleSize; ++j) lastIndex = max(lastIndex, node.getQueryIndex()); for (; lastIndex < node.getQueryIndex() + tupleSize; ++lastIndex) result[lastIndex] = node.getDatabaseIndex() + lastIndex - node.getQueryIndex(); } return result; }
/** * Constructs new text aligner that servers requests for alignment of * sequence of words with the provided database sequence. Sequences are * aligned by tuples comprising one or more subsequent words. * * @param words list of words forming the database * @param tupleSize size of a tuple, must be greater or equal to 1 */ public LongTextAligner(List<String> words, int tupleSize) { assert words != null; assert tupleSize > 0; this.tupleSize = tupleSize; this.refWords = words; int offset = 0; reftup = getTuples(words); tupleIndex = new HashMap<String, ArrayList<Integer>>(); for (String tuple : reftup) { ArrayList<Integer> indexes = tupleIndex.get(tuple); if (indexes == null) { indexes = new ArrayList<Integer>(); tupleIndex.put(tuple, indexes); } indexes.add(offset++); } }
/** * Aligns query sequence with the previously built database. * @param words list words to look for * @param range range of database to look for alignment * * @return indices of alignment */ public int[] align(List<String> words, Range range) { if (range.upperEndpoint() - range.lowerEndpoint() < tupleSize || words.size() < tupleSize) { return alignTextSimple(refWords.subList(range.lowerEndpoint(), range.upperEndpoint()), words, range.lowerEndpoint()); } int[] result = new int[words.size()]; fill(result, -1); int lastIndex = 0; for (Alignment.Node node : new Alignment(getTuples(words), range) .getIndices()) { // for (int j = 0; j < tupleSize; ++j) lastIndex = max(lastIndex, node.getQueryIndex()); for (; lastIndex < node.getQueryIndex() + tupleSize; ++lastIndex) result[lastIndex] = node.getDatabaseIndex() + lastIndex - node.getQueryIndex(); } return result; }