Skip to content

Commit

Permalink
beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolabertoldi committed May 19, 2014
1 parent d85bd05 commit 2f3cd5e
Show file tree
Hide file tree
Showing 54 changed files with 2,878 additions and 2,855 deletions.
15 changes: 6 additions & 9 deletions moses/ChartCellLabelSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class ChartCellLabelSet
typedef MapType::iterator iterator;

ChartCellLabelSet(const WordsRange &coverage)
: m_coverage(coverage)
, m_map(FactorCollection::Instance().GetNumNonTerminals(), NULL)
, m_size(0) { }
: m_coverage(coverage)
, m_map(FactorCollection::Instance().GetNumNonTerminals(), NULL)
, m_size(0) { }

~ChartCellLabelSet() {
RemoveAllInColl(m_map);
Expand Down Expand Up @@ -82,8 +82,7 @@ class ChartCellLabelSet
if (ChartCellExists(idx)) {
ChartCellLabel::Stack & s = m_map[idx]->MutableStack();
s.cube = stack;
}
else {
} else {
ChartCellLabel::Stack s;
s.cube = stack;
m_size++;
Expand All @@ -97,8 +96,7 @@ class ChartCellLabelSet
if (m_map.at(idx) != NULL) {
return true;
}
}
catch (const std::out_of_range& oor) {
} catch (const std::out_of_range& oor) {
m_map.resize(FactorCollection::Instance().GetNumNonTerminals(), NULL);
}
return false;
Expand All @@ -116,8 +114,7 @@ class ChartCellLabelSet
size_t idx = w[0]->GetId();
try {
return m_map.at(idx);
}
catch (const std::out_of_range& oor) {
} catch (const std::out_of_range& oor) {
return NULL;
}
}
Expand Down
12 changes: 6 additions & 6 deletions moses/ChartKBestExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ namespace Moses

// Extract the k-best list from the search graph.
void ChartKBestExtractor::Extract(
const std::vector<const ChartHypothesis*> &topLevelHypos, std::size_t k,
KBestVec &kBestList)
const std::vector<const ChartHypothesis*> &topLevelHypos, std::size_t k,
KBestVec &kBestList)
{
kBestList.clear();
if (topLevelHypos.empty()) {
Expand All @@ -45,7 +45,7 @@ void ChartKBestExtractor::Extract(
std::vector<const ChartHypothesis*>::const_iterator p = topLevelHypos.begin();
const ChartHypothesis &bestTopLevelHypo = **p;
boost::scoped_ptr<ChartHypothesis> supremeHypo(
new ChartHypothesis(bestTopLevelHypo, *this));
new ChartHypothesis(bestTopLevelHypo, *this));

// Do the same for each alternative top-level hypothesis, but add the new
// ChartHypothesis objects as arcs from supremeHypo, as if they had been
Expand All @@ -68,8 +68,8 @@ void ChartKBestExtractor::Extract(
// each derivation.
kBestList.reserve(targetVertex->kBestList.size());
for (std::vector<boost::weak_ptr<Derivation> >::const_iterator
q = targetVertex->kBestList.begin();
q != targetVertex->kBestList.end(); ++q) {
q = targetVertex->kBestList.begin();
q != targetVertex->kBestList.end(); ++q) {
const boost::shared_ptr<Derivation> d(*q);
assert(d);
assert(d->subderivations.size() == 1);
Expand Down Expand Up @@ -124,7 +124,7 @@ Phrase ChartKBestExtractor::GetOutputPhrase(const Derivation &d)

// Create an unweighted hyperarc corresponding to the given ChartHypothesis.
ChartKBestExtractor::UnweightedHyperarc ChartKBestExtractor::CreateEdge(
const ChartHypothesis &h)
const ChartHypothesis &h)
{
UnweightedHyperarc edge;
edge.head = FindOrCreateVertex(h);
Expand Down
8 changes: 4 additions & 4 deletions moses/ChartKBestExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class ChartKBestExtractor

struct Vertex {
typedef std::priority_queue<boost::weak_ptr<Derivation>,
std::vector<boost::weak_ptr<Derivation> >,
DerivationOrderer> DerivationQueue;
std::vector<boost::weak_ptr<Derivation> >,
DerivationOrderer> DerivationQueue;

Vertex(const ChartHypothesis &h) : hypothesis(h), visited(false) {}

Expand All @@ -92,7 +92,7 @@ class ChartKBestExtractor

private:
typedef boost::unordered_map<const ChartHypothesis *,
boost::shared_ptr<Vertex> > VertexMap;
boost::shared_ptr<Vertex> > VertexMap;

struct DerivationHasher {
std::size_t operator()(const boost::shared_ptr<Derivation> &d) const {
Expand All @@ -114,7 +114,7 @@ class ChartKBestExtractor
};

typedef boost::unordered_set<boost::shared_ptr<Derivation>, DerivationHasher,
DerivationEqualityPred> DerivationSet;
DerivationEqualityPred> DerivationSet;

UnweightedHyperarc CreateEdge(const ChartHypothesis &);
boost::shared_ptr<Vertex> FindOrCreateVertex(const ChartHypothesis &);
Expand Down
8 changes: 4 additions & 4 deletions moses/ChartManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ void ChartManager::CalcNBest(size_t count, ChartTrellisPathList &ret,bool onlyDi
* \param onlyDistinct whether to check for distinct output sentence or not (default - don't check, just return top n-paths)
*/
void ChartManager::CalcNBest(
std::size_t n,
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > &nBestList,
bool onlyDistinct) const
std::size_t n,
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > &nBestList,
bool onlyDistinct) const
{
nBestList.clear();
if (n == 0 || m_source.GetSize() == 0) {
Expand All @@ -282,7 +282,7 @@ void ChartManager::CalcNBest(
WordsRange range(0, m_source.GetSize()-1);
const ChartCell &lastCell = m_hypoStackColl.Get(range);
boost::scoped_ptr<const std::vector<const ChartHypothesis*> > topLevelHypos(
lastCell.GetAllSortedHypotheses());
lastCell.GetAllSortedHypotheses());
if (!topLevelHypos) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion moses/ChartManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class ChartManager
return m_hypothesisId++;
}

const ChartParser &GetParser() const { return m_parser; }
const ChartParser &GetParser() const {
return m_parser;
}
};

}
Expand Down
2 changes: 1 addition & 1 deletion moses/ChartParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void ChartParser::Create(const WordsRange &wordsRange, ChartParserCallback &to)
size_t maxSpan = decodeGraph.GetMaxChartSpan();
size_t last = m_source.GetSize()-1;
if (maxSpan != 0) {
last = min(last, wordsRange.GetStartPos()+maxSpan);
last = min(last, wordsRange.GetStartPos()+maxSpan);
}
if (maxSpan == 0 || wordsRange.GetNumWordsCovered() <= maxSpan) {
ruleLookupManager.GetChartRuleCollection(wordsRange, last, to);
Expand Down
8 changes: 6 additions & 2 deletions moses/ChartParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class ChartParserUnknown

void Process(const Word &sourceWord, const WordsRange &range, ChartParserCallback &to);

const std::vector<Phrase*> &GetUnknownSources() const { return m_unksrcs; }
const std::vector<Phrase*> &GetUnknownSources() const {
return m_unksrcs;
}

private:
std::vector<Phrase*> m_unksrcs;
Expand All @@ -69,7 +71,9 @@ class ChartParser
size_t GetSize() const;
const InputPath &GetInputPath(size_t startPos, size_t endPos) const;
const InputPath &GetInputPath(WordsRange &range) const;
const std::vector<Phrase*> &GetUnknownSources() const { return m_unknown.GetUnknownSources(); }
const std::vector<Phrase*> &GetUnknownSources() const {
return m_unknown.GetUnknownSources();
}

private:
ChartParserUnknown m_unknown;
Expand Down
10 changes: 5 additions & 5 deletions moses/ChartTranslationOptionList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ void ChartTranslationOptionList::ApplyThreshold()

float ChartTranslationOptionList::GetBestScore(const ChartCellLabel *chartCell) const
{
const HypoList *stack = chartCell->GetStack().cube;
assert(stack);
assert(!stack->empty());
const ChartHypothesis &bestHypo = **(stack->begin());
return bestHypo.GetTotalScore();
const HypoList *stack = chartCell->GetStack().cube;
assert(stack);
assert(!stack->empty());
const ChartHypothesis &bestHypo = **(stack->begin());
return bestHypo.GetTotalScore();
}

void ChartTranslationOptionList::Evaluate(const InputType &input, const InputPath &inputPath)
Expand Down
Loading

0 comments on commit 2f3cd5e

Please sign in to comment.