method2testcases
stringlengths
118
6.63k
### Question: SimpleTextReader implements AutoCloseable { public LineIterator getLineIterator() throws IOException { return new LineIterator(getReader(), trim, filters); } SimpleTextReader(InputStream is, Template template); SimpleTextReader(File file); SimpleTextReader(File file, String encoding); SimpleTextReader(...
### Question: LogMath { public static double logSum(double logA, double logB) { if (Double.isInfinite(logA)) { return logB; } if (Double.isInfinite(logB)) { return logA; } if (logA > logB) { double dif = logA - logB; return dif >= 30d ? logA : logA + Math.log(1 + Math.exp(-dif)); } else { double dif = logB - logA; retu...
### Question: LogMath { public static double log(double base, double val) { return Math.log(val) / Math.log(base); } private LogMath(); static double logSum(double logA, double logB); static double logSum10(double log10A, double log10B); static double logSum(double... logValues); static double log(double base, double ...
### Question: LogMath { public static double log2(double input) { return Math.log(input) * INVERSE_LOG_TWO; } private LogMath(); static double logSum(double logA, double logB); static double logSum10(double log10A, double log10B); static double logSum(double... logValues); static double log(double base, double val); s...
### Question: WordGenerator { public List<Result> generate(String stem, List<String> morphemeIds) { List<Morpheme> morphemes = new ArrayList<>(); for (String morphemeId : morphemeIds) { Morpheme morpheme = TurkishMorphotactics.getMorpheme(morphemeId); morphemes.add(morpheme); } List<StemTransition> candidates = stemTra...
### Question: FloatArrays { public static float mean(float... input) { validateArray(input); return sum(input) / input.length; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input); static float[][] convert(int[][] i...
### Question: DoubleArrays { public static double sum(double... input) { double sum = 0; for (double v : input) { sum += v; } return sum; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static double[][...
### Question: DoubleArrays { public static void addToFirstScaled(double[] first, double[] second, double scale) { validateArrays(first, second); for (int i = 0; i < first.length; i++) { first[i] = first[i] + second[i] * scale; } } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); stat...
### Question: DoubleArrays { public static double dotProduct(double[] a1, double[] a2) { return sum(multiply(a1, a2)); } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static double[][] convert(int[][] i...
### Question: DoubleArrays { public static double[] square(double... input) { double[] res = new double[input.length]; for (int i = 0; i < input.length; i++) { res[i] = input[i] * input[i]; } return res; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(doubl...
### Question: DoubleArrays { public static double squaredSum(double[] array) { double result = 0; validateArray(array); for (double a : array) { result += a * a; } return result; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double...
### Question: DoubleArrays { public static void addToAll(double[] data, double valueToAdd) { validateArray(data); for (int i = 0; i < data.length; i++) { data[i] += valueToAdd; } } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double...
### Question: DoubleArrays { public static double mean(double... input) { validateArray(input); return sum(input) / input.length; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static double[][] conver...
### Question: DoubleArrays { public static boolean inRange(double d1, double d2, double range) { return Math.abs(d1 - d2) <= range; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static double[][] conv...
### Question: DoubleArrays { public static double[] reverse(double[] input) { double[] result = new double[input.length]; for (int i = 0; i < input.length; i++) { result[input.length - i - 1] = input[i]; } return result; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static doubl...
### Question: TurkishDictionaryLoader { public static RootLexicon load(File input) throws IOException { return Files.asCharSource(input, Charsets.UTF_8).readLines(new TextLexiconProcessor()); } static RootLexicon loadDefaultDictionaries(); static RootLexicon loadFromResources(String... resourcePaths); static RootLexic...
### Question: DoubleArrays { public static boolean arrayEqualsInRange(double[] d1, double[] d2, double range) { validateArrays(d1, d2); for (int i = 0; i < d1.length; i++) { if (Math.abs(d1[i] - d2[i]) > range) { return false; } } return true; } private DoubleArrays(); static boolean inRange(double d1, double d2, doub...
### Question: DoubleArrays { public static boolean arrayEquals(double[] d1, double[] d2) { validateArrays(d1, d2); return Arrays.equals(d1, d2); } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static do...
### Question: DoubleArrays { public static double variance(double[] input) { double sigmaSquare = 0; double mean = mean(input); for (double a : input) { final double meanDiff = a - mean; sigmaSquare += meanDiff * meanDiff; } return sigmaSquare / (input.length - 1); } private DoubleArrays(); static boolean inRange(doub...
### Question: DoubleArrays { public static boolean containsNaN(double[] a) { for (double v : a) { if (Double.isNaN(v)) { return true; } } return false; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); st...
### Question: DoubleArrays { public static void floorInPlace(double[] var, double minValue) { for (int k = 0; k < var.length; k++) { if (var[k] < minValue) { var[k] = minValue; } } } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static doub...
### Question: TurkishDictionaryLoader { public static DictionaryItem loadFromString(String dictionaryLine) { String lemma = dictionaryLine; if (dictionaryLine.contains(" ")) { lemma = dictionaryLine.substring(0, dictionaryLine.indexOf(" ")); } return load(dictionaryLine).getMatchingItems(lemma).get(0); } static RootLe...
### Question: DoubleArrays { public static void nonZeroFloorInPlace(double[] data, double floor) { for (int i = 0; i < data.length; i++) { if (data[i] != 0.0 && data[i] < floor) { data[i] = floor; } } } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[]...
### Question: DoubleArrays { public static void normalizeInPlace(double[] data) { double sum = sum(data); scaleInPlace(data, 1d / sum); } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static double[][] ...
### Question: DoubleArrays { public static void validateArray(double... input) { if (input == null) { throw new IllegalArgumentException("array is null!"); } else if (input.length == 0) { throw new IllegalArgumentException("array is empty!"); } } private DoubleArrays(); static boolean inRange(double d1, double d2, dou...
### Question: BlockTextLoader implements Iterable<TextChunk> { public static BlockTextLoader fromPath(Path corpus, int blockSize) { return new BlockTextLoader(Collections.singletonList(corpus), blockSize); } BlockTextLoader(List<Path> corpusPaths, int blockSize); List<Path> getCorpusPaths(); int getBlockSize(); int pat...
### Question: Histogram implements Iterable<T> { public void remove(T t) { map.remove(t); } Histogram(int initialSize); Histogram(Map<T, Integer> countMap); Histogram(); static Histogram<String> loadFromLines(List<String> lines, char delimiter); static Histogram<String> loadFromLines( List<String> lines, ...
### Question: Histogram implements Iterable<T> { public int add(T t) { return add(t, 1); } Histogram(int initialSize); Histogram(Map<T, Integer> countMap); Histogram(); static Histogram<String> loadFromLines(List<String> lines, char delimiter); static Histogram<String> loadFromLines( List<String> lines, c...
### Question: UIntValueMap extends HashBase<T> implements Iterable<T> { public int incrementByAmount(T key, int amount) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int l = locate(key); if (l < 0) { l = -l - 1; values[l] = amoun...
### Question: IntVector { public void add(int i) { if (size == data.length) { expand(); } data[size] = i; size++; } IntVector(); IntVector(int initialCapacity); IntVector(int[] values); void add(int i); void addAll(int[] arr); void addAll(IntVector vec); int get(int index); void set(int index, int value); void safeSe...
### Question: IntVector { public void addAll(int[] arr) { if (size + arr.length >= data.length) { expand(arr.length); } System.arraycopy(arr, 0, data, size, arr.length); size += arr.length; } IntVector(); IntVector(int initialCapacity); IntVector(int[] values); void add(int i); void addAll(int[] arr); void addAll(Int...
### Question: IntVector { public void trimToSize() { data = Arrays.copyOf(data, size); } IntVector(); IntVector(int initialCapacity); IntVector(int[] values); void add(int i); void addAll(int[] arr); void addAll(IntVector vec); int get(int index); void set(int index, int value); void safeSet(int index, int value); in...
### Question: LongBitVector { public void fill(boolean bitValue) { if (bitValue) { Arrays.fill(words, 0xffffffffffffffffL); int last = (int) (size / 64); words[last] &= cutMasks[(int) (size & mod64Mask)] >>> 1; } else { Arrays.fill(words, 0); } } LongBitVector(); LongBitVector(long initialCapcity); LongBitVector(long...
### Question: UIntMap extends UIntKeyHashBase implements Iterable<T> { public T get(int key) { if (key < 0) { throw new IllegalArgumentException("Key cannot be negative: " + key); } int slot = hash(key) & modulo; while (true) { final int t = keys[slot]; if (t == EMPTY) { return null; } if (t == DELETED) { slot = (slot ...
### Question: UIntMap extends UIntKeyHashBase implements Iterable<T> { public List<T> getValues() { List<T> result = new ArrayList<>(); for (int i = 0; i < keys.length; i++) { int key = keys[i]; if (key >= 0) { result.add(values[i]); } } return result; } UIntMap(); UIntMap(int size); T get(int key); boolean containsKe...
### Question: IntIntMap extends CompactIntMapBase { public int get(int key) { checkKey(key); int slot = firstProbe(key); while (true) { final long entry = entries[slot]; final int t = (int) (entry & 0xFFFF_FFFFL); if (t == key) { return (int) (entry >>> 32); } if (t == EMPTY) { return NO_RESULT; } slot = probe(slot); }...
### Question: IntIntMap extends CompactIntMapBase { public void put(int key, int value) { checkKey(key); expandIfNecessary(); int loc = locate(key); if (loc >= 0) { setValue(loc, value); } else { setKeyValue(-loc - 1, key, value); keyCount++; } } IntIntMap(); IntIntMap(int capacity); void put(int key, int value); void...
### Question: IntValueMap extends HashBase<T> implements Iterable<T> { public int addOrIncrement(T key) { return incrementByAmount(key, 1); } IntValueMap(); IntValueMap(int size); int addOrIncrement(T key); void addOrIncrementAll(Iterable<T> keys); int get(T key); int decrement(T key); int incrementByAmount(T key, int...
### Question: IntValueMap extends HashBase<T> implements Iterable<T> { public void put(T key, int value) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int loc = locate(key); if (loc >= 0) { values[loc] = value; } else { loc = -lo...
### Question: IntValueMap extends HashBase<T> implements Iterable<T> { private void expand() { IntValueMap<T> h = new IntValueMap<>(newSize()); for (int i = 0; i < keys.length; i++) { if (hasValidKey(i)) { h.put(keys[i], values[i]); } } expandCopyParameters(h); this.values = h.values; } IntValueMap(); IntValueMap(int ...
### Question: IntValueMap extends HashBase<T> implements Iterable<T> { public int get(T key) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } int slot = hash(key) & modulo; while (true) { final T t = keys[slot]; if (t == null) { return 0; } if (t == TOMB_STONE) { slot = (slot + 1) & mod...
### Question: IntValueMap extends HashBase<T> implements Iterable<T> { public int[] copyOfValues() { int[] result = new int[keyCount]; int k = 0; for (int i = 0; i < keys.length; i++) { if (hasValidKey(i)) { result[k] = values[i]; k++; } } return result; } IntValueMap(); IntValueMap(int size); int addOrIncrement(T key...
### Question: IntValueMap extends HashBase<T> implements Iterable<T> { public void addOrIncrementAll(Iterable<T> keys) { for (T t : keys) { incrementByAmount(t, 1); } } IntValueMap(); IntValueMap(int size); int addOrIncrement(T key); void addOrIncrementAll(Iterable<T> keys); int get(T key); int decrement(T key); int i...
### Question: FixedBitVector { public boolean safeGet(int n) { check(n); return (words[n >> 5] & setMasks[n & 31]) != 0; } FixedBitVector(int length); boolean get(int n); boolean safeGet(int n); void set(int n); void safeSet(int n); void clear(int n); void safeClear(int n); int numberOfOnes(); int numberOfNewOneBitCoun...
### Question: FixedBitVector { public void safeSet(int n) { check(n); words[n >> 5] |= setMasks[n & 31]; } FixedBitVector(int length); boolean get(int n); boolean safeGet(int n); void set(int n); void safeSet(int n); void clear(int n); void safeClear(int n); int numberOfOnes(); int numberOfNewOneBitCount(FixedBitVector...
### Question: FixedBitVector { public void safeClear(int n) { check(n); words[n >> 5] &= resetMasks[n & 31]; } FixedBitVector(int length); boolean get(int n); boolean safeGet(int n); void set(int n); void safeSet(int n); void clear(int n); void safeClear(int n); int numberOfOnes(); int numberOfNewOneBitCount(FixedBitVe...
### Question: FloatValueMap extends HashBase<T> implements Iterable<T> { public float[] values() { float[] result = new float[size()]; int j = 0; for (int i = 0; i < keys.length; i++) { if (hasValidKey(i)) { result[j++] = values[i]; } } return result; } FloatValueMap(); FloatValueMap(int size); private FloatValueMap(...
### Question: LookupSet extends HashBase<T> implements Iterable<T> { public boolean add(T key) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int loc = locate(key); if (loc >= 0) { return false; } else { loc = -loc - 1; keys[loc] ...
### Question: LookupSet extends HashBase<T> implements Iterable<T> { public T getOrAdd(T key) { if (key == null) { throw new IllegalArgumentException("Key cannot be null."); } if (keyCount + removeCount == threshold) { expand(); } int loc = locate(key); if (loc >= 0) { return keys[loc]; } else { loc = -loc - 1; keys[lo...
### Question: IntFloatMap extends CompactIntMapBase { public float get(int key) { checkKey(key); int slot = firstProbe(key); while (true) { final long entry = entries[slot]; final int t = (int) (entry & 0xFFFF_FFFFL); if (t == key) { return Float.intBitsToFloat((int) (entry >>> 32)); } if (t == EMPTY) { return NO_RESUL...
### Question: IntFloatMap extends CompactIntMapBase { public void put(int key, float value) { checkKey(key); expandIfNecessary(); int loc = locate(key); if (loc >= 0) { setValue(loc, value); } else { setKeyValue(-loc - 1, key, value); keyCount++; } } IntFloatMap(); IntFloatMap(int capacity); void put(int key, float va...
### Question: Trie { public List<T> getAll() { List<T> items = new ArrayList<>(size); List<Node<T>> toWalk = Lists.newArrayList(root); while (toWalk.size() > 0) { List<Node<T>> n = new ArrayList<>(); for (Node<T> tNode : toWalk) { if (tNode.hasItem()) { items.addAll(tNode.items); } if (tNode.children != null && tNode.c...
### Question: Trie { public void remove(String s, T item) { Node node = walkToNode(s); if (node != null && node.hasItem()) { node.items.remove(item); size--; } } void add(String s, T item); void remove(String s, T item); int size(); boolean containsItem(String s, T item); List<T> getItems(String s); List<T> getAll(); ...
### Question: TurkishAlphabet { public boolean isVowel(char c) { return lookup(vowelLookup, c); } private TurkishAlphabet(); String toAscii(String in); String foreignDiacriticsToTurkish(String in); boolean containsAsciiRelated(String s); IntIntMap getTurkishToAsciiMap(); char getAsciiEqual(char c); boolean isAsciiEqua...
### Question: TurkishAlphabet { public int vowelCount(String s) { int result = 0; for (int i = 0; i < s.length(); i++) { if (isVowel(s.charAt(i))) { result++; } } return result; } private TurkishAlphabet(); String toAscii(String in); String foreignDiacriticsToTurkish(String in); boolean containsAsciiRelated(String s);...
### Question: TurkishAlphabet { public char voice(char c) { int res = voicingMap.get(c); return res == IntIntMap.NO_RESULT ? c : (char) res; } private TurkishAlphabet(); String toAscii(String in); String foreignDiacriticsToTurkish(String in); boolean containsAsciiRelated(String s); IntIntMap getTurkishToAsciiMap(); ch...
### Question: TurkishAlphabet { public char devoice(char c) { int res = devoicingMap.get(c); return res == IntIntMap.NO_RESULT ? c : (char) res; } private TurkishAlphabet(); String toAscii(String in); String foreignDiacriticsToTurkish(String in); boolean containsAsciiRelated(String s); IntIntMap getTurkishToAsciiMap()...
### Question: TurkishAlphabet { public char normalizeCircumflex(char c) { int res = circumflexMap.get(c); return res == IntIntMap.NO_RESULT ? c : (char) res; } private TurkishAlphabet(); String toAscii(String in); String foreignDiacriticsToTurkish(String in); boolean containsAsciiRelated(String s); IntIntMap getTurkis...
### Question: TurkishAlphabet { public String toAscii(String in) { StringBuilder sb = new StringBuilder(in.length()); for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); int res = turkishToAsciiMap.get(c); char map = res == IntIntMap.NO_RESULT ? c : (char) res; sb.append(map); } return sb.toString(); } priva...
### Question: TurkishAlphabet { public boolean equalsIgnoreDiacritics(String s1, String s2) { if (s1 == null || s2 == null) { return false; } if (s1.length() != s2.length()) { return false; } for (int i = 0; i < s1.length(); i++) { char c1 = s1.charAt(i); char c2 = s2.charAt(i); if (!isAsciiEqual(c1, c2)) { return fals...
### Question: TurkishAlphabet { public boolean checkVowelHarmonyA(CharSequence source, CharSequence target) { TurkicLetter sourceLastVowel = getLastVowel(source); TurkicLetter targetFirstVowel = getLastVowel(target); return checkVowelHarmonyA(sourceLastVowel, targetFirstVowel); } private TurkishAlphabet(); String toAs...
### Question: TurkishAlphabet { public boolean checkVowelHarmonyI(CharSequence source, CharSequence target) { TurkicLetter sourceLastVowel = getLastVowel(source); TurkicLetter targetFirstVowel = getLastVowel(target); return checkVowelHarmonyI(sourceLastVowel, targetFirstVowel); } private TurkishAlphabet(); String toAs...
### Question: TurkishAlphabet { public boolean startsWithIgnoreDiacritics(String s1, String s2) { if (s1 == null || s2 == null) { return false; } if (s1.length() < s2.length()) { return false; } for (int i = 0; i < s2.length(); i++) { char c1 = s1.charAt(i); char c2 = s2.charAt(i); if (!isAsciiEqual(c1, c2)) { return f...
### Question: LmVocabulary { public boolean containsAll(int... indexes) { for (int index : indexes) { if (!contains(index)) { return false; } } return true; } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(RandomAccessFile raf); private LmVocabulary(DataInputStream di...
### Question: LmVocabulary { public static LmVocabulary loadFromBinary(File binaryVocabularyFile) throws IOException { try (DataInputStream dis = new DataInputStream( new BufferedInputStream(new FileInputStream(binaryVocabularyFile)))) { return new LmVocabulary(dis); } } LmVocabulary(String... vocabulary); LmVocabular...
### Question: LmVocabulary { public static LmVocabulary loadFromUtf8File(File utfVocabularyFile) throws IOException { return new LmVocabulary(SimpleTextReader.trimmingUTF8Reader(utfVocabularyFile).asStringList()); } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(Random...
### Question: LmVocabulary { public static LmVocabulary loadFromDataInputStream(DataInputStream dis) throws IOException { return new LmVocabulary(dis); } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(RandomAccessFile raf); private LmVocabulary(DataInputStream dis); s...
### Question: LmVocabulary { public static LmVocabulary loadFromRandomAccessFile(RandomAccessFile raf) throws IOException { return new LmVocabulary(raf); } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(RandomAccessFile raf); private LmVocabulary(DataInputStream dis);...
### Question: LmVocabulary { public boolean contains(int index) { return index >= 0 && index < vocabulary.size(); } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(RandomAccessFile raf); private LmVocabulary(DataInputStream dis); static LmVocabulary loadFromBinary(File...
### Question: LmVocabulary { public long encodeTrigram(int g0, int g1, int g2) { long encoded = g2; encoded = (encoded << 21) | g1; return (encoded << 21) | g0; } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(RandomAccessFile raf); private LmVocabulary(DataInputStrea...
### Question: LmVocabulary { public String[] toWords(int... indexes) { String[] words = new String[indexes.length]; int k = 0; for (int index : indexes) { if (contains(index)) { words[k++] = vocabulary.get(index); } else { Log.warn("Out of bounds word index is used:" + index); words[k++] = unknownWord; } } return words...
### Question: LmVocabulary { public static Builder builder() { return new Builder(); } LmVocabulary(String... vocabulary); LmVocabulary(List<String> vocabulary); private LmVocabulary(RandomAccessFile raf); private LmVocabulary(DataInputStream dis); static LmVocabulary loadFromBinary(File binaryVocabularyFile); stati...
### Question: SmoothLm extends BaseLanguageModel implements NgramLanguageModel { @Override public int getOrder() { return order; } private SmoothLm( DataInputStream dis, float logBase, float unigramWeight, float unknownBackoffPenalty, boolean useStupidBackoff, float stupidBackoffAlp...
### Question: SmoothLm extends BaseLanguageModel implements NgramLanguageModel { @Override public LmVocabulary getVocabulary() { return vocabulary; } private SmoothLm( DataInputStream dis, float logBase, float unigramWeight, float unknownBackoffPenalty, boolean useStupidBackoff, flo...
### Question: SmoothLm extends BaseLanguageModel implements NgramLanguageModel { public String explain(int... wordIndexes) { return explain(new Explanation(), wordIndexes).sb.toString(); } private SmoothLm( DataInputStream dis, float logBase, float unigramWeight, float unknownBackoffPenalty, ...
### Question: NerDataSet { public static NerDataSet load(Path path, AnnotationStyle style) throws IOException { switch (style) { case BRACKET: return loadBracketStyle(path); case ENAMEX: return loadEnamexStyle(path); case OPEN_NLP: return loadOpenNlpStyle(path); } throw new IOException(String.format("Cannot load data f...
### Question: TurkishTokenizer { public static Builder builder() { return new Builder(); } private TurkishTokenizer(long acceptedTypeBits); static Builder builder(); boolean isTypeAccepted(Token.Type i); boolean isTypeIgnored(Token.Type i); List<Token> tokenize(File file); List<Token> tokenize(String input); List<Toke...
### Question: TurkishTokenizer { public List<Token> tokenize(File file) throws IOException { return getAllTokens(lexerInstance(CharStreams.fromPath(file.toPath()))); } private TurkishTokenizer(long acceptedTypeBits); static Builder builder(); boolean isTypeAccepted(Token.Type i); boolean isTypeIgnored(Token.Type i); L...
### Question: Span { public String getSubstring(String input) { return input.substring(start, end); } Span(int start, int end); int length(); int middleValue(); Span copy(int offset); String getSubstring(String input); boolean inSpan(int i); final int start; final int end; }### Answer: @Test public void substringTest()...
### Question: Span { public int length() { return end - start; } Span(int start, int end); int length(); int middleValue(); Span copy(int offset); String getSubstring(String input); boolean inSpan(int i); final int start; final int end; }### Answer: @Test public void lengthTest() { Assert.assertEquals(0, new Span(0, 0)...
### Question: TurkishSentenceExtractor extends PerceptronSegmenter { public List<String> fromParagraph(String paragraph) { List<Span> spans = extractToSpans(paragraph); List<String> sentences = new ArrayList<>(spans.size()); for (Span span : spans) { String sentence = span.getSubstring(paragraph).trim(); if (sentence.l...
### Question: TurkishSentenceExtractor extends PerceptronSegmenter { public static Builder builder() { return new Builder(); } private TurkishSentenceExtractor(FloatValueMap<String> weights); private TurkishSentenceExtractor(FloatValueMap<String> weights, boolean doNotSplitInDoubleQuotes); static Builder builde...
### Question: TurkishDictionaryLoader { public static RootLexicon loadDefaultDictionaries() throws IOException { return loadFromResources(DEFAULT_DICTIONARY_RESOURCES); } static RootLexicon loadDefaultDictionaries(); static RootLexicon loadFromResources(String... resourcePaths); static RootLexicon loadFromResources(Co...
### Question: TurkishNumbers { public static String convertToString(long input) { if (input == 0) { return "sıfır"; } if (input < MIN_NUMBER || input > MAX_NUMBER) { throw new IllegalArgumentException("number is out of bounds:" + input); } String result = ""; long girisPos = Math.abs(input); int sayac = 0; while (giris...
### Question: TurkishNumbers { public static String convertNumberToString(String input) { if (input.startsWith("+")) { input = input.substring(1); } List<String> sb = new ArrayList<>(); int i; for (i = 0; i < input.length(); i++) { if (input.charAt(i) == '0') { sb.add("sıfır"); } else { break; } } String rest = input.s...
### Question: TurkishNumbers { public static String convertOrdinalNumberString(String input) { String numberPart = input; if (input.endsWith(".")) { numberPart = Strings.subStringUntilFirst(input, "."); } long number = Long.parseLong(numberPart); String text = convertToString(number); String[] words = text.trim().split...
### Question: TurkishNumbers { public static List<String> separateNumbers(String s) { return Regexps.allMatches(NUMBER_SEPARATION, s); } static Map<String, String> getOrdinalMap(); static String convertToString(long input); static String convertNumberToString(String input); static long singleWordNumberValue(String wor...
### Question: TurkishNumbers { public static List<String> seperateConnectedNumbers(List<String> inputSequence) { List<String> output = new ArrayList<>(inputSequence.size()); for (String s : inputSequence) { if (stringToNumber.containsKey(s)) { output.add(valueOf(stringToNumber.get(s))); continue; } output.addAll(sepera...
### Question: TurkishNumbers { public static long convertToNumber(String... words) { return textToNumber.convert(words); } static Map<String, String> getOrdinalMap(); static String convertToString(long input); static String convertNumberToString(String input); static long singleWordNumberValue(String word); static Lis...
### Question: TurkishNumbers { public static int romanToDecimal(String s) { if (s == null || s.isEmpty() || !romanNumeralPattern.matcher(s).matches()) { return -1; } final Matcher matcher = Pattern.compile("M|CM|D|CD|C|XC|L|XL|X|IX|V|IV|I").matcher(s); final int[] decimalValues = {1000, 900, 500, 400, 100, 90, 50, 40, ...
### Question: SingleAnalysis { public PrimaryPos getPos() { return getGroup(groupCount() - 1).getPos(); } SingleAnalysis( DictionaryItem item, List<MorphemeData> morphemeDataList, int[] groupBoundaries); static SingleAnalysis unknown(String input); static SingleAnalysis dummy(String input, DictionaryI...
### Question: SingleAnalysis { public List<String> getStems() { List<String> stems = Lists.newArrayListWithCapacity(2); stems.add(getStem()); String previousStem = getGroup(0).surfaceForm(); if (groupBoundaries.length > 1) { for (int i = 1; i < groupBoundaries.length; i++) { MorphemeGroup ig = getGroup(i); MorphemeData...
### Question: SingleAnalysis { public List<String> getLemmas() { List<String> lemmas = Lists.newArrayListWithCapacity(2); lemmas.add(item.root); String previousStem = getGroup(0).surfaceForm(); if (!previousStem.equals(item.root)) { if (previousStem.endsWith("ğ")) { previousStem = previousStem.substring(0, previousStem...
### Question: SingleAnalysis { public String formatLong() { return AnalysisFormatters.DEFAULT.format(this); } SingleAnalysis( DictionaryItem item, List<MorphemeData> morphemeDataList, int[] groupBoundaries); static SingleAnalysis unknown(String input); static SingleAnalysis dummy(String input, Diction...
### Question: WordAnalysisSurfaceFormatter { public String format(SingleAnalysis analysis, String apostrophe) { DictionaryItem item = analysis.getDictionaryItem(); String ending = analysis.getEnding(); if (apostrophe != null || apostropheRequired(analysis)) { if (apostrophe == null) { apostrophe = "'"; } return ending....
### Question: WordAnalysisSurfaceFormatter { public String formatToCase(SingleAnalysis analysis, CaseType type, String apostrophe) { String formatted = format(analysis, apostrophe); Locale locale = analysis.getDictionaryItem().hasAttribute(RootAttribute.LocaleEn) ? Locale.ENGLISH : Turkish.LOCALE; switch (type) { case ...
### Question: TurkishSpellChecker { public List<String> suggestForWord(String word, NgramLanguageModel lm) { List<String> unRanked = getUnrankedSuggestions(word); return rankWithUnigramProbability(unRanked, lm); } TurkishSpellChecker(TurkishMorphology morphology); TurkishSpellChecker(TurkishMorphology morphology, Char...
### Question: WordAnalysisSurfaceFormatter { public CaseType guessCase(String input) { boolean firstLetterUpperCase = false; int lowerCaseCount = 0; int upperCaseCount = 0; int letterCount = 0; for (int i = 0; i < input.length(); i++) { char c = input.charAt(i); if (!Character.isAlphabetic(c)) { continue; } if (i == 0)...
### Question: RuleBasedDisambiguator { public ResultSentence disambiguate(String sentence) { List<WordAnalysis> ambiguous = analyzer.analyzeSentence(sentence); ResultSentence s = new ResultSentence(sentence, ambiguous); s.makeDecisions(rules); return s; } RuleBasedDisambiguator(TurkishMorphology analyzer, Rules rules);...
### Question: WebDocument { public static WebDocument fromText(String meta, List<String> pageData) { String url = Regexps.firstMatch(urlPattern, meta, 2); String id = url.replaceAll("http: String source = Regexps.firstMatch(sourcePattern, meta, 2); String crawlDate = Regexps.firstMatch(crawlDatePattern, meta, 2); Strin...