You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2008/09/30 13:56:33 UTC

svn commit: r700424 - /incubator/uima/sandbox/trunk/Tagger/src/main/java/org/apache/uima/examples/tagger/Viterbi.java

Author: twgoetz
Date: Tue Sep 30 04:56:33 2008
New Revision: 700424

URL: http://svn.apache.org/viewvc?rev=700424&view=rev
Log:
Jira UIMA-1193: protect against NPE.  Unsure if fix is correct, but test cases still go through.

https://issues.apache.org/jira/browse/UIMA-1193

Modified:
    incubator/uima/sandbox/trunk/Tagger/src/main/java/org/apache/uima/examples/tagger/Viterbi.java

Modified: incubator/uima/sandbox/trunk/Tagger/src/main/java/org/apache/uima/examples/tagger/Viterbi.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/Tagger/src/main/java/org/apache/uima/examples/tagger/Viterbi.java?rev=700424&r1=700423&r2=700424&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/Tagger/src/main/java/org/apache/uima/examples/tagger/Viterbi.java (original)
+++ incubator/uima/sandbox/trunk/Tagger/src/main/java/org/apache/uima/examples/tagger/Viterbi.java Tue Sep 30 04:56:33 2008
@@ -248,8 +248,8 @@
                 }
               } else {
                 Iterator posValuePairs2 = available_pos_zwischen.entrySet().iterator(); // iterate
-                                                                                        // over
-                                                                                        // words
+                // over
+                // words
                 while (posValuePairs2.hasNext()) {
                   Map.Entry<String, Double> entry = (Map.Entry<String, Double>) posValuePairs2
                       .next();
@@ -360,8 +360,13 @@
 
             if (transition_probs.containsKey(ngram)) {
 
+              // The following commented-out expression used to throw the occasional NPE, probably
+              // because transition_probs.get(ngram2) is null. Make sure this does not happen. Not
+              // sure this is the correct way to fix it, though.  Test cases still go through...
+              double transProbNgram2 = (transition_probs.containsKey(ngram2) ? transition_probs
+                  .get(ngram2) : 0.0);
               ppp = (lambda3 * transition_probs.get(ngram))
-                  + (lambda2 * transition_probs.get(ngram2))
+                  + (lambda2 * transProbNgram2)
                   + (lambda1 * transition_probs.get(new NGram(key_next)));
             } else {
               // System.out.println(ngram2);