You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/05/31 16:37:01 UTC

[05/13] incubator-joshua git commit: Handled an edge case where a null hypergraph with topn!=0 would not return an empty output translation

Handled an edge case where a null hypergraph with topn!=0 would not return an empty output translation


Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/b6010671
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/b6010671
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/b6010671

Branch: refs/heads/JOSHUA-252
Commit: b6010671dba008669282a1e7b2b334217443c587
Parents: e3673e9
Author: Artem Sokolov <ar...@amazon.com>
Authored: Fri Apr 22 15:50:38 2016 +0200
Committer: Felix Hieber <fh...@amazon.com>
Committed: Mon May 30 09:09:59 2016 +0200

----------------------------------------------------------------------
 src/joshua/decoder/StructuredTranslationFactory.java | 11 +++++++++++
 src/joshua/decoder/Translation.java                  |  1 +
 src/joshua/decoder/hypergraph/KBestExtractor.java    |  2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/b6010671/src/joshua/decoder/StructuredTranslationFactory.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/StructuredTranslationFactory.java b/src/joshua/decoder/StructuredTranslationFactory.java
index c6bfb50..f3ba33f 100644
--- a/src/joshua/decoder/StructuredTranslationFactory.java
+++ b/src/joshua/decoder/StructuredTranslationFactory.java
@@ -20,6 +20,7 @@ package joshua.decoder;
 
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyList;
+import static java.util.Collections.emptyMap;
 import static joshua.decoder.hypergraph.ViterbiExtractor.getViterbiFeatures;
 import static joshua.decoder.hypergraph.ViterbiExtractor.getViterbiString;
 import static joshua.decoder.hypergraph.ViterbiExtractor.getViterbiWordAlignmentList;
@@ -61,6 +62,16 @@ public class StructuredTranslationFactory {
   }
   
   /**
+   * Returns a StructuredTranslation from an empty decoder output
+   * @param sourceSentence
+   * @return
+   */
+  public static StructuredTranslation fromEmptyOutput(final Sentence sourceSentence) {
+        return new StructuredTranslation(
+                sourceSentence, "", emptyList(), 0, emptyList(), emptyMap(), 0f);
+      }
+  
+  /**
    * Returns a StructuredTranslation instance from a KBest DerivationState. 
    * @param sourceSentence Sentence object representing the source.
    * @param derivationState the KBest DerivationState.

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/b6010671/src/joshua/decoder/Translation.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/Translation.java b/src/joshua/decoder/Translation.java
index 03ea62f..92f9a57 100644
--- a/src/joshua/decoder/Translation.java
+++ b/src/joshua/decoder/Translation.java
@@ -88,6 +88,7 @@ public class Translation {
         final KBestExtractor kBestExtractor = new KBestExtractor(source, featureFunctions, Decoder.weights, false, joshuaConfiguration);
         structuredTranslations = kBestExtractor.KbestExtractOnHG(hypergraph, joshuaConfiguration.topN);
         if (structuredTranslations.isEmpty()) {
+            structuredTranslations = asList(StructuredTranslationFactory.fromEmptyOutput(source));
             this.output = "";
         } else {
             this.output = structuredTranslations.get(0).getTranslationString();

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/b6010671/src/joshua/decoder/hypergraph/KBestExtractor.java
----------------------------------------------------------------------
diff --git a/src/joshua/decoder/hypergraph/KBestExtractor.java b/src/joshua/decoder/hypergraph/KBestExtractor.java
index d6e7c60..c64b449 100644
--- a/src/joshua/decoder/hypergraph/KBestExtractor.java
+++ b/src/joshua/decoder/hypergraph/KBestExtractor.java
@@ -184,7 +184,7 @@ public class KBestExtractor {
    */
   public List<StructuredTranslation> KbestExtractOnHG(HyperGraph hg, int topN) {
     resetState();
-    if (hg.goalNode == null) {
+    if (hg == null || hg.goalNode == null) {
       return emptyList();
     }
     final List<StructuredTranslation> kbest = new ArrayList<>(topN);