private static boolean turkish_match_pattern(CharArrayMap<Integer> dlist, int point, char[] turkish_string, int length) { final int turkish_context_size = 10; int rank = dlist.size() * 2; char[] str = turkish_get_context(turkish_context_size, point, turkish_string, length); //System.out.println("length = " + str.length); int start = 0; int end; int _len = str.length; while (start <= turkish_context_size) { end = turkish_context_size + 1; while (end <= _len) { Integer r = dlist.get(str, start, end - start); if (r != null && Math.abs(r) < Math.abs(rank)) { rank = r; } end++; } start++; } return rank > 0; }
public static CharArrayMap<Integer> getMap(char c) { switch (c) { case 'c': return MapC.map; case 'g': return MapG.map; case 'i': return MapI.map; case 'o': return MapO.map; case 's': return MapS.map; case 'u': return MapU.map; default: return null; } }
private static CharArrayMap<char[]> initializeDictHash() { CharArrayMap<char[]> charMap = new CharArrayMap<>(2000, false); try { URL url = Resources.getResource(BritishUSFilter.class, "british.txt"); String text = Resources.toString(url, Charsets.UTF8_CHARSET); String[] lines = text.split("\n"); for (String line : lines) { if (!line.startsWith("UK\tUS")) { String[] parts = line.split("\t"); if (parts.length == 2) { charMap.put(parts[0].toCharArray(), parts[1].toCharArray()); } } } } catch (Exception e) { throw new RuntimeException(e); } return charMap; }
/** * Determine if char at cursor needs correction. */ private static boolean turkish_need_correction(char c, int point, char[] turkish_string, int length) { final Character tr; if (turkish_asciify_table.containsKey(c)) tr = turkish_asciify_table.get(c); else tr = c; CharArrayMap<Integer> pl = PatternTableFactory.getMap(Character.toLowerCase(tr)); boolean m = false; if (pl != null) { m = turkish_match_pattern(pl, point, turkish_string, length); } if (tr.equals('I')) { if (c == tr) { return !m; } else { return m; } } else { if (c == tr) { return m; } else { return !m; } } }
private List<TermIDF> getResults(String fieldName, CharArrayMap<MutableValueInt> map, int numResults) { TFIDFPriorityQueue queue = new TFIDFPriorityQueue(numResults); IDFIndexCalc idfCalc = new IDFIndexCalc(searcher.getIndexReader()); int tf = -1; double idf = -1.0; int minTf = minTermFreq; String text = null; //make more efficient // Term reusableTerm = new Term(fieldName, ""); for (Map.Entry<Object, MutableValueInt> entry : map.entrySet()) { tf = entry.getValue().value; if (tf < minTf) continue; text = new String((char[]) entry.getKey()); // calculate idf for potential phrase try { idf = idfCalc.singleTermIDF(new Term(fieldName, text)); } catch (IOException e) { throw new RuntimeException("Error trying to calculate IDF: " + e.getMessage()); } int estimatedDF = (int) Math.max(1, Math.round(idfCalc.unIDF(idf))); TermIDF r = new TermIDF(text, estimatedDF, tf, idf); queue.insertWithOverflow(r); } List<TermIDF> results = new LinkedList<>(); while (queue.size() > 0) { results.add(0, queue.pop()); } return results; }