aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/fef/featurenamebuilder.h
blob: ad04255acf12415772bc6e6bb144d7a78a0e8ff1 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <vespa/vespalib/stllike/string.h>
#include <vector>

namespace search::fef {

/**
 * An object of this class may be used to build feature names in a
 * convenient way. Using this class will ensure things like correct
 * quoting of reserved characters used in parameters.
 **/
class FeatureNameBuilder
{
private:
    vespalib::string              _baseName;
    std::vector<vespalib::string> _parameters;
    vespalib::string              _output;

public:
    /**
     * Create an empty builder.
     **/
    FeatureNameBuilder();
    ~FeatureNameBuilder();

    /**
     * Set the base name.
     *
     * @return this object, for chaining
     * @param str base name
     **/
    FeatureNameBuilder &baseName(const vespalib::string &str);

    /**
     * Add a parameter to the end of the parameter list.
     *
     * @return this object, for chaining
     * @param str a parameter
     * @param exact if this is true, the parameter will preserve its
     * exact string value. If this is false, the framework is allowed
     * to normalize the string as if it was a feature name.
     **/
    FeatureNameBuilder &parameter(const vespalib::string &str, bool exact = true);

    /**
     * Clear the list of parameters.
     *
     * @return this object, for chaining
     **/
    FeatureNameBuilder &clearParameters();

    /**
     * Set the output name
     *
     * @return this object, for chaining
     * @param str output name
     **/
    FeatureNameBuilder &output(const vespalib::string &str);

    /**
     * Build a full feature name from the information put into this
     * object.
     *
     * @return feature name
     **/
    vespalib::string buildName() const;
};

}