Exemplo n.º 1
0
 /** Test of rightShiftBuffer method, of class FidelDecoder. */
 public void testRightShiftBuffer() {
   System.out.println("rightShiftBuffer");
   int[] buf = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0};
   int shift = 2;
   int at = 6;
   FidelDecoder.rightShiftBuffer(buf, shift, at);
   Assert.assertArrayEquals(new int[] {1, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9}, buf);
   final int[] buf2 = new int[] {7, 9, 0};
   FidelDecoder.rightShiftBuffer(buf2, 1, 1);
   Assert.assertArrayEquals(new int[] {7, 9, 9}, buf2);
 }
Exemplo n.º 2
0
 /** Test of recalcDist method, of class FidelDecoder. */
 @Test
 public void testRecalcDist() {
   System.out.println("recalcDist");
   int[] dist = {0, 0, -1, 1, 0};
   int length = 2;
   int shift = 2;
   int[] expResult = {0, 0, -1, -2, -2, 3, 2};
   int[] result = FidelDecoder.recalcDist(dist, length, shift);
   assertArrayEquals(expResult, result);
   assertArrayEquals(new int[] {-2, 1, 1}, FidelDecoder.recalcDist(new int[] {0, 0}, 1, 2));
 }
Exemplo n.º 3
0
 /** Test of tryPutTranslation method, of class FidelDecoder. */
 @Test
 public void testTryPutTranslation_7args() {
   System.out.println("tryPutTranslation");
   PhraseTranslation pt =
       new PhraseTranslation(
           new int[] {6},
           new double[] {
             log10(0.474756), log10(0.427108), log10(0.128955), log10(0.144797), log10(2.718)
           });
   double[] weights = {1, 1, 1, 1, 1, 1, 1, 1};
   int[] buf = new int[2];
   int pos = 0;
   IntegerLanguageModelImpl languageModel = lm;
   int lmN = 2;
   int dist = 0;
   double expResult =
       log10(0.474756)
           + log10(0.427108)
           + log10(0.128955)
           + log10(0.144797)
           + log10(2.718)
           - 3.320179;
   double result =
       FidelDecoder.tryPutTranslation(pt, weights, buf, pos, languageModel, lmN, dist)[0];
   assertEquals(expResult, result, 0.001);
 }
Exemplo n.º 4
0
 /** Test of lmScore method, of class FidelDecoder. */
 public void testLmScoreDirect() {
   System.out.println("lmScore");
   int[] buf = {6, 9, 12};
   IntegerLanguageModelImpl languageModel = lm;
   int lmN = 2;
   assertEquals(
       -2.74139, FidelDecoder.lmScore(buf, 2, languageModel, lmN, Double.NEGATIVE_INFINITY), 0.01);
 }
Exemplo n.º 5
0
 @Test
 public void testDeltaDist() {
   System.out.println("deltaDist");
   int[] dist = {0, 0, -1, 1, 0};
   int length = 2;
   int shift = 2;
   double[] weights = {1, 1, 1, 1, 1, 1, 1, 1};
   double result = FidelDecoder.deltaDist(dist, length, shift, weights);
   assertEquals(-8, result, 0.0);
 }
Exemplo n.º 6
0
 /** Test of leftShiftBuffer method, of class FidelDecoder. */
 @Test
 public void testLeftShiftBuffer() {
   System.out.println("leftShiftBuffer");
   int[] buf = {1, 2, 3, 4, 5, 6, 7, 6, 7, 8, 9};
   int shift = 2;
   int at = 6;
   FidelDecoder.leftShiftBuffer(buf, shift, at);
   int[] expResult = {1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 9};
   assertArrayEquals(expResult, buf);
 }
Exemplo n.º 7
0
 /** Test of calcPartialScore method, of class FidelDecoder. */
 @Test
 public void testCalcPartialScore() {
   System.out.println("calcPartialScore");
   int[] src = {0, 1, 2, 3, 4, 5};
   Object2ObjectMap<Phrase, Collection<PhraseTranslation>> phraseTable = pt;
   double[] weights = {1, 1, 1, 1, 1, 1, 1, 1};
   IntegerLanguageModelImpl languageModel = lm;
   int lmN = 2;
   double[] expResult = {-5.3066, -7.6801, -6.2073, -3.5574, -5.0824, -7.3064};
   double[] result = FidelDecoder.calcPartialScore(src, phraseTable, weights, languageModel, lmN);
   assertArrayEquals(expResult, result, 0.01);
 }
Exemplo n.º 8
0
 /** Test of decode method, of class FidelDecoder. */
 public void testDecode() {
   System.out.println("decode");
   int[] src = {0, 1, 2, 3, 4, 5};
   Object2ObjectMap<Phrase, Collection<PhraseTranslation>> phraseTable = pt;
   IntegerLanguageModelImpl languageModel = lm;
   int lmN = 2;
   double[] weights = new double[] {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
   int distiortionLimit = 3;
   int nBest = 1;
   Solution[] result =
       FidelDecoder.decode(
           src, phraseTable, languageModel, lmN, weights, distiortionLimit, nBest, 1000, false);
   final int[] expSoln = new int[] {7, 9, 16, 11};
   System.out.println("My Guess:" + Arrays.toString(expSoln));
   System.out.println("Fidel's soln: " + Arrays.toString(result[0].soln()));
   //        assertArrayEquals(expSoln, result[0].soln);
 }
Exemplo n.º 9
0
 public void testFeatures() {
   System.out.println("decode");
   int[] src = {0, 1, 2, 3, 4, 5};
   Object2ObjectMap<Phrase, Collection<PhraseTranslation>> phraseTable = pt;
   IntegerLanguageModelImpl languageModel = lm;
   int lmN = 2;
   double[] weights = new double[] {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
   int distiortionLimit = 3;
   int nBest = 1;
   Solution[] result =
       FidelDecoder.decode(
           src, phraseTable, languageModel, lmN, weights, distiortionLimit, nBest, 1000, false);
   for (int j = 0; j < result.length; j++) {
     double scoreFromFeats = 0.0;
     for (int i = 0; i < weights.length; i++) {
       scoreFromFeats += result[j].features()[i];
     }
     assertEquals(result[j].score(), scoreFromFeats, 0.0001);
   }
 }
Exemplo n.º 10
0
 public void testDecodeSimple() {
   System.out.println("decodeSimple");
   int[] src = {0, 1, 2};
   Object2ObjectMap<Phrase, Collection<PhraseTranslation>> phraseTable =
       new Object2ObjectOpenHashMap<Phrase, Collection<PhraseTranslation>>();
   phraseTable.put(
       new Phrase(new int[] {0}),
       Arrays.asList(new PhraseTranslation(new int[] {3}, new double[] {-1})));
   phraseTable.put(
       new Phrase(new int[] {1}),
       Arrays.asList(new PhraseTranslation(new int[] {4}, new double[] {-1})));
   phraseTable.put(
       new Phrase(new int[] {2}),
       Arrays.asList(new PhraseTranslation(new int[] {5}, new double[] {-1})));
   final IntegerLanguageModelImpl languageModel = new IntegerLanguageModelImpl();
   languageModel.put(new Phrase(new int[] {3}), new double[] {-1, -10});
   languageModel.put(new Phrase(new int[] {4}), new double[] {-1, -10});
   languageModel.put(new Phrase(new int[] {5}), new double[] {-1, -10});
   languageModel.put(
       new Phrase(new int[] {3, 4}),
       new double[] {
         -1,
       });
   languageModel.put(
       new Phrase(new int[] {4, 5}),
       new double[] {
         -1,
       });
   int lmN = 2;
   double[] weights = new double[] {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
   int distiortionLimit = 3;
   int nBest = 1;
   Solution[] result =
       FidelDecoder.decode(
           src, phraseTable, languageModel, lmN, weights, distiortionLimit, nBest, 1000, false);
   assertArrayEquals(new int[] {3, 4, 5}, result[0].soln());
   assertEquals(-6, result[0].score(), 0.01);
 }