Skip to content

Commit 6891165

Browse files
authored
Merge pull request #68 from ecmwf/feature/data_keyword
added method to check if a keyword is used for indexing (category: data)
2 parents c6c5c5b + cff606b commit 6891165

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

share/metkit/axis.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ axes:
4949
- resolution
5050
- year
5151
- month
52+
- obsgroup

share/metkit/language.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ _field: &_field
350350
val: 'prod'
351351

352352
dataset:
353+
category: data
353354
multiple: false
354355
type: enum
355356
values:
@@ -1323,7 +1324,6 @@ disseminate:
13231324
type: any
13241325

13251326
use:
1326-
category: data
13271327
flatten: false
13281328
multiple: true
13291329
type: enum

src/metkit/mars/MarsLanguage.cc

+21-7
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,22 @@ MarsLanguage::MarsLanguage(const std::string& verb) : verb_(verb) {
8484
types_[keyword]->attach();
8585
keywords_.push_back(keyword);
8686

87+
std::optional<eckit::Value> aliases;
8788
if (settings.contains("aliases")) {
88-
eckit::Value aliases = settings["aliases"];
89-
for (size_t j = 0; j < aliases.size(); ++j) {
90-
aliases_[aliases[j]] = keyword;
91-
keywords_.push_back(aliases[j]);
89+
aliases = settings["aliases"];
90+
}
91+
if (settings.contains("category") && settings["category"] == "data") {
92+
dataKeywords_.insert(keyword);
93+
if (aliases) {
94+
for (size_t j = 0; j < aliases->size(); ++j) {
95+
dataKeywords_.insert((*aliases)[j]);
96+
}
97+
}
98+
}
99+
if (aliases) {
100+
for (size_t j = 0; j < aliases->size(); ++j) {
101+
aliases_[(*aliases)[j]] = keyword;
102+
keywords_.push_back((*aliases)[j]);
92103
}
93104
}
94105
}
@@ -100,9 +111,7 @@ MarsLanguage::MarsLanguage(const std::string& verb) : verb_(verb) {
100111
}
101112
}
102113

103-
std::set<std::string> keywordsInAxis;
104114
for (const std::string& a : hypercube::AxisOrder::instance().axes()) {
105-
keywordsInAxis.insert(a);
106115
Type* t=nullptr;
107116
auto it = types_.find(a);
108117
if(it != types_.end()) {
@@ -111,10 +120,15 @@ MarsLanguage::MarsLanguage(const std::string& verb) : verb_(verb) {
111120
typesByAxisOrder_.emplace_back(a, t);
112121
}
113122
for (const auto& [k,t] : types_) {
114-
if (keywordsInAxis.find(k) == keywordsInAxis.end()) { typesByAxisOrder_.emplace_back(k, t); }
123+
if (dataKeywords_.find(k) == dataKeywords_.end()) { typesByAxisOrder_.emplace_back(k, t); }
115124
}
116125
}
117126

127+
bool MarsLanguage::isData(const std::string& keyword) const {
128+
return (dataKeywords_.find(keyword) != dataKeywords_.end());
129+
}
130+
131+
118132
MarsLanguage::~MarsLanguage() {
119133
for (std::map<std::string, Type*>::iterator j = types_.begin(); j != types_.end(); ++j) {
120134
(*j).second->detach();

src/metkit/mars/MarsLanguage.h

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class MarsLanguage : private eckit::NonCopyable {
5353

5454
Type* type(const std::string& name) const;
5555

56+
bool isData(const std::string& keyword) const;
57+
5658
public: // class methods
5759

5860
static std::string expandVerb(const MarsExpandContext&, const std::string& verb);
@@ -80,6 +82,7 @@ class MarsLanguage : private eckit::NonCopyable {
8082

8183
std::string verb_;
8284
std::map<std::string, Type* > types_;
85+
std::set<std::string> dataKeywords_;
8386
std::vector<std::pair<std::string, Type*>> typesByAxisOrder_;
8487
std::vector<std::string> keywords_;
8588

0 commit comments

Comments
 (0)