[Tynstep-svn] r173 - in trunk: step-web-app/src/main/resources/com/tyndalehouse/step/web/client/css step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage

ChrisBurrell at crosswire.org ChrisBurrell at crosswire.org
Mon Aug 9 12:18:30 MST 2010


Author: ChrisBurrell
Date: 2010-08-09 12:18:30 -0700 (Mon, 09 Aug 2010)
New Revision: 173

Added:
   trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/MorphWordCombo.java
Modified:
   trunk/step-web-app/src/main/resources/com/tyndalehouse/step/web/client/css/passage.css
   trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/GetCurrentBibleTextHandler.java
   trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/StrongMorphMap.java
Log:
committing interlinear fix

Modified: trunk/step-web-app/src/main/resources/com/tyndalehouse/step/web/client/css/passage.css
===================================================================
--- trunk/step-web-app/src/main/resources/com/tyndalehouse/step/web/client/css/passage.css	2010-08-08 11:34:15 UTC (rev 172)
+++ trunk/step-web-app/src/main/resources/com/tyndalehouse/step/web/client/css/passage.css	2010-08-09 19:18:30 UTC (rev 173)
@@ -47,12 +47,13 @@
 
 .interlinear { 
 	float: left; 
-	text-align: center;
-	margin-top: 8px; 
+	margin-top: 8px;
 }
 
 .interlinear td {
 	white-space: nowrap; 
+	height: 1.5em; 
+	text-align: center;
 }
 
 .interlinearTitle { 

Modified: trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/GetCurrentBibleTextHandler.java
===================================================================
--- trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/GetCurrentBibleTextHandler.java	2010-08-08 11:34:15 UTC (rev 172)
+++ trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/GetCurrentBibleTextHandler.java	2010-08-09 19:18:30 UTC (rev 173)
@@ -202,7 +202,7 @@
 
         if (GREEK.equals(translatedText.getOriginalLanguage())) {
             versionToUse = DEFAULT_GREEK_INTERLINEAR_TEXT;
-        } else if (HEBREW.equals(translatedText)) {
+        } else if (HEBREW.equals(translatedText.getOriginalLanguage())) {
             versionToUse = DEFAULT_HEBREW_INTERLINEAR_TEXT;
         } else {
             // TODO remove all references to Action exceptions if possible

Added: trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/MorphWordCombo.java
===================================================================
--- trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/MorphWordCombo.java	                        (rev 0)
+++ trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/MorphWordCombo.java	2010-08-09 19:18:30 UTC (rev 173)
@@ -0,0 +1,41 @@
+package com.tyndalehouse.step.web.server.handler.util.passage;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MorphWordCombo {
+    private final Map<String, String> morphToWord = new HashMap<String, String>();
+
+    /**
+     * adds a key to the combo. This overwrites previous morph keys
+     * 
+     * @param morph
+     *            the morph
+     * @param word
+     *            the word
+     */
+    public void put(final String morph, final String word) {
+        morphToWord.put(morph, word);
+    }
+
+    /**
+     * returns the list of values contained in this combo
+     * 
+     * @return
+     */
+    public Collection<String> values() {
+        return morphToWord.values();
+    }
+
+    /**
+     * returns the value attached to the current morphology
+     * 
+     * @param morph
+     *            the morphology of the word to retrieve
+     * @return the word attached to the morphology
+     */
+    public String get(final String morph) {
+        return morphToWord.get(morph);
+    }
+}

Modified: trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/StrongMorphMap.java
===================================================================
--- trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/StrongMorphMap.java	2010-08-08 11:34:15 UTC (rev 172)
+++ trunk/step-web-server/src/main/java/com/tyndalehouse/step/web/server/handler/util/passage/StrongMorphMap.java	2010-08-09 19:18:30 UTC (rev 173)
@@ -1,10 +1,16 @@
 package com.tyndalehouse.step.web.server.handler.util.passage;
 
+import static org.apache.commons.lang.StringUtils.isNotEmpty;
+
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.lang.StringUtils;
+
 /**
  * This map will store the mapping for strong,morph to the word However
  * sometimes the morphology of the word is not present in the passage and since
@@ -32,10 +38,10 @@
      * this map maps strong numbers to morphs. it is the first level of
      * indirection to the map of morphs which maps to a word
      */
-    private final Map<String, Map<String, String>> strongToMorph;
+    private final Map<String, MorphWordCombo> strongToMorph;
 
     /**
-     * this map maps the strong number ot the word directly
+     * this map maps the strong number to the word directly
      */
     private final Map<String, String> strongToWord;
 
@@ -43,7 +49,7 @@
      * Default constructor that initialises the two maps
      */
     public StrongMorphMap() {
-        strongToMorph = new HashMap<String, Map<String, String>>();
+        strongToMorph = new HashMap<String, MorphWordCombo>();
         strongToWord = new HashMap<String, String>();
     }
 
@@ -51,12 +57,17 @@
      * only to be used if no morph is available
      * 
      * @param strong
-     *            the strong number or lemma
+     *            the strong numbers or lemmas
      * @param word
      *            the word to be stored
      */
     public final void addWord(final String strong, final String word) {
-        strongToWord.put(strong, word);
+        if (isNotEmpty(strong)) {
+            final String[] multipleLemmas = strong.split(" ");
+            for (final String l : multipleLemmas) {
+                strongToWord.put(l, word);
+            }
+        }
     }
 
     /**
@@ -75,10 +86,16 @@
             return;
         }
 
-        Map<String, String> morphsToWords = strongToMorph.get(strong);
+        MorphWordCombo morphsToWords = strongToMorph.get(strong);
         if (morphsToWords == null) {
-            morphsToWords = new HashMap<String, String>();
-            strongToMorph.put(strong, morphsToWords);
+            morphsToWords = new MorphWordCombo();
+
+            if (StringUtils.isNotEmpty(strong)) {
+                final String[] lemmas = strong.split(" ");
+                for (final String l : lemmas) {
+                    strongToMorph.put(l, morphsToWords);
+                }
+            }
         }
 
         // guaranteed non-null map
@@ -98,22 +115,31 @@
      */
     // TODO: check for nulls on lemma
     public final String get(final String lemma, final String morph) {
-        final Map<String, String> morphToWord = strongToMorph.get(lemma);
+        final MorphWordCombo[] morphToWord = getMorphToWordMap(lemma);
 
         if (morphToWord != null) {
             if (morph != null) {
                 // use the chain from morphs to word
-                final String word = morphToWord.get(morph);
-                if (word != null) {
+                final String word = getWords(morphToWord, morph);
+
+                if (isNotEmpty(word)) {
                     return word;
                 } else {
                     // well we didn't find our morph, so the best option is to
                     // return another morph for the same strong number
-                    final Collection<String> words = morphToWord.values();
-                    final Iterator<String> wordsIterator = words.iterator();
-                    if (wordsIterator.hasNext()) {
-                        return wordsIterator.next();
+                    // since we have keyed by multiple lemmas sometimes, we
+                    // return one of each!?
+                    final StringBuilder alternativeText = new StringBuilder();
+                    for (int ii = 0; ii < morphToWord.length; ii++) {
+                        final Collection<String> words = morphToWord[ii].values();
+                        // TODO why iterator here?
+                        final Iterator<String> wordsIterator = words.iterator();
+                        if (wordsIterator.hasNext()) {
+                            alternativeText.append(wordsIterator.next());
+                            continue;
+                        }
                     }
+                    return alternativeText.toString();
                 }
             }
         }
@@ -123,4 +149,47 @@
         // therefore, let's just return something from the other map
         return strongToWord.get(lemma);
     }
+
+    /**
+     * returns any words contained in the morph map concatenated
+     * 
+     * @param morphToWord
+     *            the list of morph, for all lemmas in the key
+     * @param morph
+     *            the morph map
+     * @return the list of words associated with the morph
+     */
+    private String getWords(final MorphWordCombo[] morphToWord, final String morph) {
+        final StringBuilder allWords = new StringBuilder();
+        for (final MorphWordCombo words : morphToWord) {
+            final String wordText = words.get(morph);
+            if (wordText != null) {
+                allWords.append(wordText);
+            }
+        }
+
+        return allWords.toString();
+    }
+
+    MorphWordCombo[] getMorphToWordMap(final String lemma) {
+        final MorphWordCombo morphWordCombo = strongToMorph.get(lemma);
+        if (morphWordCombo != null) {
+            return new MorphWordCombo[] { morphWordCombo };
+        }
+
+        // TODO define " " in a common place
+        final String[] lemmas = lemma.split(" ");
+        final List<MorphWordCombo> matchingMorphs = new ArrayList<MorphWordCombo>();
+        for (final String l : lemmas) {
+            final MorphWordCombo matchingMorph = strongToMorph.get(l);
+            if (matchingMorph != null) {
+                matchingMorphs.add(matchingMorph);
+            }
+        }
+
+        // TODO check spec to find out if we need to allocate a number of
+        // elements in array, if used uniquely for determining
+        // type
+        return matchingMorphs.toArray(new MorphWordCombo[matchingMorphs.size()]);
+    }
 }




More information about the Tynstep-svn mailing list