Search in sources :

Example 6 with TaggableItem

use of com.yahoo.prelude.query.TaggableItem in project vespa by vespa-engine.

the class YqlParser method leafStyleSettings.

@NonNull
private <T extends TaggableItem> T leafStyleSettings(OperatorNode<?> ast, @NonNull T out) {
    {
        Map<?, ?> connectivity = getAnnotation(ast, CONNECTIVITY, Map.class, null, "connectivity settings");
        if (connectivity != null) {
            connectedItems.add(new ConnectedItem(out, getMapValue(CONNECTIVITY, connectivity, CONNECTION_ID, Integer.class), getMapValue(CONNECTIVITY, connectivity, CONNECTION_WEIGHT, Number.class).doubleValue()));
        }
        Number significance = getAnnotation(ast, SIGNIFICANCE, Number.class, null, "term significance");
        if (significance != null) {
            out.setSignificance(significance.doubleValue());
        }
        Integer uniqueId = getAnnotation(ast, UNIQUE_ID, Integer.class, null, "term ID", false);
        if (uniqueId != null) {
            out.setUniqueID(uniqueId);
            identifiedItems.put(uniqueId, out);
        }
    }
    {
        Item leaf = (Item) out;
        Map<?, ?> itemAnnotations = getAnnotation(ast, ANNOTATIONS, Map.class, Collections.emptyMap(), "item annotation map");
        for (Map.Entry<?, ?> entry : itemAnnotations.entrySet()) {
            Preconditions.checkArgument(entry.getKey() instanceof String, "Expected String annotation key, got %s.", entry.getKey().getClass());
            Preconditions.checkArgument(entry.getValue() instanceof String, "Expected String annotation value, got %s.", entry.getValue().getClass());
            leaf.addAnnotation((String) entry.getKey(), entry.getValue());
        }
        Boolean filter = getAnnotation(ast, FILTER, Boolean.class, null, FILTER_DESCRIPTION);
        if (filter != null) {
            leaf.setFilter(filter);
        }
        Boolean isRanked = getAnnotation(ast, RANKED, Boolean.class, null, RANKED_DESCRIPTION);
        if (isRanked != null) {
            leaf.setRanked(isRanked);
        }
        String label = getAnnotation(ast, LABEL, String.class, null, "item label");
        if (label != null) {
            leaf.setLabel(label);
        }
        Integer weight = getAnnotation(ast, WEIGHT, Integer.class, null, "term weight for ranking");
        if (weight != null) {
            leaf.setWeight(weight);
        }
    }
    if (out instanceof IntItem) {
        IntItem number = (IntItem) out;
        Integer hitLimit = getCappedRangeSearchParameter(ast);
        if (hitLimit != null) {
            number.setHitLimit(hitLimit);
        }
    }
    return out;
}
Also used : BigInteger(java.math.BigInteger) CompositeItem(com.yahoo.prelude.query.CompositeItem) WordAlternativesItem(com.yahoo.prelude.query.WordAlternativesItem) NullItem(com.yahoo.prelude.query.NullItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) OrItem(com.yahoo.prelude.query.OrItem) PhraseItem(com.yahoo.prelude.query.PhraseItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) SubstringItem(com.yahoo.prelude.query.SubstringItem) AndItem(com.yahoo.prelude.query.AndItem) RankItem(com.yahoo.prelude.query.RankItem) EquivItem(com.yahoo.prelude.query.EquivItem) WeightedSetItem(com.yahoo.prelude.query.WeightedSetItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) PredicateQueryItem(com.yahoo.prelude.query.PredicateQueryItem) WeakAndItem(com.yahoo.prelude.query.WeakAndItem) ONearItem(com.yahoo.prelude.query.ONearItem) DotProductItem(com.yahoo.prelude.query.DotProductItem) Item(com.yahoo.prelude.query.Item) SuffixItem(com.yahoo.prelude.query.SuffixItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) IntItem(com.yahoo.prelude.query.IntItem) WandItem(com.yahoo.prelude.query.WandItem) RegExpItem(com.yahoo.prelude.query.RegExpItem) RangeItem(com.yahoo.prelude.query.RangeItem) WordItem(com.yahoo.prelude.query.WordItem) NotItem(com.yahoo.prelude.query.NotItem) NearItem(com.yahoo.prelude.query.NearItem) IntItem(com.yahoo.prelude.query.IntItem) Map(java.util.Map) LazyMap(com.yahoo.collections.LazyMap) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 7 with TaggableItem

use of com.yahoo.prelude.query.TaggableItem in project vespa by vespa-engine.

the class YqlParser method instantiatePhraseSegmentItem.

@NonNull
private Item instantiatePhraseSegmentItem(String field, OperatorNode<ExpressionOperator> ast, boolean forcePhrase) {
    Substring origin = getOrigin(ast);
    Boolean stem = getAnnotation(ast, STEM, Boolean.class, Boolean.TRUE, STEM_DESCRIPTION);
    Boolean andSegmenting = getAnnotation(ast, AND_SEGMENTING, Boolean.class, Boolean.FALSE, "setting for whether to force using AND for segments on and off");
    SegmentItem phrase;
    List<String> words = null;
    if (forcePhrase || !andSegmenting) {
        phrase = new PhraseSegmentItem(origin.getValue(), origin.getValue(), true, !stem, origin);
    } else {
        phrase = new AndSegmentItem(origin.getValue(), true, !stem);
    }
    phrase.setIndexName(field);
    if (resegment && getAnnotation(ast, IMPLICIT_TRANSFORMS, Boolean.class, Boolean.TRUE, IMPLICIT_TRANSFORMS_DESCRIPTION)) {
        words = segmenter.segment(origin.getValue(), currentlyParsing.getLanguage());
    }
    if (words != null && words.size() > 0) {
        for (String word : words) {
            phrase.addItem(new WordItem(word, field, true));
        }
    } else {
        for (OperatorNode<ExpressionOperator> word : ast.<List<OperatorNode<ExpressionOperator>>>getArgument(1)) {
            phrase.addItem(instantiateWordItem(field, word, phrase.getClass(), SegmentWhen.NEVER));
        }
    }
    if (phrase instanceof TaggableItem) {
        leafStyleSettings(ast, (TaggableItem) phrase);
    }
    phrase.lock();
    return phrase;
}
Also used : Substring(com.yahoo.prelude.query.Substring) TaggableItem(com.yahoo.prelude.query.TaggableItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) List(java.util.List) ArrayList(java.util.ArrayList) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) AndSegmentItem(com.yahoo.prelude.query.AndSegmentItem) SegmentItem(com.yahoo.prelude.query.SegmentItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 8 with TaggableItem

use of com.yahoo.prelude.query.TaggableItem in project vespa by vespa-engine.

the class YqlParser method connectItems.

private void connectItems() {
    for (ConnectedItem entry : connectedItems) {
        TaggableItem to = identifiedItems.get(entry.toId);
        Preconditions.checkNotNull(to, "Item '%s' was specified to connect to item with ID %s, which does not " + "exist in the query.", entry.fromItem, entry.toId);
        entry.fromItem.setConnectivity((Item) to, entry.weight);
    }
}
Also used : TaggableItem(com.yahoo.prelude.query.TaggableItem)

Example 9 with TaggableItem

use of com.yahoo.prelude.query.TaggableItem in project vespa by vespa-engine.

the class YqlParser method resegment.

@NonNull
private TaggableItem resegment(String field, OperatorNode<ExpressionOperator> ast, String wordData, boolean fromQuery, Class<?> parent, Language language) {
    String toSegment = wordData;
    Substring s = getOrigin(ast);
    Language usedLanguage = language == null ? currentlyParsing.getLanguage() : language;
    if (s != null) {
        toSegment = s.getValue();
    }
    List<String> words = segmenter.segment(toSegment, usedLanguage);
    TaggableItem wordItem;
    if (words.size() == 0) {
        wordItem = new WordItem(wordData, fromQuery);
    } else if (words.size() == 1 || !phraseArgumentSupported(parent)) {
        wordItem = new WordItem(words.get(0), fromQuery);
    } else {
        wordItem = new PhraseSegmentItem(toSegment, fromQuery, false);
        ((PhraseSegmentItem) wordItem).setIndexName(field);
        for (String w : words) {
            WordItem segment = new WordItem(w, fromQuery);
            prepareWord(field, ast, fromQuery, segment);
            ((PhraseSegmentItem) wordItem).addItem(segment);
        }
        ((PhraseSegmentItem) wordItem).lock();
    }
    return wordItem;
}
Also used : Substring(com.yahoo.prelude.query.Substring) TaggableItem(com.yahoo.prelude.query.TaggableItem) Language(com.yahoo.language.Language) WordItem(com.yahoo.prelude.query.WordItem) PhraseSegmentItem(com.yahoo.prelude.query.PhraseSegmentItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

TaggableItem (com.yahoo.prelude.query.TaggableItem)9 CompositeItem (com.yahoo.prelude.query.CompositeItem)6 Item (com.yahoo.prelude.query.Item)6 PhraseSegmentItem (com.yahoo.prelude.query.PhraseSegmentItem)4 WordItem (com.yahoo.prelude.query.WordItem)4 NonNull (edu.umd.cs.findbugs.annotations.NonNull)4 AndSegmentItem (com.yahoo.prelude.query.AndSegmentItem)3 SegmentItem (com.yahoo.prelude.query.SegmentItem)3 AndItem (com.yahoo.prelude.query.AndItem)2 DotProductItem (com.yahoo.prelude.query.DotProductItem)2 EquivItem (com.yahoo.prelude.query.EquivItem)2 ExactStringItem (com.yahoo.prelude.query.ExactStringItem)2 IntItem (com.yahoo.prelude.query.IntItem)2 NearItem (com.yahoo.prelude.query.NearItem)2 NotItem (com.yahoo.prelude.query.NotItem)2 NullItem (com.yahoo.prelude.query.NullItem)2 ONearItem (com.yahoo.prelude.query.ONearItem)2 OrItem (com.yahoo.prelude.query.OrItem)2 PhraseItem (com.yahoo.prelude.query.PhraseItem)2 PredicateQueryItem (com.yahoo.prelude.query.PredicateQueryItem)2