src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
FloatArrays { public static float dotProduct(float[] a1, float[] a2) { return sum(multiply(a1, a2)); } 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[][] input); static float[] conv...
@Test public void testDotProduct() { float[] da = {1, 2, 0, -1, -3}; float[] da2 = {0.5f, -2, 30, 1, -30}; Assert.assertTrue(inDelta(FloatArrays.dotProduct(da, da2), 85.5f)); }
FloatArrays { public static float[] appendZeros(float[] darray, int zeroAmountToAppend) { if (zeroAmountToAppend < 0) { throw new IllegalArgumentException( "Cannot append negative amount of zeros. Amount:" + zeroAmountToAppend); } return Arrays.copyOf(darray, darray.length + zeroAmountToAppend); } private FloatArrays(...
@Test public void testAppendZeros() { float[] da = {1, 2, 0, -1, -3}; float[] da2 = {1, 2, 0, -1, -3, 0, 0, 0, 0, 0, 0}; Assert.assertTrue(inDelta(FloatArrays.appendZeros(da, 6), da2)); Assert.assertTrue(inDelta(FloatArrays.appendZeros(da2, 0), da2)); } @Test(expected = IllegalArgumentException.class) public void testA...
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 = stemTransitions.getPr...
@Test public void testGeneration2() { WordGenerator wordGenerator = new WordGenerator(getMorphotactics("elma")); List<String> morphemes = Lists.newArrayList("Noun", "A3pl", "P1pl"); List<Result> results = wordGenerator.generate( "elma", morphemes ); Assert.assertTrue(results.size() > 0); Assert.assertEquals("elmalarımı...
FloatArrays { public static float[] square(float... input) { float[] res = new float[input.length]; for (int i = 0; i < input.length; i++) { res[i] = input[i] * input[i]; } return res; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[...
@Test public void testSquare() { float[] da = {1, 2, 0, -1, -3}; Assert.assertTrue(inDelta(FloatArrays.square(da), new float[]{1, 4, 0, 1, 9})); }
FloatArrays { public static float squaredSum(float[] array) { float result = 0; validateArray(array); for (float a : array) { result += a * a; } return result; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input); s...
@Test public void testSquaredSum() { float[] da = {1, 2, 0, -1, -3}; Assert.assertTrue(inDelta(FloatArrays.squaredSum(da), 15)); float[] da2 = {0, 1, 1, -2, 1}; Assert.assertTrue(inDelta(FloatArrays.squaredSumOfDifferences(da, da2), 20)); Assert.assertTrue(inDelta(FloatArrays.absoluteDifference(da, da2), new float[]{1,...
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[][] input); static ...
@Test public void testMean() { float[] da = {1, 2, 0, -1, -3}; Assert.assertTrue(inDelta(FloatArrays.mean(da), -1f / 5f)); }
FloatArrays { public static boolean inRange(float d1, float d2, float range) { return Math.abs(d1 - d2) <= range; } 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[][] input); static...
@Test public void testInRange() { float d = 3; float d2 = 2.5f; float d3 = 7; Assert.assertTrue(FloatArrays.inRange(d, d2, 1)); Assert.assertFalse(FloatArrays.inRange(d2, d3, 4)); Assert.assertTrue(FloatArrays.inRange(d, d2, 0.5f)); }
FloatArrays { public static float[] reverse(float[] input) { float[] result = new float[input.length]; for (int i = 0; i < input.length; i++) { result[input.length - i - 1] = input[i]; } return result; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] inpu...
@Test public void testReverse() { float[] da = {1, 3, 7, 2.5f, 0}; float[] da2 = FloatArrays.reverse(FloatArrays.reverse(da)); Assert.assertNotNull(da2); Assert.assertEquals(da.length, da2.length); Assert.assertTrue(inDelta(da, da2)); }
FloatArrays { public static float[] convert(int[] input) { float[] data = new float[input.length]; int k = 0; for (int i : input) { data[k++] = i; } return data; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input);...
@Test public void testConvertInt() { int[] ia = {1, 3, -1, 0, 9, 12}; float[] da2 = {1, 3, -1, 0, 9.0f, 12.0f}; float[] da = FloatArrays.convert(ia); Assert.assertNotNull(da); Assert.assertTrue(inDelta(da, da2)); } @Test public void testConvert2f() { int[][] ia = {{1, 2}, {4, 3}, {-1, 5}}; float[][] da = {{1, 2}, {4, 3...
FloatArrays { public static boolean arrayEqualsInRange(float[] d1, float[] d2, float 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 FloatArrays(); static boolean inRange(float d1, float d2, float range); static floa...
@Test public void testArrayEqualsInRange() { float[] da = {0, 3.5f, 7, -2, 19}; float[] da2 = {0, 4.5f, 4, 2, -18}; Assert.assertTrue(FloatArrays.arrayEqualsInRange(da, da2, 37)); Assert.assertFalse(FloatArrays.arrayEqualsInRange(da, da2, 15)); Assert.assertTrue(FloatArrays.arrayEqualsInRange(da, da2, 45)); }
FloatArrays { public static boolean arrayEquals(float[] d1, float[] d2) { validateArrays(d1, d2); return Arrays.equals(d1, d2); } 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[][] ...
@Test public void testArrayEquals() { float[] da = {-1, 0, 3.4f, 7}; float[] da2 = {-1, 0.0f, 3.4f, 7}; float[] da3 = {7, 9.0f, 12.3f, -5.6f}; Assert.assertTrue(FloatArrays.arrayEquals(da, da2)); Assert.assertFalse(FloatArrays.arrayEquals(da2, da3)); }
FloatArrays { public static float[] multiply(float[] a1, float[] a2) { validateArrays(a1, a2); float[] mul = new float[a1.length]; for (int i = 0; i < a1.length; i++) { mul[i] = a1[i] * a2[i]; } return mul; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[]...
@Test public void testMultiply() { float[] da = {-1, 1.3f, 8.2f, 10, 90}; float[] da2 = {-1, 3, 2, 2, -1}; Assert.assertTrue(inDelta(FloatArrays.multiply(da, da2), new float[]{1, 3.9f, 16.4f, 20, -90})); FloatArrays.multiplyToFirst(da, da2); Assert.assertTrue(inDelta(da, new float[]{1, 3.9f, 16.4f, 20, -90})); }
FloatArrays { public static float[] scale(float[] a1, float b) { validateArray(a1); float[] mul = new float[a1.length]; for (int i = 0; i < a1.length; i++) { mul[i] = a1[i] * b; } return mul; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static...
@Test public void testScale() { float[] da = {1, -1, 3.1f, 0.0f, 0}; Assert.assertTrue(inDelta(FloatArrays.scale(da, 0), new float[]{0, 0, 0, 0, 0})); Assert.assertTrue(inDelta(FloatArrays.scale(da, -1), new float[]{-1, 1, -3.1f, 0, 0.0f})); Assert.assertTrue(inDelta(FloatArrays.scale(da, 4), new float[]{4, -4, 12.4f, ...
FloatArrays { public static float[] absoluteDifference(float[] a, float[] b) { validateArrays(a, b); float[] diff = new float[a.length]; for (int i = 0; i < a.length; i++) { diff[i] += abs(a[i] - b[i]); } return diff; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reve...
@Test public void testAbsoluteDifference() { float[] da = {1, 2, 4.5f, -2, 4}; float[] da2 = {1, 1, 2.5f, 5, -15.2f}; Assert.assertTrue( inDelta(FloatArrays.absoluteDifference(da, da2), new float[]{0, 1, 2, 7, 19.2f})); Assert.assertEquals(FloatArrays.absoluteSumOfDifferences(da, da2), 29.2f, 0.0001); }
FloatArrays { public static float variance(float[] input) { float sigmaSquare = 0; float mean = mean(input); for (float a : input) { float meanDiff = a - mean; sigmaSquare += meanDiff * meanDiff; } return sigmaSquare / (input.length - 1); } private FloatArrays(); static boolean inRange(float d1, float d2, float range)...
@Test public void testVariance() { float[] da = {0, 2, 4}; Assert.assertEquals(FloatArrays.variance(da), 4f, 0.0001); Assert.assertEquals(FloatArrays.standardDeviation(da), 2f, 0.0001); }
FloatArrays { public static boolean containsNaN(float[] a) { for (float v : a) { if (Float.isNaN(v)) { return true; } } return false; } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input); static float[][] convert(in...
@Test public void testContainsNaN() { float[] da = {-1, 1, 3, 5, 7, 9, Float.NaN}; Assert.assertTrue(FloatArrays.containsNaN(da)); float[] da2 = {-1, 1, 3, 5, 7, 9}; Assert.assertFalse(FloatArrays.containsNaN(da2)); }
FloatArrays { public static void floorInPlace(float[] var, float minValue) { for (int k = 0; k < var.length; k++) { if (var[k] < minValue) { var[k] = minValue; } } } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input...
@Test public void testFloorInPlace() { float[] da = {0, -7, 2, 1.1123f, -10, -22, 56}; FloatArrays.floorInPlace(da, -7); Assert.assertTrue(inDelta(da, new float[]{0, -7, 2, 1.1123f, -7, -7, 56})); }
FloatArrays { public static void nonZeroFloorInPlace(float[] data, float floor) { for (int i = 0; i < data.length; i++) { if (data[i] != 0.0f && data[i] < floor) { data[i] = floor; } } } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[...
@Test public void testNonZeroFloorInPlace() { float[] da = {0, -7, 2, 1.1123f, -10, -22, 56}; FloatArrays.nonZeroFloorInPlace(da, 3); Assert.assertTrue(inDelta(da, new float[]{0, 3, 3, 3, 3, 3, 56})); }
FloatArrays { public static void normalizeInPlace(float[] data) { float sum = sum(data); scaleInPlace(data, 1f / sum); } 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[][] input); s...
@Test public void testNormalizeInPlace() { float[] da = {1, 5.6f, 2.4f, -1, -3.0f, 5}; FloatArrays.normalizeInPlace(da); Assert.assertTrue(inDelta(da, new float[]{0.1f, 0.56f, 0.24f, -0.1f, -0.3f, 0.5f})); }
FloatArrays { public static void addToAll(float[] data, float valueToAdd) { validateArray(data); for (int i = 0; i < data.length; i++) { data[i] += valueToAdd; } } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static float[] reverse(float[] input); static float[] convert(int[] input);...
@Test public void testAddToAll() { float[] da = {1, 2, 0, -1, -3}; float[] expected = {2, 3, 1, 0, -2}; FloatArrays.addToAll(da, 1); Assert.assertTrue(Arrays.equals(expected, da)); }
FloatArrays { public static void validateArray(float... input) { if (input == null) { throw new IllegalArgumentException("array is null!"); } else if (input.length == 0) { throw new IllegalArgumentException("array is empty!"); } } private FloatArrays(); static boolean inRange(float d1, float d2, float range); static f...
@Test public void testValidateArray() { float[] da = null; try { FloatArrays.validateArray(da); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } da = new float[0]; try { FloatArrays.validateArray(da); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } } @Test(expected = IllegalArgumentEx...
FloatArrays { public static void validateArrays(float[] a1, float[] a2) { if (a1 == null) { throw new NullPointerException("first array is null!"); } if (a2 == null) { throw new NullPointerException("second array is null!"); } if (a1.length != a2.length) { throw new IllegalArgumentException("Array sizes must be equal. ...
@Test public void testValidateArrays() { float[] da1 = {1, 2, 3}; float[] da2 = null; try { FloatArrays.validateArrays(da1, da2); } catch (NullPointerException e) { Assert.assertTrue(true); } float[] da3 = {5, 6, 2.33f, 2}; try { FloatArrays.validateArrays(da1, da3); } catch (IllegalArgumentException e) { Assert.assert...
FloatArrays { public static float[] normalize16bitLittleEndian(byte[] bytez) { return normalize16bitLittleEndian(bytez, bytez.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(i...
@Test public void testNormalize16bitLittleEndian() { byte[] ba = {0x10, 0x71, 0x18, 0x54}; float[] da = FloatArrays.normalize16bitLittleEndian(ba); Assert.assertEquals(da[0] * Short.MAX_VALUE, 28944f, 0.0001); Assert.assertEquals(da[1] * Short.MAX_VALUE, 21528f, 0.0001); byte[] ba2 = FloatArrays.denormalize16BitLittleE...
FloatArrays { public static int[] toUnsignedInteger(float[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] arr = new int[input.length]; float divider = (float) ((double) max / 2.0); for (int i = 0; i < input.length; i++) { float d = i...
@Test public void testToUnsignedInteger() { float[] da = {0.2f, -0.4f, 0.6f}; int[] ia = FloatArrays.toUnsignedInteger(da, 6); Assert.assertEquals((int) (0.2f * 3.0f), ia[0]); Assert.assertEquals((int) (-0.4f * 3.0f), ia[1]); }
FloatArrays { public static String format(float... input) { return format(10, 3, " ", input); } 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[][] input); static float[] convert(dou...
@Test public void testFormat() { float[] da = {0.2f, -0.45f, 0.6f}; Assert.assertEquals("0.2 -0.4 0.6", FloatArrays.format(1, " ", da)); Assert.assertEquals("0.20 -0.45 0.60", FloatArrays.format(2, " ", da)); Assert.assertEquals("0.20, -0.45, 0.60", FloatArrays.format(2, ", ", da)); Assert.assertEquals("0.20-0.450.60",...
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[][] convert(int[...
@Test public void testSum() { double[] da = {1, 2, 0, -1, -3}; double[] da2 = {0.5, -2, 30, 1, -30}; Assert.assertTrue(inDelta(DoubleArrays.sum(da), -1)); Assert.assertTrue(inDelta(DoubleArrays.sum(da, da2), new double[]{1.5, 0, 30, 0, -33})); DoubleArrays.addToFirst(da, da2); Assert.assertTrue(inDelta(da, new double[]...
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); static double[] re...
@Test public void addToFirstScaledTest() { double[] da1 = {1, 2, 0, -1, -30}; double[] da2 = {-0.5, -1, 0, 0.5, 15}; DoubleArrays.addToFirstScaled(da1, da2, 2); Assert.assertEquals(DoubleArrays.max(da1), 0d, 0.0001); Assert.assertEquals(DoubleArrays.min(da1), 0d, 0.0001); }
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[][] input); static ...
@Test public void testDotProduct() { double[] da = {1, 2, 0, -1, -3}; double[] da2 = {0.5, -2, 30, 1, -30}; Assert.assertTrue(inDelta(DoubleArrays.dotProduct(da, da2), 85.5)); }
DoubleArrays { public static double[] appendZeros(double[] darray, int zeroAmountToAppend) { if (zeroAmountToAppend < 0) { throw new IllegalArgumentException( "Cannot append negative amount of zeros. Amount:" + zeroAmountToAppend); } return Arrays.copyOf(darray, darray.length + zeroAmountToAppend); } private DoubleArr...
@Test public void testAppendZeros() { double[] da = {1, 2, 0, -1, -3}; double[] da2 = {1, 2, 0, -1, -3, 0, 0, 0, 0, 0, 0}; Assert.assertTrue(inDelta(DoubleArrays.appendZeros(da, 6), da2)); Assert.assertTrue(inDelta(DoubleArrays.appendZeros(da2, 0), da2)); } @Test(expected = IllegalArgumentException.class) public void t...
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(double[] input); st...
@Test public void testSquare() { double[] da = {1, 2, 0, -1, -3}; Assert.assertTrue(inDelta(DoubleArrays.square(da), new double[]{1, 4, 0, 1, 9})); }
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[] convert(int...
@Test public void testSquaredSum() { double[] da = {1, 2, 0, -1, -3}; Assert.assertTrue(inDelta(DoubleArrays.squaredSum(da), 15)); double[] da2 = {0, 1, 1, -2, 1}; Assert.assertTrue(inDelta(DoubleArrays.squaredSumOfDifferences(da, da2), 20)); Assert .assertTrue(inDelta(DoubleArrays.absoluteDifference(da, da2), new doub...
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[] convert(int...
@Test public void testAddToAll() { double[] da = {1, 2, 0, -1, -3}; double[] expected = {2, 3, 1, 0, -2}; DoubleArrays.addToAll(da, 1); Assert.assertTrue(Arrays.equals(expected, da)); }
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[][] convert(int[][] inpu...
@Test public void testMean() { double[] da = {1, 2, 0, -1, -3}; Assert.assertTrue(inDelta(DoubleArrays.mean(da), -1d / 5d)); }
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[][] convert(int[][] in...
@Test public void testInRange() { double d = 3; double d2 = 2.5; double d3 = 7; Assert.assertTrue(DoubleArrays.inRange(d, d2, 1)); Assert.assertFalse(DoubleArrays.inRange(d2, d3, 4)); Assert.assertTrue(DoubleArrays.inRange(d, d2, 0.5)); }
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 double[] reverse(do...
@Test public void testReverse() { double[] da = {1, 3, 7, 2.5, 0}; double[] da2 = DoubleArrays.reverse(DoubleArrays.reverse(da)); Assert.assertNotNull(da2); Assert.assertEquals(da.length, da2.length); Assert.assertTrue(inDelta(da, da2)); }
DoubleArrays { public static double[] convert(int[] input) { double[] data = new double[input.length]; int k = 0; for (int i : input) { data[k++] = i; } return data; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(in...
@Test public void testConvertInt() { int[] ia = {1, 3, -1, 0, 9, 12}; double[] da2 = {1, 3, -1, 0, 9.0, 12.0}; double[] da = DoubleArrays.convert(ia); Assert.assertNotNull(da); Assert.assertTrue(inDelta(da, da2)); } @Test public void testConvert2d() { int[][] ia = {{1, 2}, {4, 3}, {-1, 5}}; double[][] da = {{1, 2}, {4,...
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 RootLexicon loadFromRes...
@Test public void loadNounsFromFileTest() throws IOException { RootLexicon items = TurkishDictionaryLoader .load(new File(Resources.getResource("test-lexicon-nouns.txt").getFile())); Assert.assertFalse(items.isEmpty()); for (DictionaryItem item : items) { Assert.assertSame(item.primaryPos, Noun); } } @Test public void ...
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, double range); sta...
@Test public void testArrayEqualsInRange() { double[] da = {0, 3.5, 7, -2, 19}; double[] da2 = {0, 4.5, 4, 2, -18}; Assert.assertTrue(DoubleArrays.arrayEqualsInRange(da, da2, 37)); Assert.assertFalse(DoubleArrays.arrayEqualsInRange(da, da2, 15)); Assert.assertTrue(DoubleArrays.arrayEqualsInRange(da, da2, 45)); }
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 double[][] conve...
@Test public void testArrayEquals() { double[] da = {-1, 0, 3.4, 7}; double[] da2 = {-1, 0.0, 3.4, 7}; double[] da3 = {7, 9.0, 12.3, -5.6}; Assert.assertTrue(DoubleArrays.arrayEquals(da, da2)); Assert.assertFalse(DoubleArrays.arrayEquals(da2, da3)); }
DoubleArrays { public static double[] multiply(double[] a1, double[] a2) { validateArrays(a1, a2); double[] mul = new double[a1.length]; for (int i = 0; i < a1.length; i++) { mul[i] = a1[i] * a2[i]; } return mul; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reve...
@Test public void testMultiply() { double[] da = {-1, 1.3, 8.2, 10, 90}; double[] da2 = {-1, 3, 2, 2, -1}; Assert.assertTrue(inDelta(DoubleArrays.multiply(da, da2), new double[]{1, 3.9, 16.4, 20, -90})); DoubleArrays.multiplyToFirst(da, da2); Assert.assertTrue(inDelta(da, new double[]{1, 3.9, 16.4, 20, -90})); }
DoubleArrays { public static double[] scale(double[] a1, double b) { validateArray(a1); double[] mul = new double[a1.length]; for (int i = 0; i < a1.length; i++) { mul[i] = a1[i] * b; } return mul; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] in...
@Test public void testScale() { double[] da = {1, -1, 3.1, 0.0, 0}; Assert.assertTrue(inDelta(DoubleArrays.scale(da, 0), new double[]{0, 0, 0, 0, 0})); Assert.assertTrue(inDelta(DoubleArrays.scale(da, -1), new double[]{-1, 1, -3.1, 0, 0.0})); Assert.assertTrue(inDelta(DoubleArrays.scale(da, 4), new double[]{4, -4, 12.4...
DoubleArrays { public static double[] absoluteDifference(double[] a, double[] b) { validateArrays(a, b); double[] diff = new double[a.length]; for (int i = 0; i < a.length; i++) { diff[i] += abs(a[i] - b[i]); } return diff; } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static do...
@Test public void testAbsoluteDifference() { double[] da = {1, 2, 4.5, -2, 4}; double[] da2 = {1, 1, 2.5, 5, -15.2}; Assert.assertTrue( inDelta(DoubleArrays.absoluteDifference(da, da2), new double[]{0, 1, 2, 7, 19.2})); Assert.assertEquals(DoubleArrays.absoluteSumOfDifferences(da, da2), 29.2, 0.0001); }
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(double d1, double ...
@Test public void testVariance() { double[] da = {0, 2, 4}; Assert.assertEquals(DoubleArrays.variance(da), 4d, 0.0001); Assert.assertEquals(DoubleArrays.standardDeviation(da), 2d, 0.0001); }
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); static double[][...
@Test public void testContainsNaN() { double[] da = {-1, 1, 3, 5, 7, 9, Double.NaN}; Assert.assertTrue(DoubleArrays.containsNaN(da)); double[] da2 = {-1, 1, 3, 5, 7, 9}; Assert.assertFalse(DoubleArrays.containsNaN(da2)); }
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 double[] convert(i...
@Test public void testFloorInPlace() { double[] da = {0, -7, 2, 1.1123, -10, -22, 56}; DoubleArrays.floorInPlace(da, -7); Assert.assertTrue(inDelta(da, new double[]{0, -7, 2, 1.1123, -7, -7, 56})); }
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 RootLexicon loadDefa...
@Test public void voicingInferenceTest() { DictionaryItem item = TurkishDictionaryLoader.loadFromString("aort [A:NoVoicing]"); Assert.assertEquals("aort", item.root); Assert.assertEquals(Noun, item.primaryPos); Assert.assertTrue(item.hasAttribute(RootAttribute.NoVoicing)); Assert.assertFalse(item.hasAttribute(RootAttri...
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[] input); stati...
@Test public void testNonZeroFloorInPlace() { double[] da = {0, -7, 2, 1.1123, -10, -22, 56}; DoubleArrays.nonZeroFloorInPlace(da, 3); Assert.assertTrue(inDelta(da, new double[]{0, 3, 3, 3, 3, 3, 56})); }
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[][] convert(int[][...
@Test public void testNormalizeInPlace() { double[] da = {1, 5.6, 2.4, -1, -3.0, 5}; DoubleArrays.normalizeInPlace(da); Assert.assertTrue(inDelta(da, new double[]{0.1, 0.56, 0.24, -0.1, -0.3, 0.5})); }
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, double range); st...
@Test public void testValidateArray() { double[] da = null; try { DoubleArrays.validateArray(da); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } da = new double[0]; try { DoubleArrays.validateArray(da); } catch (IllegalArgumentException e) { Assert.assertTrue(true); } } @Test(expected = IllegalArgume...
DoubleArrays { public static void validateArrays(double[] a1, double[] a2) { if (a1 == null) { throw new NullPointerException("first array is null!"); } if (a2 == null) { throw new NullPointerException("second array is null!"); } if (a1.length != a2.length) { throw new IllegalArgumentException("Array sizes must be equa...
@Test public void testValidateArrays() { double[] da1 = {1, 2, 3}; double[] da2 = null; try { DoubleArrays.validateArrays(da1, da2); } catch (NullPointerException e) { Assert.assertTrue(true); } double[] da3 = {5, 6, 2.33, 2}; try { DoubleArrays.validateArrays(da1, da3); } catch (IllegalArgumentException e) { Assert.as...
DoubleArrays { public static double[] normalize16bitLittleEndian(byte[] bytez) { return normalize16bitLittleEndian(bytez, bytez.length); } private DoubleArrays(); static boolean inRange(double d1, double d2, double range); static double[] reverse(double[] input); static double[] convert(int[] input); static double[][]...
@Test public void testNormalize16bitLittleEndian() { byte[] ba = {0x10, 0x71, 0x18, 0x54}; double[] da = DoubleArrays.normalize16bitLittleEndian(ba); Assert.assertEquals(da[0] * Short.MAX_VALUE, 28944d, 0.0001); Assert.assertEquals(da[1] * Short.MAX_VALUE, 21528d, 0.0001); byte[] ba2 = DoubleArrays.denormalize16BitLitt...
DoubleArrays { public static int[] toUnsignedInteger(double[] input, int max) { if (max < 1) { throw new IllegalArgumentException("Maximum int value must be positive. But it is:" + max); } int[] iarr = new int[input.length]; double divider = (double) max / 2.0; for (int i = 0; i < input.length; i++) { double d = input[...
@Test public void testToUnsignedInteger() { double[] da = {0.2, -0.4, 0.6}; int[] ia = DoubleArrays.toUnsignedInteger(da, 6); Assert.assertEquals((int) (0.2 * 3.0), ia[0]); Assert.assertEquals((int) (-0.4 * 3.0), ia[1]); }
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 pathCount(); stat...
@Test public void loadTest1() throws IOException { List<String> lines = new ArrayList<>(); for (int i = 0; i < 10000; i++) { lines.add(String.valueOf(i)); } Path path = TestUtil.tempFileWithData(lines); BlockTextLoader loader = BlockTextLoader.fromPath(path, 1000); int i = 0; List<String> read = new ArrayList<>(); for ...
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, char delimiter...
@Test public void testRemove() { Histogram<String> histogram = new Histogram<>(); histogram.add("Apple", "Pear", "Plum", "Apple", "Apple", "Grape", "Pear"); histogram.remove("Apple"); Assert.assertEquals(0, histogram.getCount("Apple")); Assert.assertEquals(2, histogram.getCount("Pear")); Assert.assertEquals(1, histogra...
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, char delimiter,...
@Test @Ignore("Not a test.") public void testMergePerformance() throws IOException { Histogram<String> first = new Histogram<>(); Histogram<String> second = new Histogram<>(); Set<String> c1 = uniqueStrings(1000000, 5); Set<String> c2 = uniqueStrings(1000000, 5); Stopwatch sw = Stopwatch.createStarted(); first.add(c1);...
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] = amount; keys[l] = k...
@Test public void stressTest() { List<String> stringSet = randomNumberStrings(100_000); UIntValueMap<String> a = new UIntValueMap<>(); UIntValueMap<String> b = new UIntValueMap<>(); for (int i = 0; i < 20; i++) { for (String s : stringSet) { char c = s.charAt(s.length() - 1); if (a.contains(s)) { a.incrementByAmount(s,...
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 safeSet(int index, i...
@Test public void testAdd() { IntVector darray = new IntVector(); for (int i = 0; i < 10000; i++) { darray.add(i); } Assert.assertEquals(10000, darray.size()); for (int i = 0; i < 10000; i++) { Assert.assertEquals(i, darray.get(i)); } }
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(IntVector vec); i...
@Test public void testAddAll() { int[] d1 = {2, 4, 5, 17, -1, -2, 5, -123}; IntVector darray = new IntVector(); IntVector i = new IntVector(d1); darray.addAll(i); Assert.assertEquals(i, darray); }
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); int size(); int ...
@Test public void testTrimToSize() { IntVector darray = new IntVector(); for (int i = 0; i < 10000; i++) { darray.add(i); } Assert.assertEquals(10000, darray.size()); Assert.assertNotEquals(darray.size(), darray.capacity()); darray.trimToSize(); Assert.assertEquals(10000, darray.size()); Assert.assertEquals(10000, darr...
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[] words, long...
@Test public void fillTest() { LongBitVector vector = new LongBitVector(128); vector.add(128, false); for (int i = 0; i < 128; i++) { Assert.assertTrue(!vector.get(i)); } vector.fill(true); for (int i = 0; i < 128; i++) { Assert.assertTrue(vector.get(i)); } vector.fill(false); for (int i = 0; i < 128; i++) { Assert.ass...
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 + 1) & modulo;...
@Test public void getTest() { UIntMap<String> map = new UIntMap<>(1); map.put(1, "2"); Assert.assertEquals("2", map.get(1)); Assert.assertNull(map.get(2)); map.put(1, "3"); Assert.assertEquals("3", map.get(1)); map = new UIntMap<>(); for (int i = 0; i < 100000; i++) { map.put(i, String.valueOf(i + 1)); } for (int i = 0...
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 containsKey(int key); vo...
@Test public void getValuesTest() { UIntMap<String> map = new UIntMap<>(); int size = 1000; List<String> expected = new ArrayList<>(); for (int i = 0; i < size; i++) { String value = String.valueOf(i + 1); map.put(i, value); expected.add(value); } Assert.assertEquals(expected, map.getValuesSortedByKey()); }
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); } } IntIntMap()...
@Test public void removeSpansWorksCorrectly2() { IntIntMap im = createMap(); int limit = 9999; insertSpan(im, 0, limit); int[] r = TestUtils.createRandomUintArray(1000, limit); for (int i : r) { im.remove(i); } for (int i : r) { assertEquals(im.get(i), IntIntMap.NO_RESULT); } insertSpan(im, 0, limit); checkSpan(im, 0, ...
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 increment(int...
@Test public void removeTest2() { IntIntMap map = createMap(); for (int i = 0; i < 10000; i++) { map.put(i, i + 1); } for (int i = 0; i < 10000; i += 3) { map.remove(i); } for (int i = 0; i < 10000; i += 3) { Assert.assertTrue(!map.containsKey(i)); } for (int i = 0; i < 10000; i++) { map.put(i, i + 1); } for (int i = 0...
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 amount); void...
@Test public void constructorTest2() { IntValueMap<String> set = new IntValueMap<>(1); set.addOrIncrement("foo"); Assert.assertEquals(1, set.size()); set.remove("foo"); Assert.assertEquals(0, set.size()); Assert.assertFalse(set.contains("foo")); }
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 = -loc - 1; keys[lo...
@Test public void putTest() { IntValueMap<String> table = new IntValueMap<>(); table.put("foo", 1); Assert.assertEquals(1, table.size()); table.put("foo", 2); Assert.assertEquals(1, table.size()); table = new IntValueMap<>(); for (int i = 0; i < 1000; i++) { table.put(String.valueOf(i), i + 1); Assert.assertEquals(i + ...
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 size); int add...
@Test public void expandTest() { IntValueMap<String> table = new IntValueMap<>(); for (int i = 0; i < 10000; i++) { table.put(String.valueOf(i), i + 1); Assert.assertEquals(i + 1, table.size()); } for (int i = 0; i < 5000; i++) { table.remove(String.valueOf(i)); Assert.assertEquals(10000 - i - 1, table.size()); } for (...
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) & modulo; continue;...
@Test public void getTest() { IntValueMap<Integer> table = new IntValueMap<>(); table.put(1, 2); Assert.assertEquals(2, table.get(1)); Assert.assertEquals(0, table.get(2)); table.put(1, 3); Assert.assertEquals(3, table.get(1)); table = new IntValueMap<>(); for (int i = 0; i < 1000; i++) { table.put(i, i + 1); } for (in...
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); void addOrI...
@Test public void copyOfValuesTest() { IntValueMap<String> set = new IntValueMap<>(); for (int i = 0; i < 1000; i++) { set.put(String.valueOf(i), i + 1); } int[] values = set.copyOfValues(); Assert.assertEquals(1000, values.length); Arrays.sort(values); for (int i = 0; i < 1000; i++) { Assert.assertEquals(i + 1, values...
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 incrementByAmou...
@Test @Ignore("Not a unit test") public void perfStrings() { for (int i = 0; i < 5; i++) { Set<String> strings = uniqueStrings(1000000, 7); Stopwatch sw = Stopwatch.createStarted(); Set<String> newSet = new HashSet<>(strings); System.out.println("Java Set : " + sw.elapsed(TimeUnit.MILLISECONDS)); System.out.println("Si...
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 numberOfNewOneBitCount(FixedBitVect...
@Test(expected = IllegalArgumentException.class) public void safeGet() { FixedBitVector vector = new FixedBitVector(10); vector.safeGet(10); }
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 other); int d...
@Test(expected = IllegalArgumentException.class) public void safeSet() { FixedBitVector vector = new FixedBitVector(10); vector.safeSet(10); }
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(FixedBitVector other); i...
@Test(expected = IllegalArgumentException.class) public void safeClear() { FixedBitVector vector = new FixedBitVector(10); vector.safeClear(10); }
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(FloatValueMap<...
@Test public void testValues() { FloatValueMap<String> set = new FloatValueMap<>(); set.set("a", 7); set.set("b", 2); set.set("c", 3); set.set("d", 4); set.set("d", 5); Assert.assertEquals(4, set.size()); float[] values = set.values(); Arrays.sort(values); Assert.assertTrue(Arrays.equals(new float[]{2f, 3f, 5f, 7f}, va...
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] = key; keyCoun...
@Test public void addTest() { Foo f1 = new Foo("abc", 1); Foo f2 = new Foo("abc", 2); LookupSet<Foo> fooSet = new LookupSet<>(); Assert.assertTrue(fooSet.add(f1)); Assert.assertFalse(fooSet.add(f2)); } @Test public void lookupTest() { Foo f1 = new Foo("abc", 1); Foo f2 = new Foo("abc", 2); LookupSet<Foo> fooSet = new L...
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[loc] = key; keyC...
@Test public void getOrAddTest() { Foo f1 = new Foo("abc", 1); Foo f2 = new Foo("abc", 2); LookupSet<Foo> fooSet = new LookupSet<>(); Assert.assertEquals(1, fooSet.getOrAdd(f1).b); Assert.assertEquals(1, fooSet.getOrAdd(f2).b); } @Test public void removeTest() { Foo f1 = new Foo("abc", 1); Foo f2 = new Foo("abc", 2); L...
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_RESULT; } slot = pr...
@Test public void removeSpansWorksCorrectly2() { IntFloatMap im = createMap(); int limit = 9999; insertSpan(im, 0, limit); int[] r = TestUtils.createRandomUintArray(1000, limit); for (int i : r) { im.remove(i); } for (int i : r) { assertEqualsF(im.get(i), IntIntMap.NO_RESULT); } insertSpan(im, 0, limit); checkSpan(im, ...
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 value); void inc...
@Test public void removeTest2() { IntFloatMap map = createMap(); for (int i = 0; i < 10000; i++) { map.put(i, i + 1); } for (int i = 0; i < 10000; i += 3) { map.remove(i); } for (int i = 0; i < 10000; i += 3) { Assert.assertTrue(!map.containsKey(i)); } for (int i = 0; i < 10000; i++) { map.put(i, i + 1); } for (int i =...
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.children.size()...
@Test public void getAllTest() { List<Item> items = createitems("elma", "el", "arm", "armut", "a", "elmas"); additems(items); List<Item> all = lt.getAll(); Assert.assertEquals(6, all.size()); }
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(); List<T> getPre...
@Test public void removeStems() { List<Item> items = createitems("el", "elmas", "elma", "ela"); additems(items); checkitemsExist(items); checkitemsMatches("el", createitems("el")); checkitemsMatches("el", createitems()); lt.remove(items.get(1).surfaceForm, items.get(1)); checkitemsMatches("elmas", createitems()); check...
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 isAsciiEqual(char c1, cha...
@Test public void isVowelTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String vowels = "aeiuüıoöâîû"; for (char c : vowels.toCharArray()) { Assert.assertTrue(alphabet.isVowel(c)); } String nonvowels = "bcçdfgğjklmnprştvxwzq."; for (char c : nonvowels.toCharArray()) { Assert.assertFalse(alphabet.isVowel(...
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); IntIntMap get...
@Test public void vowelCountTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String[] entries = {"a", "aa", "", "bb", "bebaba"}; int[] expCounts = {1, 2, 0, 0, 3}; int i = 0; for (String entry : entries) { Assert.assertEquals(expCounts[i++], alphabet.vowelCount(entry)); } }
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(); char getAsciiEqu...
@Test public void voiceTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String iStr = "çÇgGkKpPtTaAbB"; String oStr = "cCğĞğĞbBdDaAbB"; for (int i = 0; i < iStr.length(); i++) { char in = iStr.charAt(i); char outExpected = oStr.charAt(i); Assert.assertEquals("", String.valueOf(outExpected), String.valueOf(...
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(); char getAsci...
@Test public void devoiceTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String iStr = "bBcCdDgGğĞaAkK"; String oStr = "pPçÇtTkKkKaAkK"; for (int i = 0; i < iStr.length(); i++) { char in = iStr.charAt(i); char outExpected = oStr.charAt(i); Assert.assertEquals("", String.valueOf(outExpected), String.valueO...
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 getTurkishToAsciiMap();...
@Test public void circumflexTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String iStr = "abcâîûÂÎÛ fg12"; String oStr = "abcaiuAİU fg12"; Assert.assertEquals(oStr, alphabet.normalizeCircumflex(iStr)); }
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(); } private TurkishAlp...
@Test public void toAsciiTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String iStr = "abcçğıiİIoöüşâîûÂÎÛz"; String oStr = "abccgiiIIoousaiuAIUz"; Assert.assertEquals(oStr, alphabet.toAscii(iStr)); }
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 false; } } return ...
@Test public void equalsIgnoreDiacritics() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String[] a = {"siraci", "ağac", "ağaç"}; String[] b = {"şıracı", "ağaç", "agac"}; for (int i = 0; i < a.length; i++) { Assert.assertTrue(alphabet.equalsIgnoreDiacritics(a[i], b[i])); } }
TurkishAlphabet { public boolean checkVowelHarmonyA(CharSequence source, CharSequence target) { TurkicLetter sourceLastVowel = getLastVowel(source); TurkicLetter targetFirstVowel = getLastVowel(target); return checkVowelHarmonyA(sourceLastVowel, targetFirstVowel); } private TurkishAlphabet(); String toAscii(String in)...
@Test public void vowelHarmonyA() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String[] a = {"elma", "kedi", "turp"}; String[] b= {"lar", "cik", "un"}; for (int i = 0; i < a.length; i++) { Assert.assertTrue(alphabet.checkVowelHarmonyA(a[i], b[i])); } } @Test public void vowelHarmonyA2() { TurkishAlphabet alph...
TurkishAlphabet { public boolean checkVowelHarmonyI(CharSequence source, CharSequence target) { TurkicLetter sourceLastVowel = getLastVowel(source); TurkicLetter targetFirstVowel = getLastVowel(target); return checkVowelHarmonyI(sourceLastVowel, targetFirstVowel); } private TurkishAlphabet(); String toAscii(String in)...
@Test public void vowelHarmonyI1() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String[] a = {"elma", "kedi", "turp"}; String[] b = {"yı", "yi", "u"}; for (int i = 0; i < a.length; i++) { Assert.assertTrue(alphabet.checkVowelHarmonyI(a[i], b[i])); } } @Test public void vowelHarmonyI2() { TurkishAlphabet alpha...
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 false; } } retu...
@Test public void startsWithDiacriticsIgnoredTest() { TurkishAlphabet alphabet = TurkishAlphabet.INSTANCE; String[] a = {"siraci", "çağlayan"}; String[] b = {"şıracı", "cag"}; for (int i = 0; i < a.length; i++) { Assert.assertTrue(alphabet.startsWithIgnoreDiacritics(a[i], b[i])); } }
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 dis); static LmV...
@Test public void specialWordsTest() throws IOException { LmVocabulary vocabulary = new LmVocabulary("<S>", "Hello", "</S>"); vocabulary.containsAll("<S>", "Hello", "</S>", "<unk>"); }
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); LmVocabulary(List<String>...
@Test public void binaryFileGenerationTest() throws IOException { File tmp = getBinaryVocFile(); LmVocabulary vocabulary = LmVocabulary.loadFromBinary(tmp); simpleCheck(vocabulary); }
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(RandomAccessFile raf...
@Test public void utf8FileGenerationTest() throws IOException { File tmp = getUtf8VocFile(); LmVocabulary vocabulary = LmVocabulary.loadFromUtf8File(tmp); simpleCheck(vocabulary); }
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); static LmVocabu...
@Test public void streamGenerationTest() throws IOException { File tmp = getBinaryVocFile(); try (DataInputStream dis = new DataInputStream(new FileInputStream(tmp))) { LmVocabulary vocabulary = LmVocabulary.loadFromDataInputStream(dis); simpleCheck(vocabulary); } }
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); static LmVoca...
@Test public void randomAccessGenerationTest() throws IOException { File tmp = getBinaryVocFile(); try (RandomAccessFile raf = new RandomAccessFile(tmp, "r")) { LmVocabulary vocabulary = LmVocabulary.loadFromRandomAccessFile(raf); simpleCheck(vocabulary); } }
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 binaryVocabul...
@Test public void contains() throws IOException { LmVocabulary vocabulary = new LmVocabulary("Hello", "World"); int helloIndex = vocabulary.indexOf("Hello"); int worldIndex = vocabulary.indexOf("World"); Assert.assertTrue(vocabulary.contains(helloIndex)); Assert.assertTrue(vocabulary.contains(worldIndex)); int unkIndex...
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(DataInputStream dis); static...
@Test public void encodedTrigramTest() throws IOException { LmVocabulary vocabulary = new LmVocabulary("a", "b", "c", "d", "e"); long k = ((1L << 21 | 2L) << 21) | 3L; Assert.assertEquals(k, vocabulary.encodeTrigram(3, 2, 1)); Assert.assertEquals(k, vocabulary.encodeTrigram(3, 2, 1)); }
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; } LmVocabula...
@Test public void toWordsTest() throws IOException { LmVocabulary vocabulary = new LmVocabulary("a", "b", "c", "d", "e"); int[] indexes = vocabulary.toIndexes("a", "e", "b"); Assert.assertEquals("a e b", Joiner.on(" ").join(vocabulary.toWords(indexes))); indexes = vocabulary.toIndexes("a", "e", "foo"); Assert.assertEqu...
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); static LmVocabulary...
@Test public void builderTest() throws IOException { LmVocabulary.Builder builder = LmVocabulary.builder(); String[] words = {"elma", "çilek", "karpuz", "armut", "elma", "armut"}; for (String word : words) { builder.add(word); } Assert.assertEquals(4, builder.size()); Assert.assertEquals(0, builder.indexOf("elma")); As...
SmoothLm extends BaseLanguageModel implements NgramLanguageModel { @Override public int getOrder() { return order; } private SmoothLm( DataInputStream dis, float logBase, float unigramWeight, float unknownBackoffPenalty, boolean useStupidBackoff, float stupidBackoffAlpha, File...
@Test public void testGeneration() throws IOException { SmoothLm lm = getTinyLm(); Assert.assertEquals(3, lm.getOrder()); }