Example usage for org.apache.lucene.analysis CharArrayMap put

List of usage examples for org.apache.lucene.analysis CharArrayMap put

Introduction

In this page you can find the example usage for org.apache.lucene.analysis CharArrayMap put.

Prototype

public V put(char[] text, V value) 

Source Link

Document

Add the given mapping.

Usage

From source file:com.lucid.analysis.LucidKStemmer.java

License:Open Source License

private static CharArrayMap<DictEntry> initializeDictHash() {
    DictEntry defaultEntry;//from w w  w.j  av  a  2  s. c o  m
    DictEntry entry;

    CharArrayMap<DictEntry> d = new CharArrayMap<DictEntry>(Version.LUCENE_31, 1000, false);

    d = new CharArrayMap<DictEntry>(Version.LUCENE_31, 1000, false);
    for (int i = 0; i < exceptionWords.length; i++) {
        if (!d.containsKey(exceptionWords[i])) {
            entry = new DictEntry(exceptionWords[i], true);
            d.put(exceptionWords[i], entry);
        } else {
            System.out.println("Warning: Entry [" + exceptionWords[i] + "] already in dictionary 1");
        }
    }

    for (int i = 0; i < directConflations.length; i++) {
        if (!d.containsKey(directConflations[i][0])) {
            entry = new DictEntry(directConflations[i][1], false);
            d.put(directConflations[i][0], entry);
        } else {
            System.out.println("Warning: Entry [" + directConflations[i][0] + "] already in dictionary 2");
        }
    }

    for (int i = 0; i < countryNationality.length; i++) {
        if (!d.containsKey(countryNationality[i][0])) {
            entry = new DictEntry(countryNationality[i][1], false);
            d.put(countryNationality[i][0], entry);
        } else {
            System.out.println("Warning: Entry [" + countryNationality[i][0] + "] already in dictionary 3");
        }
    }

    defaultEntry = new DictEntry(null, false);

    String[] array;
    array = KStemData1.data;

    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    array = KStemData2.data;
    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    array = KStemData3.data;
    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    array = KStemData4.data;
    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    array = KStemData5.data;
    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    array = KStemData6.data;
    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    array = KStemData7.data;
    for (int i = 0; i < array.length; i++) {
        if (!d.containsKey(array[i])) {
            d.put(array[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + array[i] + "] already in dictionary 4");
        }
    }

    for (int i = 0; i < KStemData8.data.length; i++) {
        if (!d.containsKey(KStemData8.data[i])) {
            d.put(KStemData8.data[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + KStemData8.data[i] + "] already in dictionary 4");
        }
    }

    for (int i = 0; i < supplementDict.length; i++) {
        if (!d.containsKey(supplementDict[i])) {
            d.put(supplementDict[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + supplementDict[i] + "] already in dictionary 5");
        }
    }

    for (int i = 0; i < properNouns.length; i++) {
        if (!d.containsKey(properNouns[i])) {
            d.put(properNouns[i], defaultEntry);
        } else {
            System.out.println("Warning: Entry [" + properNouns[i] + "] already in dictionary 6");
        }
    }

    return d;
}

From source file:org.apache.solr.util.TestCharArrayMap.java

License:Apache License

public void doRandom(int iter, boolean ignoreCase) {
    CharArrayMap map = new CharArrayMap(1, ignoreCase);
    HashMap hmap = new HashMap();

    char[] key;/* ww  w  .  j a  v a2 s .c om*/
    for (int i = 0; i < iter; i++) {
        int len = r.nextInt(5);
        key = new char[len];
        for (int j = 0; j < key.length; j++) {
            key[j] = (char) r.nextInt(127);
        }
        String keyStr = new String(key);
        String hmapKey = ignoreCase ? keyStr.toLowerCase() : keyStr;

        int val = r.nextInt();

        Object o1 = map.put(key, val);
        Object o2 = hmap.put(hmapKey, val);
        assertEquals(o1, o2);

        // add it again with the string method
        assertEquals(val, map.put(keyStr, val));

        assertEquals(val, map.get(key, 0, key.length));
        assertEquals(val, map.get(key));
        assertEquals(val, map.get(keyStr));

        assertEquals(hmap.size(), map.size());
    }

    assertEquals(map, hmap);
    assertEquals(hmap, map);
}

From source file:org.tallison.lucene.contrast.QueryToCorpusContraster.java

License:Apache License

public List<TermIDF> contrast(Query query, String fieldName, int numResults) throws IOException {
    TopScoreDocCollector results = TopScoreDocCollector.create(maxDocs, maxDocs + 10000);
    searcher.search(query, results);//  w  w  w.  j a  v a 2  s  .  c om

    ScoreDoc[] scoreDocs = results.topDocs().scoreDocs;
    //if there are fewer documents than minTermFreq
    //return empty list now
    if (scoreDocs.length < minTermFreq) {
        return new ArrayList<TermIDF>();
    }

    //total hack
    int initialSize = scoreDocs.length * 100;
    CharArrayMap<MutableValueInt> map = new CharArrayMap<MutableValueInt>(initialSize, ignoreCase);
    CharArraySet tmpSet = new CharArraySet(100, ignoreCase);
    Set<String> selector = new HashSet<String>();
    selector.add(fieldName);

    for (ScoreDoc scoreDoc : scoreDocs) {
        //get terms from doc
        processDoc(scoreDoc.doc, fieldName, selector, tmpSet);
        //now update global doc freqs
        Iterator<Object> it = tmpSet.iterator();
        while (it.hasNext()) {
            char[] token = (char[]) it.next();
            MutableValueInt docCount = map.get(token, 0, token.length);
            if (docCount == null) {
                docCount = new MutableValueInt();
                docCount.value = 1;
            } else {
                docCount.value++;
            }
            map.put(token, docCount);
        }
        tmpSet.clear();
    }

    return getResults(fieldName, map, numResults);
}