software/test/performance/src/org/LexGrid/LexBIG/example/remote2/MetaMatch2.java
/**
     * Attempt to approximate word completion.
     * @param s The test string.
     * @throws LBException
     */
Attempt to approximate word completion.
@param s The test string.
Attempt to approximate word completion . @param s The test string .
@SuppressWarnings("unchecked")
    protected void matchWordCompletion(String s)
        throws LBException
    {
        _buffer.delete(0, _buffer.length());
        Util.StopWatch stopWatch = new Util.StopWatch();
        _buffer.append("\n*** Word completion (based on '.') ...\n");
        String prefix = s.toLowerCase();
        String[] words = toWords(prefix, false);
        StringBuffer regex = new StringBuffer();
        regex.append('^');
        for (int i = 0; i < words.length; i++) {
            boolean lastWord = i == words.length - 1;
            String word = words[i];
            regex.append('(');
            if (word.charAt(word.length() - 1) == '.') {
                regex.append(word.substring(0, word.length()));
                regex.append("\\w*");
            }
            else
                regex.append(word);
            regex.append("\\s").append(lastWord ? '*' : '+');
            regex.append(')');
        }
        regex.append("\\Z");
        CodedNodeSet nodes = _lbSvc.getCodingSchemeConcepts(_scheme, _csvt);
        nodes.restrictToMatchingDesignations(
                regex.toString(), SearchDesignationOption.ALL,
                "RegExp", null);
        SortOptionList sortCriteria =
            Constructors.createSortOptionList(new String[]{"matchToQuery"});
        ResolvedConceptReferenceList matches =
            nodes.resolveToList(sortCriteria, null, new PropertyType[] {}, 5);
        _buffer.append("* Found via RegExp match (limited to 5 hits)...\n");
        if (matches.getResolvedConceptReferenceCount() > 0) {
            int dotIndex = prefix.indexOf('.');
            if (dotIndex < 0)
                dotIndex = prefix.length();
            int ctr = 0;
            for (int i = 0; i < matches.getResolvedConceptReferenceCount(); i++) {
                ResolvedConceptReference ref = matches.getResolvedConceptReference(i);
                ctr = printText(ctr, ref, false, prefix.substring(0, dotIndex), -1);
            }
        } else {
            _buffer.append("\tNo match found.\n");
        }
        _buffer.append("* " + stopWatch.getResult());
        Util.displayMessage(_buffer.toString());
    }
@ SuppressWarnings ( "unchecked" ) protected void matchWordCompletion ( String s ) throws LBException { _buffer . delete ( 0 , _buffer . length ( ) ) ; Util . StopWatch stopWatch = new Util . StopWatch ( ) ; _buffer . append ( "\n*** Word completion (based on '.') ...\n" ) ; String prefix = s . toLowerCase ( ) ; String [ ] words = toWords ( prefix , false ) ; StringBuffer regex = new StringBuffer ( ) ; regex . append ( '^' ) ; for ( int i = 0 ; i < words . length ; i ++ ) { boolean lastWord = i == words . length - 1 ; String word = words [ i ] ; regex . append ( '(' ) ; if ( word . charAt ( word . length ( ) - 1 ) == '.' ) { regex . append ( word . substring ( 0 , word . length ( ) ) ) ; regex . append ( "\\w*" ) ; } else regex . append ( word ) ; regex . append ( "\\s" ) . append ( lastWord ? '*' : '+' ) ; regex . append ( ')' ) ; } regex . append ( "\\Z" ) ; CodedNodeSet nodes = _lbSvc . getCodingSchemeConcepts ( _scheme , _csvt ) ; nodes . restrictToMatchingDesignations ( regex . toString ( ) , SearchDesignationOption . ALL , "RegExp" , null ) ; SortOptionList sortCriteria = Constructors . createSortOptionList ( new String [ ] { "matchToQuery" } ) ; ResolvedConceptReferenceList matches = nodes . resolveToList ( sortCriteria , null , new PropertyType [ ] { } , 5 ) ; _buffer . append ( "* Found via RegExp match (limited to 5 hits)...\n" ) ; if ( matches . getResolvedConceptReferenceCount ( ) > 0 ) { int dotIndex = prefix . indexOf ( '.' ) ; if ( dotIndex < 0 ) dotIndex = prefix . length ( ) ; int ctr = 0 ; for ( int i = 0 ; i < matches . getResolvedConceptReferenceCount ( ) ; i ++ ) { ResolvedConceptReference ref = matches . getResolvedConceptReference ( i ) ; ctr = printText ( ctr , ref , false , prefix . substring ( 0 , dotIndex ) , - 1 ) ; } } else { _buffer . append ( "\tNo match found.\n" ) ; } _buffer . append ( "* " + stopWatch . getResult ( ) ) ; Util . displayMessage ( _buffer . toString ( ) ) ; }
Attempt to approximate word completion.
Attempt to approximate word completion .
// For word completion, we just use a regular expression and
 // substitute any alpha-numeric character for the substitution
 // character ('.').
 // Queries are currently made against all text representations,
 // but this could be narrowed.
 //
 // On resolve, we sort by lucene score ('matchToQuery' sort algorithm).
 // Resolve and analyze the result ...
 // Found a match?
