mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 19:27:11 +03:00
change dynamic to static cast
This commit is contained in:
parent
f296078607
commit
b7d947ebf6
@ -619,7 +619,7 @@ void ChartManager::OutputDetailedTranslationReport(
|
|||||||
const StaticData &staticData = StaticData::Instance();
|
const StaticData &staticData = StaticData::Instance();
|
||||||
|
|
||||||
if (staticData.IsDetailedAllTranslationReportingEnabled()) {
|
if (staticData.IsDetailedAllTranslationReportingEnabled()) {
|
||||||
const Sentence &sentence = dynamic_cast<const Sentence &>(m_source);
|
const Sentence &sentence = static_cast<const Sentence &>(m_source);
|
||||||
size_t nBestSize = staticData.options().nbest.nbest_size;
|
size_t nBestSize = staticData.options().nbest.nbest_size;
|
||||||
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
|
std::vector<boost::shared_ptr<ChartKBestExtractor::Derivation> > nBestList;
|
||||||
CalcNBest(nBestSize, nBestList, staticData.options().nbest.nbest_size);
|
CalcNBest(nBestSize, nBestList, staticData.options().nbest.nbest_size);
|
||||||
@ -720,7 +720,7 @@ void ChartManager::OutputDetailedTreeFragmentsTranslationReport(OutputCollector
|
|||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
ApplicationContext applicationContext;
|
ApplicationContext applicationContext;
|
||||||
|
|
||||||
const Sentence &sentence = dynamic_cast<const Sentence &>(m_source);
|
const Sentence &sentence = static_cast<const Sentence &>(m_source);
|
||||||
const size_t translationId = m_source.GetTranslationId();
|
const size_t translationId = m_source.GetTranslationId();
|
||||||
|
|
||||||
OutputTreeFragmentsTranslationOptions(out, applicationContext, hypo, sentence, translationId);
|
OutputTreeFragmentsTranslationOptions(out, applicationContext, hypo, sentence, translationId);
|
||||||
@ -731,7 +731,7 @@ void ChartManager::OutputDetailedTreeFragmentsTranslationReport(OutputCollector
|
|||||||
const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions();
|
const vector<const StatefulFeatureFunction*>& sff = StatefulFeatureFunction::GetStatefulFeatureFunctions();
|
||||||
for( size_t i=0; i<sff.size(); i++ ) {
|
for( size_t i=0; i<sff.size(); i++ ) {
|
||||||
if (sff[i] == treeStructure) {
|
if (sff[i] == treeStructure) {
|
||||||
const TreeState* tree = dynamic_cast<const TreeState*>(hypo->GetFFState(i));
|
const TreeState* tree = static_cast<const TreeState*>(hypo->GetFFState(i));
|
||||||
out << "Full Tree " << translationId << ": " << tree->GetTree()->GetString() << "\n";
|
out << "Full Tree " << translationId << ": " << tree->GetTree()->GetString() << "\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -503,7 +503,7 @@ FFState* BleuScoreFeature::EvaluateWhenApplied(const Hypothesis& cur_hypo,
|
|||||||
if (!m_enabled) return new BleuScoreState();
|
if (!m_enabled) return new BleuScoreState();
|
||||||
|
|
||||||
NGrams::const_iterator reference_ngrams_iter;
|
NGrams::const_iterator reference_ngrams_iter;
|
||||||
const BleuScoreState& ps = dynamic_cast<const BleuScoreState&>(*prev_state);
|
const BleuScoreState& ps = static_cast<const BleuScoreState&>(*prev_state);
|
||||||
BleuScoreState* new_state = new BleuScoreState(ps);
|
BleuScoreState* new_state = new BleuScoreState(ps);
|
||||||
|
|
||||||
float old_bleu, new_bleu;
|
float old_bleu, new_bleu;
|
||||||
@ -579,13 +579,13 @@ FFState* BleuScoreFeature::EvaluateWhenApplied(const ChartHypothesis& cur_hypo,
|
|||||||
new_state = new BleuScoreState();
|
new_state = new BleuScoreState();
|
||||||
else {
|
else {
|
||||||
const FFState* prev_state_zero = cur_hypo.GetPrevHypo(0)->GetFFState(featureID);
|
const FFState* prev_state_zero = cur_hypo.GetPrevHypo(0)->GetFFState(featureID);
|
||||||
const BleuScoreState& ps_zero = dynamic_cast<const BleuScoreState&>(*prev_state_zero);
|
const BleuScoreState& ps_zero = static_cast<const BleuScoreState&>(*prev_state_zero);
|
||||||
new_state = new BleuScoreState(ps_zero);
|
new_state = new BleuScoreState(ps_zero);
|
||||||
num_words_first_prev = ps_zero.m_target_length;
|
num_words_first_prev = ps_zero.m_target_length;
|
||||||
|
|
||||||
for (size_t i = 0; i < cur_hypo.GetPrevHypos().size(); ++i) {
|
for (size_t i = 0; i < cur_hypo.GetPrevHypos().size(); ++i) {
|
||||||
const FFState* prev_state = cur_hypo.GetPrevHypo(i)->GetFFState(featureID);
|
const FFState* prev_state = cur_hypo.GetPrevHypo(i)->GetFFState(featureID);
|
||||||
const BleuScoreState* ps = dynamic_cast<const BleuScoreState*>(prev_state);
|
const BleuScoreState* ps = static_cast<const BleuScoreState*>(prev_state);
|
||||||
BleuScoreState* ps_nonConst = const_cast<BleuScoreState*>(ps);
|
BleuScoreState* ps_nonConst = const_cast<BleuScoreState*>(ps);
|
||||||
// cerr << "prev phrase: " << cur_hypo.GetPrevHypo(i)->GetOutputPhrase()
|
// cerr << "prev phrase: " << cur_hypo.GetPrevHypo(i)->GetOutputPhrase()
|
||||||
// << " ( " << cur_hypo.GetPrevHypo(i)->GetTargetLHS() << ")" << endl;
|
// << " ( " << cur_hypo.GetPrevHypo(i)->GetTargetLHS() << ")" << endl;
|
||||||
|
@ -19,7 +19,7 @@ size_t PhraseBoundaryState::hash() const
|
|||||||
}
|
}
|
||||||
bool PhraseBoundaryState::operator==(const FFState& other) const
|
bool PhraseBoundaryState::operator==(const FFState& other) const
|
||||||
{
|
{
|
||||||
const PhraseBoundaryState& rhs = dynamic_cast<const PhraseBoundaryState&>(other);
|
const PhraseBoundaryState& rhs = static_cast<const PhraseBoundaryState&>(other);
|
||||||
bool ret = *m_targetWord == *rhs.m_targetWord && *m_sourceWord == *rhs.m_sourceWord;
|
bool ret = *m_targetWord == *rhs.m_targetWord && *m_sourceWord == *rhs.m_sourceWord;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ FFState* PhraseBoundaryFeature::EvaluateWhenApplied
|
|||||||
(const Hypothesis& cur_hypo, const FFState* prev_state,
|
(const Hypothesis& cur_hypo, const FFState* prev_state,
|
||||||
ScoreComponentCollection* scores) const
|
ScoreComponentCollection* scores) const
|
||||||
{
|
{
|
||||||
const PhraseBoundaryState* pbState = dynamic_cast<const PhraseBoundaryState*>(prev_state);
|
const PhraseBoundaryState* pbState = static_cast<const PhraseBoundaryState*>(prev_state);
|
||||||
const Phrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
const Phrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
||||||
if (targetPhrase.GetSize() == 0) {
|
if (targetPhrase.GetSize() == 0) {
|
||||||
return new PhraseBoundaryState(*pbState);
|
return new PhraseBoundaryState(*pbState);
|
||||||
|
@ -178,7 +178,7 @@ void SparseHieroReorderingFeature::EvaluateWhenApplied(
|
|||||||
|
|
||||||
//Iterate through block pairs
|
//Iterate through block pairs
|
||||||
const Sentence& sentence =
|
const Sentence& sentence =
|
||||||
dynamic_cast<const Sentence&>(cur_hypo.GetManager().GetSource());
|
static_cast<const Sentence&>(cur_hypo.GetManager().GetSource());
|
||||||
//const TargetPhrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
//const TargetPhrase& targetPhrase = cur_hypo.GetCurrTargetPhrase();
|
||||||
for (size_t i = 0; i < sourceBlocks.size()-1; ++i) {
|
for (size_t i = 0; i < sourceBlocks.size()-1; ++i) {
|
||||||
Block& leftSourceBlock = sourceBlocks[i];
|
Block& leftSourceBlock = sourceBlocks[i];
|
||||||
|
@ -19,7 +19,7 @@ size_t TargetBigramState::hash() const
|
|||||||
|
|
||||||
bool TargetBigramState::operator==(const FFState& other) const
|
bool TargetBigramState::operator==(const FFState& other) const
|
||||||
{
|
{
|
||||||
const TargetBigramState& rhs = dynamic_cast<const TargetBigramState&>(other);
|
const TargetBigramState& rhs = static_cast<const TargetBigramState&>(other);
|
||||||
return m_word == rhs.m_word;
|
return m_word == rhs.m_word;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ FFState* TargetBigramFeature::EvaluateWhenApplied(const Hypothesis& cur_hypo,
|
|||||||
const FFState* prev_state,
|
const FFState* prev_state,
|
||||||
ScoreComponentCollection* accumulator) const
|
ScoreComponentCollection* accumulator) const
|
||||||
{
|
{
|
||||||
const TargetBigramState* tbState = dynamic_cast<const TargetBigramState*>(prev_state);
|
const TargetBigramState* tbState = static_cast<const TargetBigramState*>(prev_state);
|
||||||
assert(tbState);
|
assert(tbState);
|
||||||
|
|
||||||
// current hypothesis target phrase
|
// current hypothesis target phrase
|
||||||
|
@ -20,7 +20,7 @@ size_t TargetNgramState::hash() const
|
|||||||
|
|
||||||
bool TargetNgramState::operator==(const FFState& other) const
|
bool TargetNgramState::operator==(const FFState& other) const
|
||||||
{
|
{
|
||||||
const TargetNgramState& rhs = dynamic_cast<const TargetNgramState&>(other);
|
const TargetNgramState& rhs = static_cast<const TargetNgramState&>(other);
|
||||||
bool result;
|
bool result;
|
||||||
if (m_words.size() == rhs.m_words.size()) {
|
if (m_words.size() == rhs.m_words.size()) {
|
||||||
for (size_t i = 0; i < m_words.size(); ++i) {
|
for (size_t i = 0; i < m_words.size(); ++i) {
|
||||||
|
@ -34,7 +34,7 @@ FFState* TreeStructureFeature::EvaluateWhenApplied(const ChartHypothesis& cur_hy
|
|||||||
if (word.IsNonTerminal()) {
|
if (word.IsNonTerminal()) {
|
||||||
size_t nonTermInd = cur_hypo.GetCurrTargetPhrase().GetAlignNonTerm().GetNonTermIndexMap()[pos];
|
size_t nonTermInd = cur_hypo.GetCurrTargetPhrase().GetAlignNonTerm().GetNonTermIndexMap()[pos];
|
||||||
const ChartHypothesis *prevHypo = cur_hypo.GetPrevHypo(nonTermInd);
|
const ChartHypothesis *prevHypo = cur_hypo.GetPrevHypo(nonTermInd);
|
||||||
const TreeState* prev = dynamic_cast<const TreeState*>(prevHypo->GetFFState(featureID));
|
const TreeState* prev = static_cast<const TreeState*>(prevHypo->GetFFState(featureID));
|
||||||
const TreePointer prev_tree = prev->GetTree();
|
const TreePointer prev_tree = prev->GetTree();
|
||||||
previous_trees.push_back(prev_tree);
|
previous_trees.push_back(prev_tree);
|
||||||
}
|
}
|
||||||
|
@ -450,7 +450,7 @@ void Manager::OutputDetailedTreeFragmentsTranslationReport(OutputCollector *coll
|
|||||||
}
|
}
|
||||||
|
|
||||||
const search::Applied *applied = &Completed()[0];
|
const search::Applied *applied = &Completed()[0];
|
||||||
const Sentence &sentence = dynamic_cast<const Sentence &>(m_source);
|
const Sentence &sentence = static_cast<const Sentence &>(m_source);
|
||||||
const size_t translationId = m_source.GetTranslationId();
|
const size_t translationId = m_source.GetTranslationId();
|
||||||
|
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
|
@ -167,7 +167,7 @@ public:
|
|||||||
}
|
}
|
||||||
virtual bool operator==(const FFState& o) const {
|
virtual bool operator==(const FFState& o) const {
|
||||||
const LanguageModelChartState &other =
|
const LanguageModelChartState &other =
|
||||||
dynamic_cast<const LanguageModelChartState &>( o );
|
static_cast<const LanguageModelChartState &>( o );
|
||||||
|
|
||||||
// prefix
|
// prefix
|
||||||
if (m_hypo.GetCurrSourceRange().GetStartPos() > 0) { // not for "<s> ..."
|
if (m_hypo.GetCurrSourceRange().GetStartPos() > 0) { // not for "<s> ..."
|
||||||
|
@ -521,7 +521,7 @@ void Manager::OutputWordGraph(std::ostream &outputWordGraphStream, const Hypothe
|
|||||||
const std::vector<const StatefulFeatureFunction*> &statefulFFs = StatefulFeatureFunction::GetStatefulFeatureFunctions();
|
const std::vector<const StatefulFeatureFunction*> &statefulFFs = StatefulFeatureFunction::GetStatefulFeatureFunctions();
|
||||||
for (size_t i = 0; i < statefulFFs.size(); ++i) {
|
for (size_t i = 0; i < statefulFFs.size(); ++i) {
|
||||||
const StatefulFeatureFunction *ff = statefulFFs[i];
|
const StatefulFeatureFunction *ff = statefulFFs[i];
|
||||||
const LanguageModel *lm = dynamic_cast<const LanguageModel*>(ff);
|
const LanguageModel *lm = static_cast<const LanguageModel*>(ff);
|
||||||
|
|
||||||
vector<float> scores = hypo->GetScoreBreakdown().GetScoresForProducer(lm);
|
vector<float> scores = hypo->GetScoreBreakdown().GetScoresForProducer(lm);
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ InputPathList &TranslationOptionCollectionConfusionNet::GetInputPathList(size_t
|
|||||||
*/
|
*/
|
||||||
void TranslationOptionCollectionConfusionNet::ProcessUnknownWord(size_t sourcePos)
|
void TranslationOptionCollectionConfusionNet::ProcessUnknownWord(size_t sourcePos)
|
||||||
{
|
{
|
||||||
ConfusionNet const& source=dynamic_cast<ConfusionNet const&>(m_source);
|
ConfusionNet const& source=static_cast<ConfusionNet const&>(m_source);
|
||||||
|
|
||||||
ConfusionNet::Column const& coll=source.GetColumn(sourcePos);
|
ConfusionNet::Column const& coll=source.GetColumn(sourcePos);
|
||||||
const InputPathList &inputPathList = GetInputPathList(sourcePos, sourcePos);
|
const InputPathList &inputPathList = GetInputPathList(sourcePos, sourcePos);
|
||||||
|
@ -75,7 +75,7 @@ void TranslationOptionCollectionText::ProcessUnknownWord(size_t sourcePos)
|
|||||||
*/
|
*/
|
||||||
bool TranslationOptionCollectionText::HasXmlOptionsOverlappingRange(size_t startPosition, size_t endPosition) const
|
bool TranslationOptionCollectionText::HasXmlOptionsOverlappingRange(size_t startPosition, size_t endPosition) const
|
||||||
{
|
{
|
||||||
Sentence const& source=dynamic_cast<Sentence const&>(m_source);
|
Sentence const& source=static_cast<Sentence const&>(m_source);
|
||||||
return source.XmlOverlap(startPosition,endPosition);
|
return source.XmlOverlap(startPosition,endPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ bool TranslationOptionCollectionText::HasXmlOptionsOverlappingRange(size_t start
|
|||||||
bool TranslationOptionCollectionText::ViolatesXmlOptionsConstraint(size_t startPosition, size_t endPosition, TranslationOption *transOpt) const
|
bool TranslationOptionCollectionText::ViolatesXmlOptionsConstraint(size_t startPosition, size_t endPosition, TranslationOption *transOpt) const
|
||||||
{
|
{
|
||||||
// skip if there is no overlap
|
// skip if there is no overlap
|
||||||
Sentence const& source=dynamic_cast<Sentence const&>(m_source);
|
Sentence const& source=static_cast<Sentence const&>(m_source);
|
||||||
if (!source.XmlOverlap(startPosition,endPosition)) {
|
if (!source.XmlOverlap(startPosition,endPosition)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -135,7 +135,7 @@ bool TranslationOptionCollectionText::ViolatesXmlOptionsConstraint(size_t startP
|
|||||||
*/
|
*/
|
||||||
void TranslationOptionCollectionText::CreateXmlOptionsForRange(size_t startPos, size_t endPos)
|
void TranslationOptionCollectionText::CreateXmlOptionsForRange(size_t startPos, size_t endPos)
|
||||||
{
|
{
|
||||||
Sentence const& source=dynamic_cast<Sentence const&>(m_source);
|
Sentence const& source=static_cast<Sentence const&>(m_source);
|
||||||
InputPath &inputPath = GetInputPath(startPos,endPos);
|
InputPath &inputPath = GetInputPath(startPos,endPos);
|
||||||
|
|
||||||
vector <TranslationOption*> xmlOptions;
|
vector <TranslationOption*> xmlOptions;
|
||||||
|
Loading…
Reference in New Issue
Block a user