Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphikoehn <pkoehn@inf.ed.ac.uk>2013-08-15 14:46:45 +0400
committerphikoehn <pkoehn@inf.ed.ac.uk>2013-08-15 14:46:45 +0400
commitb368085609b1d638de571e963295117003defc91 (patch)
tree21777725deebf9a7e7d54e0eccc4af89078843cf /moses/TranslationOptionCollectionText.cpp
parentabfe02f1541bd3f2323e53f2a46875cc78eabc2b (diff)
xml constraint
Diffstat (limited to 'moses/TranslationOptionCollectionText.cpp')
-rw-r--r--moses/TranslationOptionCollectionText.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/moses/TranslationOptionCollectionText.cpp b/moses/TranslationOptionCollectionText.cpp
index f403c0fb6..7b01c2863 100644
--- a/moses/TranslationOptionCollectionText.cpp
+++ b/moses/TranslationOptionCollectionText.cpp
@@ -80,6 +80,51 @@ bool TranslationOptionCollectionText::HasXmlOptionsOverlappingRange(size_t start
}
/**
+ * Check if the given translation option violates a specified xml Option
+ */
+bool TranslationOptionCollectionText::ViolatesXmlOptionsConstraint(size_t startPosition, size_t endPosition, TranslationOption *transOpt) const
+{
+ // skip if there is no overlap
+ Sentence const& source=dynamic_cast<Sentence const&>(m_source);
+ if (!source.XmlOverlap(startPosition,endPosition)) {
+ return false;
+ }
+ // check for all sub spans
+ for(size_t start=startPosition; start<=endPosition; start++) {
+ for(size_t end=start; end<=endPosition; end++) {
+ // get list of xml options for the subspan
+ vector <TranslationOption*> xmlOptions;
+ source.GetXmlTranslationOptions(xmlOptions,start,end);
+ if (xmlOptions.size() > 0) {
+ // check if any xml option matches
+ for(size_t i=0; i<xmlOptions.size(); i++) {
+ const TargetPhrase &phrase = transOpt->GetTargetPhrase();
+ const TargetPhrase &xmlPhrase = xmlOptions[i]->GetTargetPhrase();
+ // check this xml option (if shorter)
+ if (phrase.GetSize() >= xmlPhrase.GetSize()) {
+ // match may start in middle of phrase
+ for(size_t offset=0; offset <= phrase.GetSize()-xmlPhrase.GetSize(); offset++) {
+ bool match = true;
+ // match every word (only surface factor)
+ for(size_t wordPos=0; match && wordPos < xmlPhrase.GetSize(); wordPos++) {
+ if (phrase.GetFactor( wordPos+offset,0 )->Compare(*(xmlPhrase.GetFactor( wordPos,0 )))) {
+ match = false;
+ }
+ }
+ if (match) {
+ return false; // no violation if matching xml option found
+ }
+ }
+ }
+ }
+ return true; // there were xml options for this range, but none matched
+ }
+ }
+ }
+ return false;
+}
+
+/**
* Create xml-based translation options for the specific input span
*/
void TranslationOptionCollectionText::CreateXmlOptionsForRange(size_t startPos, size_t endPos)
@@ -140,5 +185,3 @@ void TranslationOptionCollectionText::CreateTranslationOptionsForRange(
}
-
-