From 5431e91c26438b9b54a9b4f722c046c7930b7417 Mon Sep 17 00:00:00 2001 From: Lane Schwartz Date: Wed, 13 Jan 2016 12:53:53 -0600 Subject: [PATCH] Revert "eclipse" This reverts commit e0fb456dbb3296bb1523d7a48b5f627322e33a4b. The reverted commit broken the moses build. --- contrib/other-builds/moses/.project | 20 --- moses/PP/TargetPreferencesPhraseProperty.cpp | 123 +++++++++++++++++++ moses/PP/TargetPreferencesPhraseProperty.h | 71 +++++++++++ 3 files changed, 194 insertions(+), 20 deletions(-) create mode 100644 moses/PP/TargetPreferencesPhraseProperty.cpp create mode 100644 moses/PP/TargetPreferencesPhraseProperty.h diff --git a/contrib/other-builds/moses/.project b/contrib/other-builds/moses/.project index 32bfa1927..e8651529d 100644 --- a/contrib/other-builds/moses/.project +++ b/contrib/other-builds/moses/.project @@ -1635,16 +1635,6 @@ 1 PARENT-3-PROJECT_LOC/moses/FF/TargetNgramFeature.h - - FF/TargetPreferencesFeature.cpp - 1 - PARENT-3-PROJECT_LOC/moses/FF/TargetPreferencesFeature.cpp - - - FF/TargetPreferencesFeature.h - 1 - PARENT-3-PROJECT_LOC/moses/FF/TargetPreferencesFeature.h - FF/TargetWordInsertionFeature.cpp 1 @@ -2005,16 +1995,6 @@ 1 PARENT-3-PROJECT_LOC/moses/PP/SpanLengthPhraseProperty.h - - PP/TargetPreferencesPhraseProperty.cpp - 1 - PARENT-3-PROJECT_LOC/moses/PP/TargetPreferencesPhraseProperty.cpp - - - PP/TargetPreferencesPhraseProperty.h - 1 - PARENT-3-PROJECT_LOC/moses/PP/TargetPreferencesPhraseProperty.h - PP/TreeStructurePhraseProperty.h 1 diff --git a/moses/PP/TargetPreferencesPhraseProperty.cpp b/moses/PP/TargetPreferencesPhraseProperty.cpp new file mode 100644 index 000000000..9358ee4bf --- /dev/null +++ b/moses/PP/TargetPreferencesPhraseProperty.cpp @@ -0,0 +1,123 @@ +#include "moses/PP/TargetPreferencesPhraseProperty.h" +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Moses +{ + +void TargetPreferencesPhraseProperty::ProcessValue(const std::string &value) +{ + std::istringstream tokenizer(value); + + if (! (tokenizer >> m_nNTs)) { // first token: number of non-terminals (incl. left-hand side) + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read number of non-terminals. Flawed property?"); + } + assert( m_nNTs > 0 ); + + if (! (tokenizer >> m_totalCount)) { // second token: overall rule count + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read overall rule count. Flawed property?"); + } + assert( m_totalCount > 0.0 ); + + + // read labelled rule items + + std::priority_queue ruleLabelledCountsPQ; + + while (tokenizer.peek() != EOF) { + try { + + TargetPreferencesPhrasePropertyItem item; + size_t numberOfLHSsGivenRHS = std::numeric_limits::max(); + + if (m_nNTs == 1) { + + item.m_labelsRHSCount = m_totalCount; + + } else { // rule has right-hand side non-terminals, i.e. it's a hierarchical rule + + for (size_t i=0; i> labelRHS) ) { // RHS non-terminal label + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read right-hand side label index. Flawed property?"); + } + item.m_labelsRHS.push_back(labelRHS); + } + + if (! (tokenizer >> item.m_labelsRHSCount)) { + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read right-hand side count. Flawed property?"); + } + + if (! (tokenizer >> numberOfLHSsGivenRHS)) { + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read number of left-hand sides. Flawed property?"); + } + } + + for (size_t i=0; i> labelLHS)) { // LHS non-terminal label + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read left-hand side label index. Flawed property?"); + } + float ruleLabelledCount; + if (! (tokenizer >> ruleLabelledCount)) { + UTIL_THROW2("TargetPreferencesPhraseProperty: Not able to read count. Flawed property?"); + } + item.m_labelsLHSList.push_back( std::make_pair(labelLHS,ruleLabelledCount) ); + ruleLabelledCountsPQ.push(ruleLabelledCount); + } + + m_labelItems.push_back(item); + + } catch (const std::exception &e) { + UTIL_THROW2("TargetPreferencesPhraseProperty: Read error. Flawed property?"); + } + } + + // keep only top N label vectors + const size_t N=50; + + if (ruleLabelledCountsPQ.size() > N) { + + float topNRuleLabelledCount = std::numeric_limits::max(); + for (size_t i=0; !ruleLabelledCountsPQ.empty() && i::iterator itemIter=m_labelItems.begin(); + while (itemIter!=m_labelItems.end()) { + if (itemIter->m_labelsRHSCount < topNRuleLabelledCount) { + itemIter = m_labelItems.erase(itemIter); + } else { + std::list< std::pair >::iterator itemLHSIter=(itemIter->m_labelsLHSList).begin(); + while (itemLHSIter!=(itemIter->m_labelsLHSList).end()) { + if (itemLHSIter->second < topNRuleLabelledCount) { + itemLHSIter = (itemIter->m_labelsLHSList).erase(itemLHSIter); + } else { + if (nKept >= N) { + itemLHSIter = (itemIter->m_labelsLHSList).erase(itemLHSIter,(itemIter->m_labelsLHSList).end()); + } else { + ++nKept; + ++itemLHSIter; + } + } + } + if ((itemIter->m_labelsLHSList).empty()) { + itemIter = m_labelItems.erase(itemIter); + } else { + ++itemIter; + } + } + } + } +}; + +} // namespace Moses + diff --git a/moses/PP/TargetPreferencesPhraseProperty.h b/moses/PP/TargetPreferencesPhraseProperty.h new file mode 100644 index 000000000..84ef9b3c5 --- /dev/null +++ b/moses/PP/TargetPreferencesPhraseProperty.h @@ -0,0 +1,71 @@ + +#pragma once + +#include "moses/PP/PhraseProperty.h" +#include "util/exception.hh" +#include +#include + +namespace Moses +{ + +class TargetPreferencesPhrasePropertyItem +{ + friend class TargetPreferencesPhraseProperty; + +public: + TargetPreferencesPhrasePropertyItem() {}; + + float GetTargetPreferencesRHSCount() const { + return m_labelsRHSCount; + }; + + const std::list &GetTargetPreferencesRHS() const { + return m_labelsRHS; + }; + + const std::list< std::pair > &GetTargetPreferencesLHSList() const { + return m_labelsLHSList; + }; + +private: + float m_labelsRHSCount; + std::list m_labelsRHS; // should be of size nNTs-1 (empty if initial rule, i.e. no right-hand side non-terminals) + std::list< std::pair > m_labelsLHSList; // list of left-hand sides for this right-hand side, with counts +}; + + +class TargetPreferencesPhraseProperty : public PhraseProperty +{ +public: + TargetPreferencesPhraseProperty() {}; + + virtual void ProcessValue(const std::string &value); + + size_t GetNumberOfNonTerminals() const { + return m_nNTs; + } + + float GetTotalCount() const { + return m_totalCount; + } + + const std::list &GetTargetPreferencesItems() const { + return m_labelItems; + }; + + virtual const std::string *GetValueString() const { + UTIL_THROW2("TargetPreferencesPhraseProperty: value string not available in this phrase property"); + return NULL; + }; + +protected: + + size_t m_nNTs; + float m_totalCount; + + std::list m_labelItems; +}; + +} // namespace Moses +