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

Added features ldep and rdep

parent c85940a5
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,50 @@ FeatureModel::FeatureValue access(Config & config, int bufferIndex, const std::s ...@@ -32,6 +32,50 @@ FeatureModel::FeatureValue access(Config & config, int bufferIndex, const std::s
return {dict, featName, tape[bufferIndex-config.getHead()], policy}; return {dict, featName, tape[bufferIndex-config.getHead()], policy};
} }
int getLeftMostDep(Config & config, int index)
{
auto & govs = config.getTape("GOV");
auto & eos = config.getTape(ProgramParameters::sequenceDelimiterTape);
int b0 = config.getHead();
if(index < 0 || index >= govs.hypSize())
return -1;
int candidate = -1;
unsigned int maxDist = 50;
for (int i = std::max<int>(index-1, 0); index - i <= (int)maxDist && i >= 0 && eos[i-b0] != ProgramParameters::sequenceDelimiter; i--)
{
int dist = index - i;
if(govs[i-b0] == std::to_string(dist))
candidate = i;
}
return candidate;
}
int getRightMostDep(Config & config, int index)
{
auto & govs = config.getTape("GOV");
auto & eos = config.getTape(ProgramParameters::sequenceDelimiterTape);
int b0 = config.getHead();
if(index < 0 || index >= govs.hypSize())
return -1;
int candidate = -1;
unsigned int maxDist = 50;
for (int i = index+1; i - index <= (int)maxDist && i < eos.hypSize() && eos[i-1-b0] != ProgramParameters::sequenceDelimiter; i++)
{
int dist = index - i;
if(govs[i-b0] == std::to_string(dist))
candidate = i;
}
return candidate;
}
std::function<FeatureModel::FeatureValue(Config &)> FeatureBank::str2func(const std::string & s) std::function<FeatureModel::FeatureValue(Config &)> FeatureBank::str2func(const std::string & s)
{ {
auto splited = split(s, '#'); auto splited = split(s, '#');
...@@ -105,6 +149,18 @@ std::function<FeatureModel::FeatureValue(Config &)> FeatureBank::str2func(const ...@@ -105,6 +149,18 @@ std::function<FeatureModel::FeatureValue(Config &)> FeatureBank::str2func(const
std::vector<std::function<int(Config&, int)> > contextFuncs; std::vector<std::function<int(Config&, int)> > contextFuncs;
char object = splited[0][0]; char object = splited[0][0];
contextFuncs.emplace_back([relativeIndex, object](Config & c, int){return getBufferIndex(c, object, relativeIndex);}); contextFuncs.emplace_back([relativeIndex, object](Config & c, int){return getBufferIndex(c, object, relativeIndex);});
for (unsigned int i = 2; i < splited.size(); i++)
{
if (splited[i] == "ldep")
contextFuncs.emplace_back([](Config & c, int currentIndex){return getLeftMostDep(c, currentIndex);});
else if (splited[i] == "rdep")
contextFuncs.emplace_back([](Config & c, int currentIndex){return getRightMostDep(c, currentIndex);});
else
{
fprintf(stderr, "ERROR (%s) : invalid feature format \'%s\', unknown context \'%s\'. Aborting.\n", ERRINFO, s.c_str(), splited[i].c_str());
exit(1);
}
}
auto getContext = [contextFuncs](Config & c) auto getContext = [contextFuncs](Config & c)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment