/** * Returns a subitem as a block item, * * @param index * the (0-base) index of the item to return * @throws IndexOutOfBoundsException * if there is no subitem at index */ public BlockItem getBlockItem(int index) { return (BlockItem) getItem(index); }
private Item collapsePhrase(PhraseItem root) { if (root.getItemCount() == 1) return root.getItem(0); else return root; }
/** * Returns a subitem as a word item * * @param index * the (0-base) index of the item to return * @throws IndexOutOfBoundsException * if there is no subitem at index */ public WordItem getWordItem(int index) { return (WordItem) getItem(index); }
private void repeatedConsecutiveTermsInPhraseCheck(PhraseItem phrase) { if (phrase.getItemCount() > MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) { String prev = null; int repeatedCount = 0; for (int i = 0; i < phrase.getItemCount(); ++i) { Item item = phrase.getItem(i); if (item instanceof TermItem) { TermItem term = (TermItem) item; String current = term.getIndexedString(); if (prev != null) { if (prev.equals(current)) { repeatedCount++; if (repeatedCount >= MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) { repeatedConsecutiveTermsInPhraseRejections.add(); throw new IllegalArgumentException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE + " ocurrences of term '" + current + "' in a row detected in phrase : " + phrase.toString()); } } else { repeatedCount = 0; } } prev = current; } else { prev = null; repeatedCount = 0; } } } } private static final class Count {
private void repeatedTermsInPhraseCheck(PhraseItem phrase) { if (phrase.getItemCount() > MAX_REPEATED_TERMS_IN_PHRASE) { Map<String, Count> repeatedCount = new HashMap<>(); for (int i = 0; i < phrase.getItemCount(); ++i) { Item item = phrase.getItem(i); if (item instanceof TermItem) { TermItem term = (TermItem) item; String current = term.getIndexedString(); Count count = repeatedCount.get(current); if (count != null) { if (count.get() >= MAX_REPEATED_TERMS_IN_PHRASE) { repeatedTermsInPhraseRejections.add(); throw new IllegalArgumentException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE + " occurrences of term '" + current + "' in phrase : " + phrase.toString()); } count.inc(); } else { repeatedCount.put(current, new Count(1)); } } } } }
destination.append(", "); Item current = phrase.getItem(i); if (current instanceof WordItem) { WordSerializer.serializeWordWithoutIndex(destination, current);