Ejemplo n.º 1
0
  /**
   * Test of extending Tesseract.
   *
   * @throws java.lang.Exception
   */
  @Test
  public void testExtendingTesseract() throws Exception {
    logger.info("Extends Tesseract");
    File imageFile = new File(this.testResourcesDataPath, "eurotext.tif");

    String expResult = "The (quick) [brown] {fox} jumps!\nOver the $43,456.78 <lazy> #90 dog";
    String[] expResults = expResult.split("\\s");

    TessExtension instance1 = new TessExtension();
    instance1.setDatapath(new File(datapath).getPath());
    int pageIteratorLevel = TessPageIteratorLevel.RIL_WORD;
    logger.info(
        "PageIteratorLevel: "
            + Utils.getConstantName(pageIteratorLevel, TessPageIteratorLevel.class));
    List<Word> result = instance1.getTextElements(imageFile, pageIteratorLevel);

    // print the complete result
    for (Word word : result) {
      logger.info(word.toString());
    }

    List<String> text = new ArrayList<String>();
    for (Word word : result.subList(0, expResults.length)) {
      text.add(word.getText());
    }

    assertArrayEquals(expResults, text.toArray());
  }
Ejemplo n.º 2
0
 @Test
 public void shouldGetSynonymsFromOtherSide() {
   wordRepository.save(earth);
   wordRepository.save(globe);
   assertThat("globe's synonyms count", globe.getSynonymsCount(), is(0));
   // as earth and globe both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.synonymWith(globe, "the planet we live");
   assertThat("globe's synonyms count", globe.getSynonymsCount(), is(equalTo(1)));
   assertThat("globe's synonyms contain earth", globe.getSynonyms(), hasItem(earth));
 }
Ejemplo n.º 3
0
  @Test
  public void shouldGetIdiomFromOtherSide() {
    wordRepository.save(earth);
    wordRepository.save(onEarth);
    assertThat("onEarth's idiom count", onEarth.getIdiomsCount(), is(0));

    // as earth and sky both are under controll of springdata graph, no need to further call
    // earth.save()
    earth.idiomWith(onEarth, "added a prefix 'on'");
    assertThat("onEarth's idiom count", onEarth.getIdiomsCount(), is(equalTo(1)));
    assertThat("onEarth's idiom contains earth", onEarth.getIdioms(), hasItem(earth));
  }
Ejemplo n.º 4
0
  @Test
  public void shouldGetExtensionFromOtherSide() {
    wordRepository.save(earth);
    wordRepository.save(sky);
    assertThat("sky's extensions count", sky.getExtensionsCount(), is(0));

    // as earth and sky both are under controll of springdata graph, no need to further call
    // earth.save()
    earth.extendWith(sky, "earth and sky just intuitive");
    assertThat("sky's extensions count", sky.getExtensionsCount(), is(equalTo(1)));
    assertThat("sky's extensions contains sky", sky.getExtensions(), hasItem(earth));
  }
Ejemplo n.º 5
0
 @Test
 public void shouldGetSynonymsFromSavingSide() {
   wordRepository.save(earth);
   assertThat("earth's synonyms count", earth.getSynonymsCount(), is(0));
   wordRepository.save(globe);
   // as earth and globe both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.synonymWith(globe, "the planet we live");
   assertThat("earth's synonyms count", earth.getSynonymsCount(), is(equalTo(1)));
   assertThat("earth's synonym contains globe", earth.getSynonyms(), hasItem(globe));
   Relationship relationship = earth.getSynonymRelationshipTo(globe);
   assertThat("relationship should work properly", relationship.getWord(), is(earth));
   assertThat("relationship should work properly", relationship.getAnotherWord(), is(globe));
   assertThat(
       "relationship should work properly", relationship.getOnEnglish(), is("the planet we live"));
 }
Ejemplo n.º 6
0
 @Test
 public void shouldGetIdiomFromSavingSide() {
   wordRepository.save(earth);
   assertThat("earth's idioms count", earth.getIdiomsCount(), is(0));
   wordRepository.save(onEarth);
   // as earth and sky both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.idiomWith(onEarth, "added a prefix 'on'");
   assertThat("earth's idioms count", earth.getIdiomsCount(), is(equalTo(1)));
   assertThat("earth's idioms contains onEarth", earth.getIdioms(), hasItem(onEarth));
   Relationship relationship = earth.getIdiomRelationshipTo(onEarth);
   assertThat("relationship should work properly", relationship.getWord(), is(earth));
   assertThat("relationship should work properly", relationship.getAnotherWord(), is(onEarth));
   assertThat(
       "relationship should work properly",
       relationship.getOnEnglish(),
       is("added a prefix 'on'"));
 }
Ejemplo n.º 7
0
 @Test
 public void shouldGetExtensionFromSavingSide() {
   wordRepository.save(earth);
   assertThat("earth's extensions count", earth.getExtensionsCount(), is(0));
   wordRepository.save(sky);
   // as earth and sky both are under controll of springdata graph, no need to further call
   // earth.save()
   earth.extendWith(sky, "earth and sky just intuitive");
   assertThat("earth's extensions count", earth.getExtensionsCount(), is(equalTo(1)));
   assertThat("earth's extensions contains sky", earth.getExtensions(), hasItem(sky));
   Relationship relationship = earth.getExtensionRelationshipTo(sky);
   assertThat("relationship should work properly", relationship.getWord(), is(earth));
   assertThat("relationship should work properly", relationship.getAnotherWord(), is(sky));
   assertThat(
       "relationship should work properly",
       relationship.getOnEnglish(),
       is("earth and sky just intuitive"));
 }
Ejemplo n.º 8
0
  @Test
  public void shouldGetAntonymFromOtherSide() {
    wordRepository.save(happy);
    wordRepository.save(sad);
    wordRepository.save(earth);
    assertThat("sad's antonym count", sad.getAntonymsCount(), is(0));
    // as earth and sky both are under controll of springdata graph, no need to further call
    // earth.save()
    happy.antonymWith(sad, "feel good vs feel bad'");
    assertThat("sad's antonym count", sad.getAntonymsCount(), is(equalTo(1)));
    assertThat("sad's antonym contains happy", sad.getAntonyms(), hasItem(happy));
    Relationship relationship = happy.getSynonymRelationshipTo(sad);
    assertThat(
        "relationship should work properly", relationship, is(CoreMatchers.<Object>nullValue()));

    Set<Relationship> relationships = happy.getRelationshipsTo(earth);
    assertThat(relationships.size(), is(0));
  }
Ejemplo n.º 9
0
  @Test
  public void shouldGetAntonymFromSavingSide() {
    wordRepository.save(happy);
    assertThat("happy's antonym count", happy.getAntonymsCount(), is(0));
    wordRepository.save(sad);
    // as earth and sky both are under controll of springdata graph, no need to further call
    // earth.save()
    happy.antonymWith(sad, "feel good vs feel bad");
    assertThat("happy's antonym count", happy.getAntonymsCount(), is(equalTo(1)));
    assertThat("happy's antonym contains sad", happy.getAntonyms(), hasItem(sad));
    Relationship relationship = happy.getAntonymRelationshipTo(sad);
    assertThat("relationship should work properly", relationship.getWord(), is(happy));
    assertThat("relationship should work properly", relationship.getAnotherWord(), is(sad));
    assertThat(
        "relationship should work properly",
        relationship.getOnEnglish(),
        is("feel good vs feel bad"));

    Set<Relationship> relationships = happy.getRelationshipsTo(sad);
    assertThat(relationships.size(), is(1));
    assertThat(relationships, hasItem(relationship));
  }
Ejemplo n.º 10
0
  public PalindromeTest() {
    ArrayList<String> words = new ArrayList<String>();
    ArrayList<String> palis;

    try {
      for (String line : Files.readAllLines(Paths.get("com/jsanders/web2"))) {
        words.add(line);
      }
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }

    palis = Palindrome.palindromes(words);
    assertEquals(palis.size(), 161, 0.01);

    int shortest = Word.shortestLength(words);
    assertEquals(shortest, 1, 0.01);

    int longest = Word.longestLength(words);
    assertEquals(longest, 24, 0.01);

    ArrayList<String> shortestWords = Word.shortestWords(words);
    assertEquals(shortestWords.size(), 52, 0.01);

    ArrayList<String> longestWords = Word.longestWords(words);
    assertEquals(longestWords.size(), 5, 0.01);

    int totalWords = Word.totalWords(words);
    double avgLen = Word.averageLength(words);

    assertEquals(totalWords, 235886, 0.01);
    assertEquals(avgLen, 9.56, 0.01);

    ArrayList<Double> letterFreq = Word.letterFrequency(words);
    assertEquals(letterFreq.get(0), 0.087, 0.01);

    double properFreq = Word.properFrequency(words);
    assertEquals(properFreq, 0.106, 0.01);

    ArrayList<Integer> startFreq = Word.startFrequency(words);
    assertEquals(startFreq.get(0), 17096, 0.01);

    ArrayList<String> sameStartEnd = Word.startEndWords(words);
    assertEquals(sameStartEnd.size(), 11505, 0.01);

    try {
      PrintWriter f = new PrintWriter("short.txt");
      for (String w : shortestWords) f.println(w);
      f.close();

      f = new PrintWriter("long.txt");
      for (String w : longestWords) f.println(w);
      f.close();

      f = new PrintWriter("same.txt");
      for (String w : sameStartEnd) f.println(w);
      f.close();

      f = new PrintWriter("statistics.txt");
      f.println("avg word len: " + avgLen);
      f.println("freq of letters: " + letterFreq);
      f.println("freq of proper nouns/names: " + properFreq);
      f.println("words that start with each letter:: " + startFreq);

      f.close();
    } catch (IOException ex) {
      System.out.println("IO error");
      System.exit(1);
    }
  }
Ejemplo n.º 11
0
 @Test
 public void shouldRetrieveTheSameWordJustSaved() {
   Word retrievedWord = wordRepository.save(earth);
   assertEquals("retrieved word match persisted one", earth, retrievedWord);
   assertEquals("retrieved word name match ", "earth", retrievedWord.getName());
 }