/** * Instantiates a new job settings. * * @param jCas the jcas */ public JobSettings(final JCas jCas) { this.jCas = jCas; metadata = new JCasMetadata(jCas); }
/** * 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); }
/** * Removes the data at the key * * @param key the key */ public void remove(final String key) { final Optional<Metadata> md = metadata.findMetadata(key); if (md.isPresent()) { md.get().removeFromIndexes(); } }
@Test public void testProcess() throws Exception { jCas.setDocumentText( new String(Files.readAllBytes(Paths.get(getClass().getResource("turing.txt").toURI())))); processJCas(KEY_STOPWORDS, erd, PARAM_STEMMING, "ENGLISH"); JCasMetadata metadata = new JCasMetadata(jCas); Set<String> keywords = metadata.findAll(KEYWORD_METADATA_KEY); assertEquals(5, keywords.size()); assertTrue(keywords.contains("machine")); assertTrue(keywords.contains("computer")); assertTrue(keywords.contains("digital computers")); assertTrue(keywords.contains("state")); // Same score so either is valid assertTrue(keywords.contains("question") || keywords.contains("digital")); assertTrue(JCasUtil.select(jCas, Buzzword.class).size() > 0); Set<String> buzzwords = new HashSet<>(); for (Buzzword bw : JCasUtil.select(jCas, Buzzword.class)) { assertEquals("keyword", bw.getTags(0)); buzzwords.add(bw.getValue()); } assertTrue(buzzwords.contains("machines")); assertTrue(buzzwords.contains("computing")); assertTrue(buzzwords.contains("questioning")); }
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)); }
@Test public void findKeyNoValues() { assertEquals(ImmutableSet.of(), metadata.findAll("missing")); }
/** * Find a value, if present, for the given metadata key * * @param key to search for * @return optional of the a value for the given key */ public Optional<String> find(String key) { Preconditions.checkNotNull(key); return findStream(key).findFirst(); }
/** * Find the metadata, if present, for the given metadata key * * @param key to search for * @return optional of the metadata for the given key */ public Optional<Metadata> findMetadata(String key) { Preconditions.checkNotNull(key); return findMetadataStream(key).findFirst(); }
@Test public void findKeys() { assertEquals(ImmutableSet.of(KEY1, KEY2), metadata.keys()); }
ae.process(jCas); JCasMetadata metadata1 = new JCasMetadata(jCas); Set<String> fullDocKeywords = metadata1.findAll(KEYWORD_METADATA_KEY); ae.process(jCas); JCasMetadata metadata2 = new JCasMetadata(jCas); Set<String> textKeywords = metadata2.findAll(KEYWORD_METADATA_KEY); assertFalse(textKeywords.isEmpty()); assertNotEquals(fullDocKeywords, textKeywords);
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 findKeyAllValues() { assertEquals(ImmutableSet.of(VALUE2, VALUE3), metadata.findAll(KEY2)); }
/** * Find a value, if present, for the given metadata key * * @param key to search for * @return optional of the a value for the given key */ public Optional<String> find(String key) { Preconditions.checkNotNull(key); return findStream(key).findFirst(); }
private Stream<String> findStream(String key) { return findMetadataStream(key).map(Metadata::getValue); }
processJCas(KEY_STOPWORDS, erd); JCasMetadata metadata = new JCasMetadata(jCas); Set<String> keywords = metadata.findAll(KEYWORD_METADATA_KEY);
@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(); }
/** * 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); }
/** * Instantiates a new job settings. * * @param jCas the jcas */ public JobSettings(final JCas jCas) { this.jCas = jCas; metadata = new JCasMetadata(jCas); }
/** * Removes the data at the key * * @param key the key */ public void remove(final String key) { final Optional<Metadata> md = metadata.findMetadata(key); if (md.isPresent()) { md.get().removeFromIndexes(); } }
/** * Find all values, if present, for the given metadata key * * @param key to search for * @return list of all the values for the given key */ public Set<String> findAll(String key) { Preconditions.checkNotNull(key); return findStream(key).collect(Collectors.toSet()); }