@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { LogFactory.getLog(getClass()).info("--- validating CAS with id [" + jcasId + "] ---"); boolean exists = JCasUtil.exists(aJCas, JCasId.class); if (!exists) { JCasId id = new JCasId(aJCas); id.setId(jcasId++); id.addToIndexes(); } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { LogFactory.getLog(getClass()).debug("--- validating CAS with id [" + jcasId + "] ---"); boolean exists = JCasUtil.exists(aJCas, JCasId.class); if (!exists) { JCasId id = new JCasId(aJCas); id.setId(jcasId++); id.addToIndexes(); } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { if (!featureMode.equals(Constants.FM_DOCUMENT)) { return; } if (JCasUtil.exists(aJCas, TextClassificationTarget.class)) { return; } TextClassificationTarget aTarget = new TextClassificationTarget(aJCas, 0, aJCas.getDocumentText().length()); aTarget.addToIndexes(); }
public static Drama getDrama(JCas jcas) { if (JCasUtil.exists(jcas, Drama.class)) { return JCasUtil.selectSingle(jcas, Drama.class); } else { Drama d = new Drama(jcas); d.addToIndexes(); return d; } }
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { if (!JCasUtil.exists(aJCas, DocumentMetaData.class)) DocumentMetaData.create(aJCas); DocumentMetaData.get(aJCas).setCollectionId(collectionId); }
@Override public void process(JCas arg0) throws AnalysisEngineProcessException { boolean exists = JCasUtil.exists(arg0, JCasId.class); if (!exists) { JCasId id = new JCasId(arg0); id.setId(jcasId++); id.addToIndexes(); } }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { if (!JCasUtil.exists(jcas, DocumentMetaData.class)) DocumentMetaData.create(jcas); if (documentId != null) DocumentMetaData.get(jcas).setDocumentId(documentId); if (documentTitle != null) DocumentMetaData.get(jcas).setDocumentTitle(documentTitle); }
@Test public void testCreateFieldAnnotationsFromSelectorFileWithRegexMissingRequired() throws AnalysisEngineProcessException, ResourceInitializationException, IOException { Path definitionFile = createGoodRecordDefinitionWithRegexRequiredAndMissing(); try { processJCas(TemplateAnnotator.PARAM_RECORD_DEFINITIONS_DIRECTORY, tempDirectory.toString()); assertFalse(JCasUtil.exists(jCas, TemplateField.class)); assertTrue(JCasUtil.exists(jCas, TemplateRecord.class)); } finally { Files.delete(definitionFile); } }
public static <T extends TOP> T getOrCreate(JCas jcas, Class<T> targetClass) { if (JCasUtil.exists(jcas, targetClass)) { return JCasUtil.selectSingle(jcas, targetClass); } else { T annotation = (T) jcas.getCas().createFS(JCasUtil.getType(jcas, targetClass)); jcas.getCas().addFsToIndexes(annotation); return annotation; } } }
public static <T extends TOP> T getOrCreate(JCas jcas, Class<T> targetClass) { if (JCasUtil.exists(jcas, targetClass)) { return JCasUtil.selectSingle(jcas, targetClass); } else { T annotation = jcas.getCas().createFS(JCasUtil.getType(jcas, targetClass)); jcas.getCas().addFsToIndexes(annotation); return annotation; } } }
public static <T extends TOP> T getOrCreate(JCas jcas, Class<T> targetClass) { if (JCasUtil.exists(jcas, targetClass)) { return JCasUtil.selectSingle(jcas, targetClass); } else { T annotation = jcas.getCas().createFS(JCasUtil.getType(jcas, targetClass)); jcas.getCas().addFsToIndexes(annotation); return annotation; } } }
@Test public void testMultipleElementsSelectedForField() throws AnalysisEngineProcessException, ResourceInitializationException, IOException { Path definitionFile = createBadRecordDefinition(); try { processJCas(TemplateAnnotator.PARAM_RECORD_DEFINITIONS_DIRECTORY, tempDirectory.toString()); assertRecordCoversParas2to4(); assertFalse(JCasUtil.exists(jCas, TemplateField.class)); } finally { Files.delete(definitionFile); } }
@Test public void testWhitelist() throws IOException, UIMAException { List<Class<? extends BaleenAnnotation>> whiteList = ImmutableList.<Class<? extends BaleenAnnotation>>of(Location.class); final JsonJCasConverter converter = createConverter(whiteList, Collections.emptyList()); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = converter.serialise(testUtil.getIn()); converter.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testBlacklist() throws IOException, UIMAException { List<Class<? extends BaleenAnnotation>> blackList = ImmutableList.<Class<? extends BaleenAnnotation>>of(Person.class); final JsonJCasConverter converter = createConverter(Collections.emptyList(), blackList); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = converter.serialise(testUtil.getIn()); converter.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testSerializeBlacklist() throws IOException, UIMAException { List<Class<? extends BaleenAnnotation>> blackList = ImmutableList.<Class<? extends BaleenAnnotation>>of(Person.class); final JsonJCasConverter serializer = createConverter(Collections.emptyList(), blackList); final JsonJCasConverter deserializer = createConverter(); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = serializer.serialise(testUtil.getIn()); deserializer.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testDeserializeBlacklist() throws IOException, UIMAException { List<Class<? extends BaleenAnnotation>> blackList = ImmutableList.<Class<? extends BaleenAnnotation>>of(Person.class); final JsonJCasConverter serializer = createConverter(); final JsonJCasConverter deserializer = createConverter(Collections.emptyList(), blackList); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = serializer.serialise(testUtil.getIn()); deserializer.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testSerializeWhitelist() throws IOException, UIMAException { List<Class<? extends BaleenAnnotation>> whiteList = ImmutableList.<Class<? extends BaleenAnnotation>>of(Location.class); final JsonJCasConverter serializer = createConverter(whiteList, Collections.emptyList()); final JsonJCasConverter deserializer = createConverter(); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = serializer.serialise(testUtil.getIn()); deserializer.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testDeserializeWhitelist() throws IOException, UIMAException { List<Class<? extends BaleenAnnotation>> whiteList = ImmutableList.<Class<? extends BaleenAnnotation>>of(Location.class); final JsonJCasConverter serializer = createConverter(); final JsonJCasConverter deserializer = createConverter(whiteList, Collections.emptyList()); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = serializer.serialise(testUtil.getIn()); deserializer.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testWhitelist() throws IOException, UIMAException { final JsonJCasConverter converter = createBuilder().withWhitelist(ImmutableList.of("Location")).build(); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = converter.serialise(testUtil.getIn()); converter.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }
@Test public void testBlacklist() throws IOException, UIMAException { final JsonJCasConverter converter = createBuilder().withBlacklist(ImmutableList.of("common.Person")).build(); JCasSerializationTester testUtil = new JCasSerializationTester(); final String json = converter.serialise(testUtil.getIn()); converter.deserialise(testUtil.getOut(), json); testUtil.assertTopLevel(); testUtil.assertLocationMatches(); assertFalse(JCasUtil.exists(testUtil.getOut(), Person.class)); }