Changeset 229

Show
Ignore:
Timestamp:
12/30/07 00:17:45 (1 year ago)
Author:
chris
Message:

Make search work the way that Ulrik recommended.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/lex/Search.java

    r225 r229  
    44import java.sql.SQLException; 
    55import java.util.ArrayList; 
     6import java.util.Iterator; 
    67import java.util.List; 
    78 
     9import jemdros.FlatSheaf; 
     10import jemdros.FlatSheafConstIterator; 
     11import jemdros.FlatStraw; 
     12import jemdros.FlatStrawConstIterator; 
    813import jemdros.MatchedObject; 
    914import jemdros.SetOfMonads; 
     
    1116import jemdros.SheafConstIterator; 
    1217import jemdros.Straw; 
    13 import jemdros.StrawConstIterator; 
    1418 
    1519import org.xml.sax.SAXException; 
     
    3135    } 
    3236     
    33     private static class ResultLocation 
     37    private static class ResultBase 
    3438    { 
    35         private SetOfMonads m_Monads; 
    36         public ResultLocation(SetOfMonads monads) 
    37         { 
    38             m_Monads = monads; 
    39         } 
     39        String location; 
     40        String url; 
     41        SetOfMonads monads; 
     42        List<MatchedObject> words = new ArrayList<MatchedObject>(); 
    4043    } 
    4144     
     
    4649            new HebrewMorphemeGenerator(m_Emdros); 
    4750         
    48         String getFeatures = "GET " + 
    49             "lexeme, " + 
    50             "phrase_dependent_part_of_speech, " + 
    51             "graphical_preformative, " + 
    52             "graphical_root_formation, " + 
    53             "graphical_lexeme, " + 
    54             "graphical_verbal_ending, " + 
    55             "graphical_nominal_ending, " + 
    56             "graphical_pron_suffix"; 
    57          
    5851        Sheaf sheaf = m_Emdros.getSheaf 
    5952        ( 
     
    6255            "WHERE [verse GET book, chapter, verse, verse_label " + 
    6356            "       [clause "+ 
    64             "        [" + 
    65             "         [word FIRST lexeme = '"+m_Query+"' " + getFeatures + "] " +  
    66             "         [word " + getFeatures + "]* " + 
    67             "         [word LAST " + getFeatures + "] " + 
    68             "        ]" + 
    69             "        OR" + 
    70             "        [" + 
    71             "         [word FIRST " + getFeatures + "] " + 
    72             "         [word " + getFeatures + "]* " + 
    73             "         [word lexeme = '"+m_Query+"' " + getFeatures + "] " +  
    74             "         [word " + getFeatures + "]* " + 
    75             "         [word LAST " + getFeatures + "] " + 
    76             "        ]" + 
    77             "        OR" + 
    78             "        [" + 
    79             "         [word FIRST " + getFeatures + "] " + 
    80             "         [word " + getFeatures + "]* " + 
    81             "         [word LAST lexeme = '"+m_Query+"' " + getFeatures + "] " +  
    82             "        ]" + 
    83             "       ]"+ 
    84             "      ]"); 
    85               
    86         List<SearchResult> results = new ArrayList<SearchResult>(); 
     57            "        [word NORETRIEVE lexeme = '"+m_Query+"']" + 
     58            "       ]" + 
     59            "      ]" 
     60        ); 
     61         
     62        List<ResultBase> resultBases = new ArrayList<ResultBase>(); 
     63        SetOfMonads powerSet = new SetOfMonads(); 
    8764         
    8865        SheafConstIterator sci = sheaf.const_iterator(); 
     
    9976                MatchedObject clause = 
    10077                    clause_iter.next().const_iterator().next(); 
    101  
    102                 String lexemes = ""; 
    103                  
    104                 StrawConstIterator word_iter = 
    105                     clause.getSheaf().const_iterator().next().const_iterator(); 
    106                      
    107                 while (word_iter.hasNext()) 
    108                 { 
    109                     MatchedObject word = word_iter.next(); 
    110                      
    111                     if (word.getEMdFValue("lexeme").toString().equals(m_Query)) 
    112                     { 
    113                         lexemes += "<strong>"; 
    114                     } 
    115                      
    116                     lexemes += HebrewConverter.wordToHtml(word, generator); 
    117                      
    118                     if (word.getEMdFValue("lexeme").toString().equals(m_Query)) 
    119                     { 
    120                         lexemes += "</strong>"; 
    121                     } 
    122              
    123                     lexemes += " "; 
    124                 } 
    125  
    126                 SearchResult result = new SearchResult( 
    127                     verse.getFeatureAsString( 
    128                         verse.getEMdFValueIndex("verse_label")), 
    129                     lexemes, 
    130                     "clause.jsp?book=" +  
     78                ResultBase base = new ResultBase(); 
     79                base.monads = clause.getMonads(); 
     80                base.location = verse.getFeatureAsString( 
     81                    verse.getEMdFValueIndex("verse_label")); 
     82                base.url = "clause.jsp?book=" +  
    13183                    m_Emdros.getEnumConstNameFromValue("book_name_e", 
    13284                        verse.getEMdFValue("book").getInt()) + 
    13385                    "&amp;chapter=" + verse.getEMdFValue("chapter") + 
    13486                    "&amp;verse="   + verse.getEMdFValue("verse") + 
    135                     "&amp;clause="  + clause.getID_D() 
    136                 ); 
     87                    "&amp;clause="  + clause.getID_D(); 
     88                resultBases.add(base); 
     89                powerSet.unionWith(base.monads); 
     90            } 
     91        } 
     92         
     93        List<SearchResult> results = new ArrayList<SearchResult>(); 
     94 
     95        if (powerSet.isEmpty()) 
     96        { 
     97            return results; 
     98        } 
     99 
     100        FlatSheaf flat = m_Emdros.getFlatSheaf( 
     101            "GET OBJECTS HAVING MONADS IN " + 
     102            powerSet.toString() +  
     103            "[word GET " + 
     104            " lexeme, " + 
     105            " phrase_dependent_part_of_speech, " + 
     106            " graphical_preformative, " + 
     107            " graphical_root_formation, " + 
     108            " graphical_lexeme, " + 
     109            " graphical_verbal_ending, " + 
     110            " graphical_nominal_ending, " + 
     111            " graphical_pron_suffix" + 
     112            "]"); 
     113         
     114        FlatSheafConstIterator fsci = flat.const_iterator(); 
     115        FlatStraw fs = fsci.next(); 
     116        FlatStrawConstIterator fwci = fs.const_iterator(); 
     117         
     118        while (fwci.hasNext()) 
     119        { 
     120            MatchedObject word = fwci.next(); 
     121            for (Iterator<ResultBase> i = resultBases.iterator(); i.hasNext();) 
     122            { 
     123                ResultBase base = i.next(); 
     124                if (SetOfMonads.overlap(base.monads, word.getMonads())) 
     125                { 
     126                    base.words.add(word); 
     127                } 
     128            } 
     129        } 
     130         
     131        for (Iterator<ResultBase> i = resultBases.iterator(); i.hasNext();) 
     132        { 
     133            ResultBase base = i.next(); 
     134            String lexemes = ""; 
     135             
     136            for (Iterator<MatchedObject> j = base.words.iterator(); j.hasNext();) 
     137            { 
     138                MatchedObject word = j.next(); 
    137139                 
    138                 results.add(result); 
     140                if (word.getEMdFValue("lexeme").toString().equals(m_Query)) 
     141                { 
     142                    lexemes += "<strong>"; 
     143                } 
     144                 
     145                lexemes += HebrewConverter.wordToHtml(word, generator); 
     146                 
     147                if (word.getEMdFValue("lexeme").toString().equals(m_Query)) 
     148                { 
     149                    lexemes += "</strong>"; 
     150                } 
     151         
     152                lexemes += " "; 
    139153            } 
     154 
     155            SearchResult result = new SearchResult(base.location,  
     156                lexemes, base.url); 
     157            results.add(result); 
    140158        } 
    141159