Package joshua.corpus.suffix_array

Examples of joshua.corpus.suffix_array.Pattern


  @Test
  public void getTerminalSequenceLengths() {
   
    {
      int[] flatWords = {1, 2, 3, 4, 5};
      Pattern flat = new Pattern(vocab, flatWords);
      byte[] flatSeqs = flat.getTerminalSequenceLengths();

      Assert.assertNotNull(flatSeqs);
      Assert.assertEquals(flatSeqs.length, 1);
      Assert.assertEquals(flatSeqs[0], 5);
    }
   
    {
      int[] hierWords = {1, SymbolTable.X, 6, 7};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 2);
      Assert.assertEquals(hierSeqs[0], 1);
      Assert.assertEquals(hierSeqs[1], 2);
    }
   
    {
      int[] hierWords = {SymbolTable.X, 6, 7};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 1);
      Assert.assertEquals(hierSeqs[0], 2);
    }
   
    {
      int[] hierWords = {1, 2, 3, SymbolTable.X};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 1);
      Assert.assertEquals(hierSeqs[0], 3);
    }
   
    {
      int[] hierWords = {1, SymbolTable.X, 6, 7, SymbolTable.X};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 2);
      Assert.assertEquals(hierSeqs[0], 1);
      Assert.assertEquals(hierSeqs[1], 2);
    }
   
    {
      int[] hierWords = {SymbolTable.X, 6, 7, SymbolTable.X, 10};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 2);
      Assert.assertEquals(hierSeqs[0], 2);
      Assert.assertEquals(hierSeqs[1], 1);
    }
   
    {
      int[] hierWords = {1, 2, 3, SymbolTable.X, 6, 7, SymbolTable.X};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 2);
      Assert.assertEquals(hierSeqs[0], 3);
      Assert.assertEquals(hierSeqs[1], 2);
    }
   
    {
      int[] hierWords = {1, SymbolTable.X, 6, SymbolTable.X, 9};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 3);
      Assert.assertEquals(hierSeqs[0], 1);
      Assert.assertEquals(hierSeqs[1], 1);
      Assert.assertEquals(hierSeqs[2], 1);
    }
   
    {
      int[] hierWords = {1, 2, 3, SymbolTable.X, 6, 7, SymbolTable.X, 9, 10, 11, 12};
      Pattern hier = new Pattern(vocab, hierWords);
      byte[] hierSeqs = hier.getTerminalSequenceLengths();
     
      Assert.assertNotNull(hierSeqs);
      Assert.assertEquals(hierSeqs.length, 3);
      Assert.assertEquals(hierSeqs[0], 3);
      Assert.assertEquals(hierSeqs[1], 2);
View Full Code Here


    cache.put(pattern, 1);
   
    Assert.assertTrue(cache.containsKey(pattern));
    Assert.assertEquals((int) cache.get(pattern), 1);
   
    Pattern copiedPattern = new Pattern(pattern);
    Assert.assertTrue(cache.containsKey(copiedPattern));
    Assert.assertEquals((int) cache.get(copiedPattern), 1);
  }
View Full Code Here

   * lexical translation probabilities for phrases with gaps.
   */
  @Test(dependsOnMethods={"setup"})
  public void calculateHieroLexProbs() {
   
    Pattern pattern = new Pattern(sourceVocab,
        sourceVocab.getID("it"),
        SymbolTable.X,
        sourceVocab.getID("and"),
        sourceVocab.getID("it"));
   
View Full Code Here

    Assert.assertEquals(targetGivenSource, 0.25f * 1.0f * 0.75f);// lex P(das X und es | it X and it)
   
  }
 
  private HierarchicalPhrases getSourcePhrase(String sourcePhrase, int startIndex, int endIndex) {
    Pattern pattern = new Pattern(sourceVocab, sourceVocab.getIDs(sourcePhrase));
    int[] terminalSequenceStartIndices = {startIndex};
    int[]       sentenceNumbers = {0};
   
    HierarchicalPhrases phrases =
      new HierarchicalPhrases(pattern, terminalSequenceStartIndices, sentenceNumbers);
View Full Code Here

  public void testHasAlignedTerminal() {
   
    SymbolTable vocab = sourceCorpusArray.getVocabulary();
   
    {
      Pattern     pattern = new Pattern(vocab, vocab.getIDs("de sesiones del parlamento europeo"));
      int[]       terminalSequenceStartIndices = {4};
      int[]       sentenceNumbers = {0};
      int phraseIndex = 0;
     
      HierarchicalPhrases phrases =
        new HierarchicalPhrases(pattern, terminalSequenceStartIndices, sentenceNumbers);
     
     
     
      Assert.assertFalse(alignments.hasAlignedTerminal(0 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(1 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(2 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(3 , phrases, phraseIndex));

      Assert.assertTrue(alignments.hasAlignedTerminal(4 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(5 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(6 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(7 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(8 , phrases, phraseIndex));

      Assert.assertFalse(alignments.hasAlignedTerminal(9 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(10 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(11 , phrases, phraseIndex));
    }
 
   
    {
      Pattern     pattern = new Pattern(vocab, vocab.getIDs(","));
      int[]       terminalSequenceStartIndices = {9};
      int[]       sentenceNumbers = {0};
      int phraseIndex = 0;

      HierarchicalPhrases phrases =
View Full Code Here

   
 
    SymbolTable vocab = sourceCorpusArray.getVocabulary();
   
    {
      Pattern     pattern = new Pattern(new Pattern(new Pattern(vocab, vocab.getIDs("de sesiones")), SymbolTable.X), vocab.getIDs("europo"));// del parlamento europeo"));
      int[]       terminalSequenceStartIndices = {4,8};
      int[]       sentenceNumbers = {0};
      int phraseIndex = 0;
     
      HierarchicalPhrases phrases =
        new HierarchicalPhrases(pattern, terminalSequenceStartIndices, sentenceNumbers);
//      HierarchicalPhrase phrase = new HierarchicalPhrase(pattern, terminalSequenceStartIndices, terminalSequenceEndIndices, sourceCorpusArray, length);

      Assert.assertFalse(alignments.hasAlignedTerminal(0 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(1 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(2 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(3 , phrases, phraseIndex));

      Assert.assertTrue(alignments.hasAlignedTerminal(4 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(5 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(6 , phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(7 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(8 , phrases, phraseIndex));

      Assert.assertFalse(alignments.hasAlignedTerminal(9 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(10 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(11 , phrases, phraseIndex));

    }
   
    {
      Pattern     pattern = new Pattern(new Pattern(new Pattern(vocab, vocab.getIDs(", y")), PrefixTree.X), vocab.getIDs("sus"));// del parlamento europeo"));
      int[]       terminalSequenceStartIndices = {17,21};
      int[]       sentenceNumbers = {0};
      int phraseIndex = 0;
     
      HierarchicalPhrases phrases =
        new HierarchicalPhrases(pattern, terminalSequenceStartIndices, sentenceNumbers);
     
      Assert.assertFalse(alignments.hasAlignedTerminal(12 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(13 , phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(14 , phrases, phraseIndex));

      Assert.assertTrue(alignments.hasAlignedTerminal(15, phrases, phraseIndex));
      Assert.assertTrue(alignments.hasAlignedTerminal(16, phrases, phraseIndex));
     
      Assert.assertFalse(alignments.hasAlignedTerminal(17, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(18, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(19, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(20, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(21, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(22, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(23, phrases, phraseIndex));
     
      Assert.assertTrue(alignments.hasAlignedTerminal(24, phrases, phraseIndex));

      Assert.assertFalse(alignments.hasAlignedTerminal(25, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(26, phrases, phraseIndex));
      Assert.assertFalse(alignments.hasAlignedTerminal(27, phrases, phraseIndex));
     
    }
   
    {

      Pattern     pattern = new Pattern(new Pattern(new Pattern(vocab, vocab.getIDs(",")), PrefixTree.X), vocab.getIDs(", y"));// del parlamento europeo"));
      int[]       terminalSequenceStartIndices = {9,17};
      int[]       sentenceNumbers = {0};
      int phraseIndex = 0;
     
      HierarchicalPhrases phrases =
View Full Code Here

TOP

Related Classes of joshua.corpus.suffix_array.Pattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.