private static String wordAnnotations(WordItem item) {
            Substring origin = item.getOrigin();
            boolean usePositionData = item.usePositionData();
            boolean stemmed = item.isStemmed();
            boolean lowercased = item.isLowercased();
            boolean accentDrop = item.isNormalizable();
            SegmentingRule andSegmenting = item.getSegmentingRule();
            boolean isFromQuery = item.isFromQuery();
            StringBuilder annotation = new StringBuilder();
            boolean prefix = item instanceof PrefixItem;
            boolean suffix = item instanceof SuffixItem;
            boolean substring = item instanceof SubstringItem;
            int initLen = annotation.length();
            String image;
            int offset;
            int length;

            if (origin == null) {
                image = item.getRawWord();
                offset = 0;
                length = image.length();
            } else {
                image = origin.getSuperstring();
                offset = origin.start;
                length = origin.end - origin.start;
            }

            if (!image.substring(offset, offset + length).equals(item.getIndexedString())) {
                VespaSerializer.serializeOrigin(annotation, image, offset, length);
            }
            if ( ! usePositionData) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(USE_POSITION_DATA).append(": false");
            }
            if (stemmed) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(STEM).append(": false");
            }
            if (lowercased) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(NORMALIZE_CASE).append(": false");
            }
            if ( ! accentDrop) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(ACCENT_DROP).append(": false");
            }
            if (andSegmenting == SegmentingRule.BOOLEAN_AND) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(AND_SEGMENTING).append(": true");
            }
            if (!isFromQuery) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(IMPLICIT_TRANSFORMS).append(": false");
            }
            if (prefix) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(PREFIX).append(": true");
            }
            if (suffix) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(SUFFIX).append(": true");
            }
            if (substring) {
                VespaSerializer.comma(annotation, initLen);
                annotation.append(SUBSTRING).append(": true");
            }
            return annotation.toString();
        }
Serialize Vespa query trees to YQL+ strings.

@author Steinar Knutsen
container-search/src/main/java/com/yahoo/search/yql/VespaSerializer.java