software/test/performance/src/org/LexGrid/LexBIG/example/remote2/MetaMatch2.java
/**
     * Attempt to approximate spelling suggestions.
     * @param s The test string.
     * @throws LBException
     */
Attempt to approximate spelling suggestions.
@param s The test string.
Attempt to approximate spelling suggestions . @param s The test string .
protected void matchSpell(String s)
        throws LBException
    {
        _buffer.delete(0, _buffer.length());
        Util.StopWatch stopWatch = new Util.StopWatch();
        _buffer.append("\n*** Matching spell suggestions ...\n");
        String[] words = toWords(s, true);
        String prefix = words[0].substring(0, 1);
        CodedNodeSet nodes = _lbSvc.getCodingSchemeConcepts(_scheme, _csvt);
        StringBuffer searchPhrase = new StringBuffer(s).append('~');
        nodes.restrictToMatchingDesignations(
            searchPhrase.toString(), SearchDesignationOption.ALL,
            MatchAlgorithms.LuceneQuery.toString(), null);
        SortOptionList sortCriteria =
            Constructors.createSortOptionList(new String[]{"matchToQuery"});
        ResolvedConceptReferenceList matches =
            nodes.resolveToList(sortCriteria, null, new PropertyType[] {}, 5);
        _buffer.append("* Levenshtein distance (limited to 5 hits): \n");
        if (matches.getResolvedConceptReferenceCount() > 0) {
            int ctr = 0;
            for (int i = 0; i < matches.getResolvedConceptReferenceCount(); i++) {
                ResolvedConceptReference ref = matches.getResolvedConceptReference(i);
                ctr = printText(ctr, ref, true, prefix, words.length);
            }
        } else {
            _buffer.append("\tNo match found.\n");
        }
        _buffer.append("* " + stopWatch.getResult());
        Util.displayMessage(_buffer.toString());
        _buffer.delete(0, _buffer.length());
        stopWatch.start();
        nodes = _lbSvc.getCodingSchemeConcepts(_scheme, _csvt);
        nodes.restrictToMatchingDesignations(
            s, SearchDesignationOption.ALL,
            MatchAlgorithms.DoubleMetaphoneLuceneQuery.toString(), null);
        matches = nodes.resolveToList(sortCriteria, null, new PropertyType[] {}, 5);
        _buffer.append("\n* Sounds-like/DoubleMetaphone (limited to 5 hits): \n");
        if (matches.getResolvedConceptReferenceCount() > 0) {
            int ctr = 0;
            for (int i = 0; i < matches.getResolvedConceptReferenceCount(); i++) {
                ResolvedConceptReference ref = matches.getResolvedConceptReference(i);
                ctr = printText(ctr, ref, true, prefix, words.length);
            }
        } else {
            _buffer.append("\tNo match found.\n");
        }
        _buffer.append("* " + stopWatch.getResult());
        Util.displayMessage(_buffer.toString());
    }
protected void matchSpell ( String s ) throws LBException { _buffer . delete ( 0 , _buffer . length ( ) ) ; Util . StopWatch stopWatch = new Util . StopWatch ( ) ; _buffer . append ( "\n*** Matching spell suggestions ...\n" ) ; String [ ] words = toWords ( s , true ) ; String prefix = words [ 0 ] . substring ( 0 , 1 ) ; CodedNodeSet nodes = _lbSvc . getCodingSchemeConcepts ( _scheme , _csvt ) ; StringBuffer searchPhrase = new StringBuffer ( s ) . append ( '~' ) ; nodes . restrictToMatchingDesignations ( searchPhrase . toString ( ) , SearchDesignationOption . ALL , MatchAlgorithms . LuceneQuery . toString ( ) , null ) ; SortOptionList sortCriteria = Constructors . createSortOptionList ( new String [ ] { "matchToQuery" } ) ; ResolvedConceptReferenceList matches = nodes . resolveToList ( sortCriteria , null , new PropertyType [ ] { } , 5 ) ; _buffer . append ( "* Levenshtein distance (limited to 5 hits): \n" ) ; if ( matches . getResolvedConceptReferenceCount ( ) > 0 ) { int ctr = 0 ; for ( int i = 0 ; i < matches . getResolvedConceptReferenceCount ( ) ; i ++ ) { ResolvedConceptReference ref = matches . getResolvedConceptReference ( i ) ; ctr = printText ( ctr , ref , true , prefix , words . length ) ; } } else { _buffer . append ( "\tNo match found.\n" ) ; } _buffer . append ( "* " + stopWatch . getResult ( ) ) ; Util . displayMessage ( _buffer . toString ( ) ) ; _buffer . delete ( 0 , _buffer . length ( ) ) ; stopWatch . start ( ) ; nodes = _lbSvc . getCodingSchemeConcepts ( _scheme , _csvt ) ; nodes . restrictToMatchingDesignations ( s , SearchDesignationOption . ALL , MatchAlgorithms . DoubleMetaphoneLuceneQuery . toString ( ) , null ) ; matches = nodes . resolveToList ( sortCriteria , null , new PropertyType [ ] { } , 5 ) ; _buffer . append ( "\n* Sounds-like/DoubleMetaphone (limited to 5 hits): \n" ) ; if ( matches . getResolvedConceptReferenceCount ( ) > 0 ) { int ctr = 0 ; for ( int i = 0 ; i < matches . getResolvedConceptReferenceCount ( ) ; i ++ ) { ResolvedConceptReference ref = matches . getResolvedConceptReference ( i ) ; ctr = printText ( ctr , ref , true , prefix , words . length ) ; } } else { _buffer . append ( "\tNo match found.\n" ) ; } _buffer . append ( "* " + stopWatch . getResult ( ) ) ; Util . displayMessage ( _buffer . toString ( ) ) ; }
Attempt to approximate spelling suggestions.
Attempt to approximate spelling suggestions .
// Note: Metaphrase contained an integrated spell check module;
 // LexBIG does not as of the 2.0 release.  Instead, spell
 // suggestion is based off entire phrase in comparison
 // to content stored in the ontology; no external dictionary
 // is utilized.  While a dedicated speller has advantages,
 // there are also advantages to this approach (e.g. automatic
 // tuning of the search to the ontology content).
 //
 // Two different algorithms are highlighted in this code
 // for consideration. The first utilizes the lucene-based
 // Levenshtein distance algorithm.  The second utilizes the
 // DoubleMetaphoneLuceneQuery (sounds-like) algorithm.
 //
 // Queries are currently made against all text representations
 // and not just the primary text representation for ,
 // but this could be narrowed.
 //
 // On resolve, we sort by lucene score ('matchToQuery' sort algorithm).
 // Levenshtein 'edit distance' processing ...
 // Resolve and analyze the result ...
 // Found a match?
 // OK, so we have it narrowed to a concept at this point but not a
 // specific term.  Narrow the choices to those that include the same
 // starting letter and number of words as our test phrase.
 //----------------------------------------------------------------------
 // Sounds-like processing ...
 //----------------------------------------------------------------------
 // Resolve and analyze the result ...
 // Found a match?
 // Once again we have it narrowed to a concept at this point but not
 // a specific term.  Narrow the choices to those that include the same
 // starting letter and number of words as our test phrase.
