diff --git a/VERSION b/VERSION index bcc565f..de1a208 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.11.18 +1.11.19 diff --git a/src/metkit/mars/MarsLanguage.cc b/src/metkit/mars/MarsLanguage.cc index ab47873..7f0f69d 100644 --- a/src/metkit/mars/MarsLanguage.cc +++ b/src/metkit/mars/MarsLanguage.cc @@ -144,9 +144,9 @@ static bool isnumeric(const std::string& s) { } std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::string& name, - const std::vector& values, bool fail, bool quiet, + const std::vector& values, bool fail, bool quiet, bool fullMatch, const std::map& aliases) { - size_t score = 1; + size_t score = (fullMatch ? name.length() : 1); std::vector best; static bool strict = eckit::Resource("$METKIT_LANGUAGE_STRICT_MODE", false); @@ -282,7 +282,7 @@ std::string MarsLanguage::expandVerb(const MarsExpandContext& ctx, const std::st // } // return cache_[verb] = bestMatch(verb, verbs_, true); - return bestMatch(ctx, verb, verbs_, true, true); + return bestMatch(ctx, verb, verbs_, true, true, false); } class TypeHidden : public Type { @@ -325,7 +325,7 @@ MarsRequest MarsLanguage::expand(const MarsExpandContext& ctx, const MarsRequest p = (*c).second; } else { - p = cache_[*j] = bestMatch(ctx, *j, keywords_, true, false, aliases_); + p = cache_[*j] = bestMatch(ctx, *j, keywords_, true, false, false, aliases_); } // if (seen.find(p) != seen.end()) { diff --git a/src/metkit/mars/MarsLanguage.h b/src/metkit/mars/MarsLanguage.h index 601fa72..4583b42 100644 --- a/src/metkit/mars/MarsLanguage.h +++ b/src/metkit/mars/MarsLanguage.h @@ -62,6 +62,7 @@ class MarsLanguage : private eckit::NonCopyable { const std::vector& values, bool fail, bool quiet, + bool fullMatch, const StringMap& aliases = StringMap()); static eckit::Value jsonFile(const std::string& name); diff --git a/src/metkit/mars/TypeEnum.cc b/src/metkit/mars/TypeEnum.cc index 69e910c..e7a0083 100644 --- a/src/metkit/mars/TypeEnum.cc +++ b/src/metkit/mars/TypeEnum.cc @@ -86,7 +86,7 @@ bool TypeEnum::expand(const MarsExpandContext& ctx, std::string& value) const { return true; } - std::string v = MarsLanguage::bestMatch(ctx, value, values_, false, false, mapping_); + std::string v = MarsLanguage::bestMatch(ctx, value, values_, false, false, false, mapping_); if (v.empty()) { return false; } diff --git a/src/metkit/mars/TypeParam.cc b/src/metkit/mars/TypeParam.cc index f417f22..9640b19 100644 --- a/src/metkit/mars/TypeParam.cc +++ b/src/metkit/mars/TypeParam.cc @@ -355,11 +355,12 @@ std::string Rule::lookup(const MarsExpandContext& ctx, const std::string & s, bo ChainedContext c(ctx, *this); - std::string paramid = metkit::mars::MarsLanguage::bestMatch(c, s, values_, false, false, mapping_); + std::string paramid = metkit::mars::MarsLanguage::bestMatch(c, s, values_, false, false, true, mapping_); if (!paramid.empty()) { return paramid; } - return metkit::mars::MarsLanguage::bestMatch(c, s, defaultValues_, fail, false, defaultMapping_); + + return metkit::mars::MarsLanguage::bestMatch(c, s, defaultValues_, fail, false, false, defaultMapping_); } static std::vector* rules = nullptr; @@ -436,7 +437,7 @@ static void init() { std::set shortnames; std::set associatedIDs; - + const eckit::Value pc = eckit::YAMLParser::decodeFile(LibMetkit::shortnameContextYamlFile()); ASSERT(pc.isList()); @@ -446,11 +447,10 @@ static void init() { for (size_t i=0; i < keys.size(); i++) { auto el = ids.element(keys[i]); - ASSERT(el.size() > 0); - auto val = el[0]; - - if (shortnames.find(val) != shortnames.end()) { - associatedIDs.emplace(keys[i]); + for (size_t j=0; j < el.size(); j++) { + if (shortnames.find(el[j]) != shortnames.end()) { + associatedIDs.emplace(keys[i]); + } } } diff --git a/tests/test_expand.cc b/tests/test_expand.cc index 9480e06..ba7cf1d 100644 --- a/tests/test_expand.cc +++ b/tests/test_expand.cc @@ -377,6 +377,64 @@ CASE( "test_metkit_expand_param" ) { EXPECT_EQUAL(params[4], "164"); EXPECT_EQUAL(params[5], "228"); } + { + const char* text = "retrieve,class=od,expver=1,stream=msmm,date=-1,time=0000,type=em,levtype=sfc,step=24,param=e"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 1); + + EXPECT_EQUAL(params[0], "172182"); + } + { + const char* text = "retrieve,class=od,expver=1,stream=msmm,date=-1,time=0000,type=em,levtype=sfc,step=24,param=e/erate"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 2); + + EXPECT_EQUAL(params[0], "172182"); + EXPECT_EQUAL(params[1], "172182"); + } + { + const char* text = "retrieve,class=od,expver=1,stream=enwh,date=-1,time=0000,type=pf,levtype=sfc,step=24,param=sh10"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 1); + + EXPECT_EQUAL(params[0], "140120"); + } + { + const char* text = "retrieve,class=od,expver=1,stream=enwh,date=-1,time=0000,type=pf,levtype=sfc,step=24,param=p1ww"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 1); + + EXPECT_EQUAL(params[0], "140223"); + } + { + const char* text = "retrieve,class=od,expver=1,stream=waef,date=-1,time=0000,type=cf,levtype=sfc,step=24,param=WSK/MWP"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 2); + + EXPECT_EQUAL(params[0], "140252"); + EXPECT_EQUAL(params[1], "140232"); + } + { + const char* text = "retrieve,class=od,expver=1,stream=eefo,date=-1,time=0000,type=fcmean,levtype=sfc,step=24,param=MSL"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 1); + + EXPECT_EQUAL(params[0], "151"); + } + { + const char* text = "retrieve,class=od,expver=1,stream=eefo,date=-1,time=0000,type=fcmean,levtype=sfc,step=24,param=strda"; + MarsRequest r = MarsRequest::parse(text); + auto params = r.values("param"); + EXPECT_EQUAL(params.size(), 1); + + EXPECT_EQUAL(params[0], "171175"); + } } //----------------------------------------------------------------------------- diff --git a/tests/test_request.cc b/tests/test_request.cc index 9b8a537..b1fdd8a 100644 --- a/tests/test_request.cc +++ b/tests/test_request.cc @@ -34,13 +34,13 @@ namespace test { CASE( "test_request_json" ) { { - const char* text = "retrieve,class=od,expver=0079,stream=enfh,date=-1,time=00/12,type=fcmean,levtype=sfc,step=24,number=1/to/2,param=mucin/mucape/tprate"; + const char* text = "retrieve,class=od,expver=0079,stream=enfh,date=20240729,time=00/12,type=fcmean,levtype=sfc,step=24,number=1/to/2,param=mucin/mucape/tprate"; MarsRequest r = MarsRequest::parse(text); { std::stringstream ss; eckit::JSON plain(ss); r.json(plain); - // std::cout << ss.str() << std::endl; + std::cout << ss.str() << std::endl; EXPECT_EQUAL(ss.str(), "{\"class\":\"od\",\"expver\":\"0079\",\"stream\":\"enfh\",\"date\":\"20240729\",\"time\":[\"0000\",\"1200\"],\"type\":\"fcmean\",\"levtype\":\"sfc\",\"step\":\"24\",\"number\":[\"1\",\"2\"],\"param\":[\"228236\",\"228235\",\"172228\"],\"domain\":\"g\"}"); } { @@ -52,7 +52,7 @@ CASE( "test_request_json" ) { } } { - const char* text = "retrieve,class=od,expver=1,stream=wave,date=-1,time=00,type=an,levtype=sfc,step=24,param=2dfd "; + const char* text = "retrieve,class=od,expver=1,stream=wave,date=20240729,time=00,type=an,levtype=sfc,step=24,param=2dfd "; MarsRequest r = MarsRequest::parse(text); { std::stringstream ss;