<commit_before><commit_msg>First pass at writing ResolveConceptIteratorTest program.<commit_after>package gov.nih.nci.evs.browser.utils.test;

import org.LexGrid.LexBIG.DataModel.Collections.*;
import org.LexGrid.LexBIG.DataModel.Core.*;
import org.LexGrid.LexBIG.LexBIGService.*;
import org.LexGrid.LexBIG.LexBIGService.CodedNodeSet.*;
import org.LexGrid.LexBIG.Utility.*;
import org.LexGrid.LexBIG.Utility.Iterators.*;

public class ResolveConceptIteratorTest {
    private String _codingSchemeName = "NCI MetaThesaurus"; // "NCI Thesaurus"

    private String getConceptInfo(ResolvedConceptReference ref) {
        return ref.getConceptCode() + ": "
            + ref.getEntityDescription().getContent();
    }
    
    private void printConcepts(ResolvedConceptReference[] refs, int offset) {
        for (int i=0; i < refs.length; ++i)
            System.out.println((i+offset+1) + ") " + getConceptInfo(refs[i]));
    }
    
    private ResolvedConceptReferencesIterator search(String matchText, 
        String algorithm, boolean ranking) throws Exception {
        LexBIGService lbs = RemoteServerUtil.createLexBIGService();
        CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag();
        CodedNodeSet cns = lbs.getNodeSet(_codingSchemeName, versionOrTag,
            null);
        cns = cns.restrictToMatchingDesignations(matchText,
            SearchDesignationOption.ALL, algorithm, null);

        LocalNameList restrictToProperties = new LocalNameList();
        boolean resolveConcepts = true;
        SortOptionList sortCriteria = null;

        if (ranking) {
            System.out.println("* Sort by Lucene score...");
            sortCriteria = Constructors
                .createSortOptionList(new String[] { "matchToQuery" });
        } else {
            System.out.println("* Sort alphabetically...");
            sortCriteria = Constructors
                .createSortOptionList(new String[] { "entityDescription" }); // code
            resolveConcepts = false;
        }

        ResolvedConceptReferencesIterator iterator = cns.resolve(sortCriteria,
            null, restrictToProperties, null, resolveConcepts);
        System.out.println("* Search found: " + iterator.numberRemaining());
        return iterator;
    }

    private void getConcepts(ResolvedConceptReferencesIterator iterator, 
        int maxReturn) throws Exception {
        ResolvedConceptReference[] refs = iterator.next(maxReturn)
            .getResolvedConceptReference();
        printConcepts(refs, 0);
    }

    private void test1() throws Exception {
        String matchText = "protein";
        String algorithm = "subString";
        boolean ranking = false;
        int maxReturn = 100;

        ResolvedConceptReferencesIterator iterator =
            search(matchText, algorithm, ranking);
        getConcepts(iterator, maxReturn);
    }

    public static void main(String[] args) throws Exception {
        ResolveConceptIteratorTest test = new ResolveConceptIteratorTest();
        test.test1();
    }
}
{'fraction_non_alphanumeric': 0.09583196586806696, 'fraction_numerical': 0.002625533311453889, 'mean_word_length': 3.0, 'pattern_counts': {'":': 1, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5568707', 'n_tokens_mistral': 856, 'n_tokens_neox': 815, 'n_words': 174}