blob: ead5b5cd3852cfb818377d6d5b9e50b406da4bd8 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// 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 {
/**
* Simple parser used to split feature names into components by the
* framework.
**/
class FeatureNameParser
{
public:
using string = vespalib::string;
using StringVector = std::vector<string>;
private:
bool _valid;
uint32_t _endPos;
string _baseName;
StringVector _parameters;
string _output;
string _executorName;
string _featureName;
public:
/**
* The constructor parses the given feature name, splitting it
* into components. If the given string is not a valid feature
* name, all components will be empty and the @ref valid method
* will return false.
*
* @param featureName feature name
**/
FeatureNameParser(const vespalib::string &featureName);
~FeatureNameParser();
/**
* Does this object represent a valid feature name?
*
* @return true if valid, false if invalid
**/
bool valid() const { return _valid; }
/**
* Obtain the number of bytes from the original feature name that
* was successfully parsed. If the feature name was valid, this
* method will simply return the size of the string given to the
* constructor. If a parse error occurred, this method will return
* the index of the offending character in the string given to the
* constructor.
*
* @return number of bytes successfully parsed
**/
uint32_t parsedBytes() const { return _endPos; }
/**
* Obtain the base name from the parsed feature name.
*
* @return base name
**/
const string &baseName() const { return _baseName; }
/**
* Obtain the parameter list from the parsed feature name.
*
* @return parameter list
**/
const StringVector ¶meters() const { return _parameters; }
/**
* Obtain the output name from the parsed feature name.
*
* @return output name
**/
const string &output() const { return _output; }
/**
* Obtain a normalized name for the executor making this
* feature. This includes the parameter list. The @ref
* FeatureNameBuilder is used to make this name.
*
* @return normalized executor name with parameters
**/
const string &executorName() const { return _executorName; }
/**
* Obtain a normalized full feature name. The @ref
* FeatureNameBuilder is used to make this name.
*
* @return normalized full feature name
**/
const string &featureName() const { return _featureName; }
};
}
|