Search in sources :

Example 1 with TaggableItem

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

the class Model method addSignificances.

private void addSignificances(List<Item> candidates, Ranking ranking) {
    for (Item candidate : candidates) {
        TaggableItem t = (TaggableItem) candidate;
        if (!t.hasExplicitSignificance())
            continue;
        String name = "vespa.term." + t.getUniqueID() + ".significance";
        ranking.getProperties().put(name, String.valueOf(t.getSignificance()));
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) Item(com.yahoo.prelude.query.Item) TaggableItem(com.yahoo.prelude.query.TaggableItem)

Example 2 with TaggableItem

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

the class Model method addLabels.

private void addLabels(List<Item> candidates, Ranking ranking) {
    for (Item candidate : candidates) {
        String label = candidate.getLabel();
        if (label != null) {
            String name = "vespa.label." + label + ".id";
            TaggableItem t = (TaggableItem) candidate;
            ranking.getProperties().put(name, String.valueOf(t.getUniqueID()));
        }
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) Item(com.yahoo.prelude.query.Item) TaggableItem(com.yahoo.prelude.query.TaggableItem)

Example 3 with TaggableItem

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

the class YqlParser method instantiateWordItem.

@NonNull
private Item instantiateWordItem(String field, String rawWord, OperatorNode<ExpressionOperator> ast, Class<?> parent, SegmentWhen segmentPolicy, boolean exactMatch, Language language) {
    String wordData = rawWord;
    if (getAnnotation(ast, NFKC, Boolean.class, Boolean.FALSE, "setting for whether to NFKC normalize input data")) {
        // NOTE: If this is set to FALSE (default), we will still NFKC normalize text data
        // during tokenization/segmentation, as that is always turned on also on the indexing side.
        wordData = normalizer.normalize(wordData);
    }
    boolean fromQuery = getAnnotation(ast, IMPLICIT_TRANSFORMS, Boolean.class, Boolean.TRUE, IMPLICIT_TRANSFORMS_DESCRIPTION);
    boolean prefixMatch = getAnnotation(ast, PREFIX, Boolean.class, Boolean.FALSE, "setting for whether to use prefix match of input data");
    boolean suffixMatch = getAnnotation(ast, SUFFIX, Boolean.class, Boolean.FALSE, "setting for whether to use suffix match of input data");
    boolean substrMatch = getAnnotation(ast, SUBSTRING, Boolean.class, Boolean.FALSE, "setting for whether to use substring match of input data");
    Preconditions.checkArgument((prefixMatch ? 1 : 0) + (substrMatch ? 1 : 0) + (suffixMatch ? 1 : 0) < 2, "Only one of prefix, substring and suffix can be set.");
    @NonNull final TaggableItem wordItem;
    if (exactMatch) {
        wordItem = new ExactStringItem(wordData, fromQuery);
    } else if (prefixMatch) {
        wordItem = new PrefixItem(wordData, fromQuery);
    } else if (suffixMatch) {
        wordItem = new SuffixItem(wordData, fromQuery);
    } else if (substrMatch) {
        wordItem = new SubstringItem(wordData, fromQuery);
    } else {
        switch(segmentPolicy) {
            case NEVER:
                wordItem = new WordItem(wordData, fromQuery);
                break;
            case POSSIBLY:
                if (shouldResegmentWord(field, fromQuery)) {
                    wordItem = resegment(field, ast, wordData, fromQuery, parent, language);
                } else {
                    wordItem = new WordItem(wordData, fromQuery);
                }
                break;
            case ALWAYS:
                wordItem = resegment(field, ast, wordData, fromQuery, parent, language);
                break;
            default:
                throw new IllegalArgumentException("Unexpected segmenting rule: " + segmentPolicy);
        }
    }
    if (wordItem instanceof WordItem) {
        prepareWord(field, ast, fromQuery, (WordItem) wordItem);
    }
    if (// mark the language used, unless it's the default
    language != Language.ENGLISH)
        ((Item) wordItem).setLanguage(language);
    return (Item) leafStyleSettings(ast, wordItem);
}
Also used : SuffixItem(com.yahoo.prelude.query.SuffixItem) 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) TaggableItem(com.yahoo.prelude.query.TaggableItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull) SubstringItem(com.yahoo.prelude.query.SubstringItem) WordItem(com.yahoo.prelude.query.WordItem) PrefixItem(com.yahoo.prelude.query.PrefixItem) ExactStringItem(com.yahoo.prelude.query.ExactStringItem) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 4 with TaggableItem

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

the class Model method setUniqueIDs.

private List<Item> setUniqueIDs(Item root) {
    List<Item> items = new ArrayList<>();
    collectTaggableItems(root, items);
    int id = 1;
    for (Item i : items) {
        TaggableItem t = (TaggableItem) i;
        t.setUniqueID(id++);
    }
    return items;
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) Item(com.yahoo.prelude.query.Item) TaggableItem(com.yahoo.prelude.query.TaggableItem)

Example 5 with TaggableItem

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

the class Model method addConnectivityRankProperties.

private void addConnectivityRankProperties(List<Item> connectedItems, Ranking ranking) {
    for (Item link : connectedItems) {
        TaggableItem t = (TaggableItem) link;
        Item connectedTo = t.getConnectedItem();
        if (connectedTo != null && strictContains(connectedTo, connectedItems)) {
            TaggableItem t2 = (TaggableItem) connectedTo;
            String name = "vespa.term." + t.getUniqueID() + ".connexity";
            ranking.getProperties().put(name, String.valueOf(t2.getUniqueID()));
            ranking.getProperties().put(name, String.valueOf(t.getConnectivity()));
        }
    }
}
Also used : CompositeItem(com.yahoo.prelude.query.CompositeItem) TaggableItem(com.yahoo.prelude.query.TaggableItem) Item(com.yahoo.prelude.query.Item) TaggableItem(com.yahoo.prelude.query.TaggableItem)

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