Skip to content

Commit

Permalink
store nbest rather than arclist
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuhoang committed Aug 23, 2016
1 parent 8c99db1 commit 31627f9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions contrib/moses2/SCFG/KBestExtractor.cpp
Expand Up @@ -20,7 +20,11 @@ namespace Moses2
{
namespace SCFG
{
NBest::NBest(const SCFG::Manager &mgr, const ArcList &varcList, size_t vind)
NBest::NBest(
const SCFG::Manager &mgr,
const NBestColl &nbestColl,
const ArcList &varcList,
size_t vind)
:arcList(&varcList)
,ind(vind)
{
Expand All @@ -39,7 +43,8 @@ NBest::NBest(const SCFG::Manager &mgr, const ArcList &varcList, size_t vind)
for (size_t i = 0; i < prevHypos.size(); ++i) {
const SCFG::Hypothesis *prevHypo = prevHypos[i];
const ArcList &childArc = arcLists.GetArcList(prevHypo);
Child child(&childArc, 0);
const NBests &childNBests = nbestColl.GetNBests(childArc);
Child child(&childNBests, 0);
children.push_back(child);
}
}
Expand Down Expand Up @@ -71,7 +76,7 @@ void NBest::OutputToStream(
const Child &child = children[nonTermInd];
UTIL_THROW_IF2(child.first == NULL, "ArcList == NULL");

const NBests &nbests = nbestColl.GetNBests(*child.first);
const NBests &nbests = *child.first;
const NBest &nbest = nbests[child.second];
nbest.OutputToStream(mgr, strm, nbestColl);
}
Expand All @@ -87,7 +92,7 @@ void NBest::OutputToStream(
/////////////////////////////////////////////////////////////
void NBestColl::Add(const SCFG::Manager &mgr, const ArcList &arcList)
{
NBest best(mgr, arcList, 0);
NBest best(mgr, *this, arcList, 0);
GetOrCreateNBests(arcList).push_back(best);
}

Expand Down
11 changes: 8 additions & 3 deletions contrib/moses2/SCFG/KBestExtractor.h
Expand Up @@ -20,18 +20,22 @@ namespace SCFG
class Manager;
class Hypothesis;
class NBestColl;
class NBests;

class NBest
{
public:
const ArcList *arcList;
size_t ind;

typedef std::pair<const ArcList *, size_t> Child; // key to another NBest
typedef std::pair<const NBests*, size_t> Child; // key to another NBest
typedef std::vector<Child> Children;
Children children;

NBest(const SCFG::Manager &mgr, const ArcList &varcList, size_t vind);
NBest(const SCFG::Manager &mgr,
const NBestColl &nbestColl,
const ArcList &varcList,
size_t vind);

const Scores &GetScores() const
{ return *m_scores; }
Expand All @@ -48,7 +52,8 @@ class NBest
};

/////////////////////////////////////////////////////////////
typedef std::vector<NBest> NBests;
class NBests : public std::vector<NBest>
{};

/////////////////////////////////////////////////////////////
class NBestColl
Expand Down

0 comments on commit 31627f9

Please sign in to comment.