public boolean equals(Object object) { if (!super.equals(object)) { return false; } IndexedItem other = (IndexedItem) object; // Ensured by superclass if (!this.index.equals(other.getIndexName())) { return false; } return true; }
public String getIndexedString() { StringBuilder buf = new StringBuilder(); for (Iterator<Item> i = getItemIterator(); i.hasNext();) { IndexedItem indexedItem = (IndexedItem) i.next(); buf.append(indexedItem.getIndexedString()); if (i.hasNext()) { buf.append(' '); } } return buf.toString(); }
public int getNumWords() { int numWords = 0; for (Iterator<Item> j = getItemIterator(); j.hasNext();) { numWords += ((IndexedItem) j.next()).getNumWords(); } return numWords; }
/** * Assigns the default index to query terms having no default index The * parser _should_ have done this, for some reason it doesn't * * @param defaultIndex The default index to assign. * @param item The item to check. */ private static void assignDefaultIndex(final String defaultIndex, Item item) { if (defaultIndex == null || item == null) return; if (item instanceof IndexedItem) { IndexedItem indexName = (IndexedItem) item; if ("".equals(indexName.getIndexName())) indexName.setIndexName(defaultIndex); } else if (item instanceof CompositeItem) { Iterator<Item> items = ((CompositeItem)item).getItemIterator(); while (items.hasNext()) assignDefaultIndex(defaultIndex, items.next()); } }
private static void initializeIndexedItem(IndexedItem indexedItem, ItemArguments arguments, ItemContext itemContext) { Object index = arguments.properties.get(indexProperty); if (index != null) { TypeCheck.ensureInstanceOf(index, String.class); indexedItem.setIndexName((String) index); } }
public void setIndexName(String index) { super.setIndexName(index); for (Iterator<Item> i = getItemIterator(); i.hasNext();) { IndexedItem word = (IndexedItem) i.next(); word.setIndexName(index); } }
public boolean equals(Object object) { if (!super.equals(object)) { return false; } IndexedItem other = (IndexedItem) object; // Ensured by superclass if (!this.index.equals(other.getIndexName())) { return false; } return true; }
private static void annotatedTerm(StringBuilder destination, IndexedItem w, String annotations) { if (annotations.length() > 0) { destination.append("([{").append(annotations).append("}]"); } destination.append('"'); escape(w.getIndexedString(), destination).append('"'); if (annotations.length() > 0) { destination.append(')'); } }
private void addIndexedItem(IndexedItem word) { word.setIndexName(this.getIndexName()); super.addItem((Item) word); }
/** A special purpose check used to simplify the above */ private boolean equalIndexNameIfParentIsPhrase(Item item,CompositeItem parent) { if ( ! (parent instanceof PhraseItem)) return true; if ( ! (item instanceof IndexedItem)) return true; return ((PhraseItem)parent).getIndexName().equals(((IndexedItem)item).getIndexName()); }
public String getIndexedString() { StringBuilder buf = new StringBuilder(); for (Iterator<Item> i = getItemIterator(); i.hasNext();) { IndexedItem indexedItem = (IndexedItem) i.next(); buf.append(indexedItem.getIndexedString()); if (i.hasNext()) { buf.append(' '); } } return buf.toString(); }
private void addIndexedItem(int index, IndexedItem word) { word.setIndexName(this.getIndexName()); super.addItem(index, (Item) word); }
static String getIndexName(Item item) { if (!(item instanceof IndexedItem)) throw new IllegalArgumentException("Expected IndexedItem, got " + item.getClass()); return normalizeIndexName(((IndexedItem) item).getIndexName()); }
@Override boolean serialize(StringBuilder destination, Item item) { EquivItem e = (EquivItem) item; String annotations = leafAnnotations(e); destination.append(getIndexName(e.getItem(0))).append(" contains "); if (annotations.length() > 0) { destination.append("([{").append(annotations).append("}]"); } destination.append(EQUIV).append('('); int initLen = destination.length(); for (Iterator<Item> i = e.getItemIterator(); i.hasNext();) { Item x = i.next(); if (destination.length() > initLen) { destination.append(", "); } if (x instanceof PhraseItem) { PhraseSerializer.serialize(destination, x, false); } else { destination.append('"'); escape(((IndexedItem) x).getIndexedString(), destination); destination.append('"'); } } if (annotations.length() > 0) { destination.append(')'); } destination.append(')'); return false; }
private Item setIndexedItem(int index, IndexedItem word) { word.setIndexName(this.getIndexName()); return super.setItem(index, (Item) word); }
private static void initializeIndexedForm(DispatchForm form, IndexedItem item) { String index = item.getIndexName(); if (!index.isEmpty()) { form.setProperty(indexProperty, index); } }
terms.add(String.valueOf(item.getItemCount())); for (Iterator<Item> i = item.getItemIterator(); i.hasNext(); ) { terms.add(((IndexedItem)i.next()).getIndexedString());
@Override public boolean equals(Object object) { if (!super.equals(object)) return false; IndexedItem other = (IndexedItem) object; // Ensured by superclass return this.index.equals(other.getIndexName()); }
/** * create an EQUIV with the given item and a set * of alternate words as children. * The new EQUIV will take connectivity, * significance and weight from the given item. * * @param item Will be modified and added as a child. * @param words Set of words to create WordItems from. **/ public EquivItem(Item item, Collection<String> words) { this(item); String idx = ((IndexedItem)item).getIndexName(); for (String word : words) { WordItem witem = new WordItem(word, idx); addItem(witem); } } }
@NonNull public String getIndexName() { if (getItemCount() == 0) { return ""; } else { return ((IndexedItem) getItem(0)).getIndexName(); } }