/** * 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 private Item instantiateEquivItem(String field, OperatorNode<ExpressionOperator> ast) { List<OperatorNode<ExpressionOperator>> args = ast.getArgument(1); Preconditions.checkArgument(args.size() >= 2, "Expected 2 or more arguments, got %s.", args.size()); EquivItem equiv = new EquivItem(); equiv.setIndexName(field); for (OperatorNode<ExpressionOperator> arg : args) { switch (arg.getOperator()) { case LITERAL: equiv.addItem(instantiateWordItem(field, arg, equiv.getClass())); break; case CALL: assertHasFunctionName(arg, PHRASE); equiv.addItem(instantiatePhraseItem(field, arg)); break; default: throw newUnexpectedArgumentException(arg.getOperator(), ExpressionOperator.CALL, ExpressionOperator.LITERAL); } } return leafStyleSettings(ast, equiv); }
@NonNull private Item instantiateEquivItem(String field, String key, Inspector value) { HashMap<Integer, Inspector> children = getChildrenMap(value); Preconditions.checkArgument(children.size() >= 2, "Expected 2 or more arguments, got %s.", children.size()); EquivItem equiv = new EquivItem(); equiv.setIndexName(field); for (Inspector word : children.values()){ if (word.type() == STRING || word.type() == LONG || word.type() == DOUBLE){ equiv.addItem(new WordItem(word.asString(), field)); } if (word.type() == OBJECT){ word.traverse((ObjectTraverser) (key2, value2) -> { assertHasOperator(key2, PHRASE); equiv.addItem(instantiatePhraseItem(field, key2, value2)); }); } } return leafStyleSettings(getAnnotations(value), equiv); }
/** * create an EQUIV with the given item as child. * The new EQUIV will take connectivity, * significance and weight from the given item. * * @param item Will be modified and added as a child. **/ public EquivItem(Item item) { addItem(item); // steal other item's connectivity: if (item.connectedItem != null) { setConnectivity(item.connectedItem, item.connectivity); item.connectedItem = null; item.connectivity = 0.0; } TaggableItem back = (TaggableItem)item.connectedBacklink; if (back != null) { back.setConnectivity(this, back.getConnectivity()); item.connectedBacklink = null; } // steal other item's significance: if (item.explicitSignificance) { setSignificance(item.significance); } // steal other item's weight: setWeight(item.getWeight()); // we have now stolen all of the other item's unique id needs: item.setHasUniqueID(false); }
EquivItem equiv = new EquivItem(); equiv.addItem(topLevelItem); return equiv;