/** * Gets the value of key * * @param key the key * @return the optional of the value */ public Optional<String> get(final String key) { return metadata.find(key); }
/** * Gets the value of key * * @param key the key * @return the optional of the value */ public Optional<String> get(final String key) { return metadata.find(key); }
/** * Gets the value at a key. * * @param key the key * @param defaultValue the default value (if the key does not exist) * @return the string value */ public String get(final String key, final String defaultValue) { return metadata.find(key).orElse(defaultValue); }
/** * Gets the value at a key. * * @param key the key * @param defaultValue the default value (if the key does not exist) * @return the string value */ public String get(final String key, final String defaultValue) { return metadata.find(key).orElse(defaultValue); }
@Test public void findKeysWithValue() { assertTrue(ImmutableSet.of(VALUE1, VALUE2, VALUE3).contains(metadata.find(KEY1, KEY2).get())); }
@Test public void testMetadataValue() { final String expectedSummary = EIGHTH_SENTENCE + "\n" + FOURTH_SENTENCE + "\n" + SIXTH_SENTENCE + "\n"; assertEquals( "The metadata key should be the summary made up of top scoring sentences", expectedSummary, metadata.find(METADATA_KEY).get()); } }
@Test public void testWordBasedShannonEntropy() { assertEquals( "Word based shannon entropy should be 3.506890595608519", "3.506890595608519", jCasMetadata.find(ShannonEntropyAnnotator.METADATA_WORD_BASED_ENTROPY_KEY).get()); }
@Test public void testCharacterBasedShannonEntropy() { assertEquals( "Character based shannon entropy should be 3.912949440895038", "3.912949440895038", jCasMetadata.find(ShannonEntropyAnnotator.METADATA_CHARACTER_BASED_ENTROPY_KEY).get()); } }
@Test public void findKeyWithoutValue() { assertEquals(Optional.empty(), metadata.find("missing")); }
private void testJcasTable1(JCas jCas, int row) { assertTrue(jCas.getDocumentText().startsWith("TEXT BLOCK")); JCasMetadata metadata = new JCasMetadata(jCas); Optional<String> find = metadata.find("resourceName"); assertTrue(find.get().toLowerCase().startsWith("h2:mem:test.my_table#" + row)); }
private void testJcasTable2(JCas jCas, int row) { JCasMetadata metadata = new JCasMetadata(jCas); Optional<String> find = metadata.find("resourceName").map(String::toLowerCase); assertTrue(find.get().startsWith("h2:mem:test.my_table2#" + row)); if (find.get().endsWith("ignore_me")) { assertEquals("IGNORE", jCas.getDocumentText()); } else { assertTrue(jCas.getDocumentText().startsWith("TEXT BLOCK")); } }
@Test public void testLongDocument() throws Exception { ExternalResourceDescription erd = ExternalResourceFactory.createExternalResourceDescription( STOPWORDS, SharedStopwordResource.class); AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( RakeKeywords.class, STOPWORDS, erd, RakeKeywords.PARAM_MAX_KEYWORDS, 12, RakeKeywords.PARAM_ADD_BUZZWORDS, true); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); jCas.setDocumentText( new String(Files.readAllBytes(Paths.get(getClass().getResource("turing.txt").toURI())))); ae.process(jCas); JCasMetadata metadata = new JCasMetadata(jCas); Optional<String> keyword = metadata.find(KEYWORD_METADATA_KEY); assertTrue(keyword.isPresent()); ae.destroy(); }