Scope-3 parsing working again

This commit is contained in:
Hieu Hoang 2013-11-22 16:26:21 +00:00
parent c4dfc60f95
commit 31632301f9
2 changed files with 0 additions and 92 deletions

View File

@ -50,56 +50,6 @@ PhraseDictionaryScope3::PhraseDictionaryScope3(const std::string &line)
}
TargetPhraseCollection &PhraseDictionaryScope3::GetOrCreateTargetPhraseCollection(
const Phrase &source
, const TargetPhrase &target
, const Word *sourceLHS)
{
PhraseDictionaryNodeMemory &currNode = GetOrCreateNode(source, target, sourceLHS);
return currNode.GetTargetPhraseCollection();
}
PhraseDictionaryNodeMemory &PhraseDictionaryScope3::GetOrCreateNode(const Phrase &source
, const TargetPhrase &target
, const Word *sourceLHS)
{
const size_t size = source.GetSize();
const AlignmentInfo &alignmentInfo = target.GetAlignNonTerm();
AlignmentInfo::const_iterator iterAlign = alignmentInfo.begin();
PhraseDictionaryNodeMemory *currNode = &m_collection;
for (size_t pos = 0 ; pos < size ; ++pos) {
const Word& word = source.GetWord(pos);
if (word.IsNonTerminal()) {
// indexed by source label 1st
const Word &sourceNonTerm = word;
UTIL_THROW_IF(iterAlign == alignmentInfo.end(), util::Exception,
"No alignment for non-term at position " << pos);
UTIL_THROW_IF(iterAlign->first != pos, util::Exception,
"Alignment info incorrect at position " << pos);
size_t targetNonTermInd = iterAlign->second;
++iterAlign;
const Word &targetNonTerm = target.GetWord(targetNonTermInd);
currNode = currNode->GetOrCreateChild(sourceNonTerm, targetNonTerm);
} else {
currNode = currNode->GetOrCreateChild(word);
}
UTIL_THROW_IF(currNode == NULL, util::Exception,
"Node not found at position " << pos);
}
// finally, the source LHS
//currNode = currNode->GetOrCreateChild(sourceLHS);
return *currNode;
}
ChartRuleLookupManager *PhraseDictionaryScope3::CreateRuleLookupManager(
const ChartParser &parser,
const ChartCellCollectionBase &cellCollection)
@ -110,31 +60,5 @@ ChartRuleLookupManager *PhraseDictionaryScope3::CreateRuleLookupManager(
return new Scope3Parser(parser, cellCollection, *this, maxChartSpan);
}
void PhraseDictionaryScope3::SortAndPrune()
{
if (GetTableLimit()) {
m_collection.Sort(GetTableLimit());
}
}
TO_STRING_BODY(PhraseDictionaryScope3);
// friend
ostream& operator<<(ostream& out, const PhraseDictionaryScope3& phraseDict)
{
typedef PhraseDictionaryNodeMemory::TerminalMap TermMap;
typedef PhraseDictionaryNodeMemory::NonTerminalMap NonTermMap;
const PhraseDictionaryNodeMemory &coll = phraseDict.m_collection;
for (NonTermMap::const_iterator p = coll.m_nonTermMap.begin(); p != coll.m_nonTermMap.end(); ++p) {
const Word &sourceNonTerm = p->first.first;
out << sourceNonTerm;
}
for (TermMap::const_iterator p = coll.m_sourceTermMap.begin(); p != coll.m_sourceTermMap.end(); ++p) {
const Word &sourceTerm = p->first;
out << sourceTerm;
}
return out;
}
}

View File

@ -34,34 +34,18 @@ class ChartParser;
*/
class PhraseDictionaryScope3 : public RuleTableUTrie
{
friend std::ostream& operator<<(std::ostream&, const PhraseDictionaryScope3&);
friend class RuleTableLoader;
public:
PhraseDictionaryScope3(const std::string &line);
const PhraseDictionaryNodeMemory &GetRootNode() const {
return m_collection;
}
ChartRuleLookupManager*
CreateRuleLookupManager(
const ChartParser &,
const ChartCellCollectionBase &);
TO_STRING();
protected:
TargetPhraseCollection &GetOrCreateTargetPhraseCollection(
const Phrase &source, const TargetPhrase &target, const Word *sourceLHS);
PhraseDictionaryNodeMemory &GetOrCreateNode(const Phrase &source
, const TargetPhrase &target
, const Word *sourceLHS);
void SortAndPrune();
PhraseDictionaryNodeMemory m_collection;
};
} // namespace Moses