Skip to content
Snippets Groups Projects
Commit c94fc04f authored by Franck Dary's avatar Franck Dary
Browse files

Added special dict value for when a feature target the child ofa node without one

parent f3eac5e2
Branches
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ class Dict ...@@ -17,6 +17,7 @@ class Dict
static constexpr char const * unknownValueStr = "__unknownValue__"; static constexpr char const * unknownValueStr = "__unknownValue__";
static constexpr char const * nullValueStr = "__nullValue__"; static constexpr char const * nullValueStr = "__nullValue__";
static constexpr char const * noChildValueStr = "__noChildValue__";
static constexpr char const * emptyValueStr = "__emptyValue__"; static constexpr char const * emptyValueStr = "__emptyValue__";
static constexpr char const * separatorValueStr = "__separatorValue__"; static constexpr char const * separatorValueStr = "__separatorValue__";
static constexpr char const * numberValueStr = "__numberValue__"; static constexpr char const * numberValueStr = "__numberValue__";
......
...@@ -6,6 +6,7 @@ Dict::Dict(State state) ...@@ -6,6 +6,7 @@ Dict::Dict(State state)
setState(state); setState(state);
insert(unknownValueStr); insert(unknownValueStr);
insert(nullValueStr); insert(nullValueStr);
insert(noChildValueStr);
insert(emptyValueStr); insert(emptyValueStr);
insert(numberValueStr); insert(numberValueStr);
insert(urlValueStr); insert(urlValueStr);
...@@ -300,6 +301,7 @@ bool Dict::isSpecialValue(const std::string & value) ...@@ -300,6 +301,7 @@ bool Dict::isSpecialValue(const std::string & value)
{ {
return value == unknownValueStr return value == unknownValueStr
|| value == nullValueStr || value == nullValueStr
|| value == noChildValueStr
|| value == emptyValueStr || value == emptyValueStr
|| value == separatorValueStr || value == separatorValueStr
|| value == numberValueStr || value == numberValueStr
......
...@@ -98,19 +98,19 @@ void ContextModuleImpl::addToContext(std::vector<std::vector<long>> & context, c ...@@ -98,19 +98,19 @@ void ContextModuleImpl::addToContext(std::vector<std::vector<long>> & context, c
{ {
int childIndex = *std::get<2>(target); int childIndex = *std::get<2>(target);
auto childs = util::split(config.getAsFeature(Config::childsColName, baseIndex).get(), '|'); auto childs = util::split(config.getAsFeature(Config::childsColName, baseIndex).get(), '|');
int candidate = -1; int candidate = -2;
if (childIndex >= 0 and childIndex < (int)childs.size()) if (childIndex >= 0 and childIndex < (int)childs.size())
{ {
candidate = std::stoi(childs[childIndex]); candidate = std::stoi(childs[childIndex]);
if (candidate > baseIndex) if (candidate > baseIndex)
candidate = -1; candidate = -2;
} }
else if (childIndex < 0 and ((int)childs.size())+childIndex >= 0) else if (childIndex < 0 and ((int)childs.size())+childIndex >= 0)
{ {
candidate = std::stoi(childs[childs.size()+childIndex]); candidate = std::stoi(childs[childs.size()+childIndex]);
if (candidate < baseIndex) if (candidate < baseIndex)
candidate = -1; candidate = -2;
} }
contextIndexes.emplace_back(candidate); contextIndexes.emplace_back(candidate);
...@@ -128,6 +128,11 @@ void ContextModuleImpl::addToContext(std::vector<std::vector<long>> & context, c ...@@ -128,6 +128,11 @@ void ContextModuleImpl::addToContext(std::vector<std::vector<long>> & context, c
for (auto & contextElement : context) for (auto & contextElement : context)
contextElement.push_back(dict.getIndexOrInsert(Dict::nullValueStr, col)); contextElement.push_back(dict.getIndexOrInsert(Dict::nullValueStr, col));
} }
else if (index == -2)
{
for (auto & contextElement : context)
contextElement.push_back(dict.getIndexOrInsert(Dict::noChildValueStr, col));
}
else else
{ {
int dictIndex; int dictIndex;
......
...@@ -94,7 +94,7 @@ void ContextualModuleImpl::addToContext(std::vector<std::vector<long>> & context ...@@ -94,7 +94,7 @@ void ContextualModuleImpl::addToContext(std::vector<std::vector<long>> & context
std::vector<long> targetIndexes; std::vector<long> targetIndexes;
std::map<long,long> configIndex2ContextIndex; std::map<long,long> configIndex2ContextIndex;
contextIndexes.emplace_back(-2); contextIndexes.emplace_back(-1);
for (long i = window.first; i <= window.second; i++) for (long i = window.first; i <= window.second; i++)
{ {
...@@ -117,7 +117,7 @@ void ContextualModuleImpl::addToContext(std::vector<std::vector<long>> & context ...@@ -117,7 +117,7 @@ void ContextualModuleImpl::addToContext(std::vector<std::vector<long>> & context
{ {
int childIndex = *std::get<2>(target); int childIndex = *std::get<2>(target);
auto childs = util::split(config.getAsFeature(Config::childsColName, baseIndex).get(), '|'); auto childs = util::split(config.getAsFeature(Config::childsColName, baseIndex).get(), '|');
int candidate = -1; int candidate = -2;
if (childIndex >= 0 and childIndex < (int)childs.size()) if (childIndex >= 0 and childIndex < (int)childs.size())
candidate = std::stoi(childs[childIndex]); candidate = std::stoi(childs[childIndex]);
...@@ -141,9 +141,8 @@ void ContextualModuleImpl::addToContext(std::vector<std::vector<long>> & context ...@@ -141,9 +141,8 @@ void ContextualModuleImpl::addToContext(std::vector<std::vector<long>> & context
} }
else if (index == -2) else if (index == -2)
{ {
//TODO maybe change this to a unique value like Dict::noneValueStr
for (auto & contextElement : context) for (auto & contextElement : context)
contextElement.push_back(dict.getIndexOrInsert(Dict::nullValueStr, col)); contextElement.push_back(dict.getIndexOrInsert(Dict::noChildValueStr, col));
} }
else else
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment