/** * Convert The parent of this item into a mutable item. Note, this * may change the shape of the query tree. (E.g. if the original parent is a * segment phrase, and the original parent's parent is a phrase, the terms * from the parent will be moved to the parent's parent.) * * @param item The item for which the parent shall be made mutable */ public void makeParentMutable(TermItem item) { CompositeItem parent = item.getParent(); CompositeItem mutable = convertSegmentItem(parent); if (parent != mutable) { CompositeItem parentsParent = parent.getParent(); insertMutableInTree(mutable, parent, parentsParent); } }
/** * Creates a match * * @param item the match to add * @param replaceValue the string to replace this match by, usually the item.getIndexedString() * which is what the replace value will be if it is passed as null here */ public Match(FlattenedItem item,String replaceValue) { this.item=item.getItem(); if (replaceValue==null) this.replaceValue=item.getItem().getIndexedString(); else this.replaceValue=replaceValue; this.parent=this.item.getParent(); this.position=item.getPosition(); }
@Override protected boolean doesMatch(RuleEvaluation e) { Choicepoint choicepoint = e.getChoicepoint(this,true); choicepoint.updateState(); boolean matches = e.currentItem().getItem().getParent() instanceof PhraseItem && allSubConditionsMatches(e); if ( ! matches) choicepoint.backtrack(); return matches; }
/** Remove items until there's only one item left */ private void removeNonreferencedMatches(RuleEvaluation e) { int itemCount=e.getEvaluation().getQuerySize(); // Remove items backwards to ease index handling for (int i=e.getNonreferencedMatchCount()-1; i>=0; i--) { // Ensure we don't produce an empty query if (getProduction().getTermCount()==0 && itemCount==1) break; itemCount--; Match match=e.getNonreferencedMatch(i); match.getItem().getParent().removeItem(match.getPosition()); } }