@Test public void testGetRhyme() throws IOException { assertNull(store.getRhyme("no hay rima")); assertEquals(store.getRhyme("¿Hay algo que rime con tres?"), "Me escondo y no me ves"); assertEquals(store.getRhyme("Nada rima con dos"), "Ya son veintidós!!"); }
public String getRhyme(final String sentence) throws IOException { String lastWord = WordUtils.getLastWord(sentence); String rhymepart = wordParser.phoneticRhymePart(lastWord); StressType type = wordParser.stressType(lastWord); LOGGER.debug("Finding rhymes for {}", sentence); Set<String> rhymes = Sets.newHashSet(); connect(); try { rhymes.addAll(search(rhymepart, type)); } finally { disconnect(); } if (rhymes.isEmpty()) { return null; } else { List<String> rhymeList = new ArrayList<String>(rhymes); Random random = new Random(System.currentTimeMillis()); int index = random.nextInt(rhymeList.size()); return rhymeList.get(index); } }
RedisStore { public String getRhyme(final String sentence) throws IOException { String lastWord = WordUtils.getLastWord(sentence); String rhymepart = wordParser.phoneticRhymePart(lastWord); StressType type = wordParser.stressType(lastWord); LOGGER.debug("Finding rhymes for {}", sentence); Set<String> rhymes = Sets.newHashSet(); connect(); try { rhymes.addAll(search(rhymepart, type)); } finally { disconnect(); } if (rhymes.isEmpty()) { return null; } else { List<String> rhymeList = new ArrayList<String>(rhymes); Random random = new Random(System.currentTimeMillis()); int index = random.nextInt(rhymeList.size()); return rhymeList.get(index); } } }
RedisStore { public String getRhyme(final String sentence) throws IOException { String lastWord = WordUtils.getLastWord(sentence); String rhymepart = wordParser.phoneticRhymePart(lastWord); StressType type = wordParser.stressType(lastWord); LOGGER.debug("Finding rhymes for {}", sentence); Set<String> rhymes = Sets.newHashSet(); connect(); try { rhymes.addAll(search(rhymepart, type)); } finally { disconnect(); } if (rhymes.isEmpty()) { return null; } else { List<String> rhymeList = new ArrayList<String>(rhymes); Random random = new Random(System.currentTimeMillis()); int index = random.nextInt(rhymeList.size()); return rhymeList.get(index); } } @Inject  RedisStore(@Named("sentence") final Keymaker sentencens,
        @Named("index") final Keymaker indexns, final WordParser wordParser, final Jedis redis,
        final @Named(REDIS_PASSWORD) Optional<String> redisPassword, final Charset encoding); }
RedisStore { public String getRhyme(final String sentence) throws IOException { String lastWord = WordUtils.getLastWord(sentence); String rhymepart = wordParser.phoneticRhymePart(lastWord); StressType type = wordParser.stressType(lastWord); LOGGER.debug("Finding rhymes for {}", sentence); Set<String> rhymes = Sets.newHashSet(); connect(); try { rhymes.addAll(search(rhymepart, type)); } finally { disconnect(); } if (rhymes.isEmpty()) { return null; } else { List<String> rhymeList = new ArrayList<String>(rhymes); Random random = new Random(System.currentTimeMillis()); int index = random.nextInt(rhymeList.size()); return rhymeList.get(index); } } @Inject  RedisStore(@Named("sentence") final Keymaker sentencens,
        @Named("index") final Keymaker indexns, final WordParser wordParser, final Jedis redis,
        final @Named(REDIS_PASSWORD) Optional<String> redisPassword, final Charset encoding); void add(final String sentence); void delete(final String sentence); Set<String> findAll(); String getRhyme(final String sentence); }
RedisStore { public String getRhyme(final String sentence) throws IOException { String lastWord = WordUtils.getLastWord(sentence); String rhymepart = wordParser.phoneticRhymePart(lastWord); StressType type = wordParser.stressType(lastWord); LOGGER.debug("Finding rhymes for {}", sentence); Set<String> rhymes = Sets.newHashSet(); connect(); try { rhymes.addAll(search(rhymepart, type)); } finally { disconnect(); } if (rhymes.isEmpty()) { return null; } else { List<String> rhymeList = new ArrayList<String>(rhymes); Random random = new Random(System.currentTimeMillis()); int index = random.nextInt(rhymeList.size()); return rhymeList.get(index); } } @Inject  RedisStore(@Named("sentence") final Keymaker sentencens,
        @Named("index") final Keymaker indexns, final WordParser wordParser, final Jedis redis,
        final @Named(REDIS_PASSWORD) Optional<String> redisPassword, final Charset encoding); void add(final String sentence); void delete(final String sentence); Set<String> findAll(); String getRhyme(final String sentence);  }