Skip to content

Commit

Permalink
create deviants
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuhoang committed Aug 23, 2016
1 parent 3af84b6 commit 933e4d2
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 13 deletions.
8 changes: 4 additions & 4 deletions contrib/moses2/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
</externalSetting>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down Expand Up @@ -106,13 +106,13 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.1445209421" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down
59 changes: 57 additions & 2 deletions contrib/moses2/SCFG/KBestExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,70 @@ NBest::NBest(
}
}

NBest::NBest(const SCFG::Manager &mgr,
const NBest &orig,
size_t childInd)
:arcList(orig.arcList)
,ind(orig.ind)
,children(orig.children)
{
Child &child = children[childInd];
size_t &ind = child.second;
++ind;
UTIL_THROW_IF2(ind >= child.first->size(), "out of bound:" << ind << ">=" << child.first->size());

// scores
MemPool &pool = mgr.GetPool();
m_scores = new (pool.Allocate<Scores>())
Scores(mgr.system,
pool,
mgr.system.featureFunctions.GetNumScores(),
orig.GetScores());

const Scores &origScores = orig.GetChild(childInd).GetScores();
const Scores &newScores = GetChild(childInd).GetScores();

m_scores->MinusEquals(mgr.system, origScores);
m_scores->PlusEquals(mgr.system, newScores);

}

const SCFG::Hypothesis &NBest::GetHypo() const
{
const HypothesisBase *hypoBase = (*arcList)[ind];
const SCFG::Hypothesis &hypo = *static_cast<const SCFG::Hypothesis*>(hypoBase);
return hypo;
}

void NBest::CreateDeviants(std::priority_queue<NBest*> &contenders)
const NBest &NBest::GetChild(size_t ind) const
{
const Child &child = children[ind];
const NBests &nbests = *child.first;
const NBest &origNBest = *nbests[child.second];
return origNBest;
}


void NBest::CreateDeviants(
const SCFG::Manager &mgr,
const NBestColl &nbestColl,
std::priority_queue<NBest*> &contenders)
{
if (ind + 1 < arcList->size()) {
NBest *next = new NBest(mgr, nbestColl, *arcList, ind + 1);
contenders.push(next);
}

for (size_t childInd = 0; childInd < children.size(); ++childInd) {
const Child &child = children[childInd];
if (child.second + 1 < child.first->size()) {
//cerr << "HH1 " << childInd << endl;
NBest *next = new NBest(mgr, *this, childInd);
//cerr << "HH2 " << childInd << endl;
contenders.push(next);
//cerr << "HH3 " << childInd << endl;
}
}
}

void NBest::OutputToStream(
Expand Down Expand Up @@ -133,7 +187,7 @@ void NBestColl::Add(const SCFG::Manager &mgr, const ArcList &arcList)
contenders.pop();
nbests.push_back(best);

best->CreateDeviants(contenders);
best->CreateDeviants(mgr, *this, contenders);

}
}
Expand Down Expand Up @@ -197,6 +251,7 @@ KBestExtractor::~KBestExtractor()

void KBestExtractor::OutputToStream(std::stringstream &strm)
{
//cerr << "1" << flush;
const Stack &lastStack = m_mgr.GetStacks().GetLastStack();
UTIL_THROW_IF2(lastStack.GetColl().size() != 1, "Only suppose to be 1 hypo coll in last stack");
UTIL_THROW_IF2(lastStack.GetColl().begin()->second == NULL, "NULL hypo collection");
Expand Down
11 changes: 10 additions & 1 deletion contrib/moses2/SCFG/KBestExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@ class NBest
const ArcList &varcList,
size_t vind);

void CreateDeviants(std::priority_queue<NBest*> &contenders);
NBest(const SCFG::Manager &mgr,
const NBest &orig,
size_t childInd);

void CreateDeviants(
const SCFG::Manager &mgr,
const NBestColl &nbestColl,
std::priority_queue<NBest*> &contenders);

const Scores &GetScores() const
{ return *m_scores; }

const NBest &GetChild(size_t ind) const;

void OutputToStream(
const SCFG::Manager &mgr,
std::stringstream &strm,
Expand Down
8 changes: 4 additions & 4 deletions contrib/other-builds/OnDiskPt/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
</externalSetting>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down Expand Up @@ -72,13 +72,13 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.macosx.exe.release.701931933" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.MachO64" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down
4 changes: 2 additions & 2 deletions contrib/other-builds/moses/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
</externalSetting>
</externalSettings>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down Expand Up @@ -86,12 +86,12 @@
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.exe.release.1911984684" moduleId="org.eclipse.cdt.core.settings" name="Release">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
Expand Down

0 comments on commit 933e4d2

Please sign in to comment.