aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/vespa/searchsummary/docsummary/annotation_converter.h
blob: 59b03c64540d4bd919665a3325e564b5de79d5e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "i_string_field_converter.h"
#include <vespa/vespalib/stllike/asciistream.h>

namespace document { class Span; }

namespace vespalib { class asciistream; }

namespace search::docsummary {

class IJuniperConverter;

/*
 * Class converting a string field value with annotations into a string
 * with interlinear annotations used by juniper before passing it to
 * the juniper converter.
 */
class AnnotationConverter : public IStringFieldConverter
{
    IJuniperConverter&     _juniper_converter;
    vespalib::stringref    _text;
    vespalib::asciistream  _out;

    template <typename ForwardIt>
    void handleAnnotations(const document::Span& span, ForwardIt it, ForwardIt last);
    template <typename ForwardIt>
    void annotateSpans(const document::Span& span, ForwardIt it, ForwardIt last);
    void handleIndexingTerms(const document::StringFieldValue& value);
public:
    AnnotationConverter(IJuniperConverter& juniper_converter);
    ~AnnotationConverter() override;
    void convert(const document::StringFieldValue &input, vespalib::slime::Inserter& inserter) override;
};

}