@SuppressWarnings("unchecked") private Collection<Class<? extends BaleenAnnotation>> createList(Collection<String> types) { Collection<Class<? extends BaleenAnnotation>> list = new ArrayList<>(); for (String type : types) { list.add((Class<? extends BaleenAnnotation>) TypeUtils.getType(type, jCas)); } return list; } }
/** * Get the given structure classes from by name or return all classes if null or empty * * @param typeNames the types to get * @return the structure classes * @throws ResourceInitializationException */ public static Set<Class<? extends Structure>> getStructureClasses(String... typeNames) throws ResourceInitializationException { return TypeUtils.getTypeClasses(Structure.class, typeNames); }
/** * Build the structure hierarchy, by first collecting all the annotations. * * @param jCas the jCas * @param annotationTypes the annotations classes to use * @return the root structure node */ protected static <T extends Annotation> Node<T> buildRoot( JCas jCas, Set<Class<? extends T>> annotationTypes) { return build( TypeUtils.filterAnnotations( JCasUtil.select(jCas, BaleenAnnotation.class), annotationTypes)); }
/** @return the build {@link EntityGraphOptions} */ public EntityGraphOptions build() { if (typeClasses == null) { typeClasses = TypeUtils.getAnnotationClasses(Entity.class); } ValueStrategyProvider valueStrategyProvider = key -> valueStrategies.getOrDefault(key, defaultValueStrategy); return new EntityGraphOptions( contentHashAsId, outputEvents, multiValueProperties, ImmutableSet.copyOf(stopFeatures), typeClasses, valueStrategyProvider, ImmutableList.copyOf(aggregateProperties), valueCoercer); } }
@Test public void testTemporalEntity() throws UIMAException, BaleenException { JCas jCas = JCasSingleton.getJCasInstance(); Class<? extends Entity> c = TypeUtils.getEntityClass("Temporal", jCas); assertEquals(Temporal.class, c); }
Class<AnnotationBase> ret = getClassFromType("." + typeName, types); if (ret == null) { ret = getClassFromType(typeName, types);
/** @return the build {@link EntityGraphOptions} */ public EntityGraphOptions build() { if (typeClasses == null) { typeClasses = TypeUtils.getAnnotationClasses(Entity.class); } ValueStrategyProvider valueStrategyProvider = key -> valueStrategies.getOrDefault(key, defaultValueStrategy); return new EntityGraphOptions( contentHashAsId, outputEvents, multiValueProperties, ImmutableSet.copyOf(stopFeatures), typeClasses, valueStrategyProvider, ImmutableList.copyOf(aggregateProperties), valueCoercer); } }
@Test public void testRelationEntity() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); try { TypeUtils.getEntityClass("Relation", jCas); fail("Expected exception not found"); } catch (BaleenException e) { // Do nothing - exception expected } }
Class<AnnotationBase> ret = getClassFromType("." + typeName, types); if (ret == null) { ret = getClassFromType(typeName, types);
/** * For a given type name, look through the type system and return the matching class. If two types * of the same name (but different packages) exist, then null will be returned and the package * will need to be included in the typeName. * * @param typeName The name of the type, optionally including the package * @param jCas A JCas object containing the type system * @return The class associated with that type */ public static Class<? extends AnnotationBase> getType(String typeName, JCas jCas) { return getType(typeName, jCas.getTypeSystem()); }
/** * Get the given structure classes from by name or return all classes if null or empty * * @param typeNames the types to get * @return the structure classes * @throws ResourceInitializationException */ public static Set<Class<? extends Structure>> getStructureClasses(String... typeNames) throws ResourceInitializationException { return TypeUtils.getTypeClasses(Structure.class, typeNames); }
/** * Build the structure hierarchy, by first collecting all the annotations. * * @param jCas the jCas * @param annotationTypes the annotations classes to use * @return the root structure node */ protected static <T extends Annotation> Node<T> buildRoot( JCas jCas, Set<Class<? extends T>> annotationTypes) { return build( TypeUtils.filterAnnotations( JCasUtil.select(jCas, BaleenAnnotation.class), annotationTypes)); }
/** @return the build {@link DocumentGraphOptions} */ public DocumentGraphOptions build() { if (typeClasses == null) { typeClasses = TypeUtils.getAnnotationClasses(Entity.class); } return new DocumentGraphOptions( contentHashAsId, outputMeta, outputContent, outputDocument, outputReferents, outputRelations, outputRelationsAsLinks, outputEvents, ImmutableSet.copyOf(typeClasses), ImmutableSet.copyOf(stopFeatures), valueCoercer); } }
@Test public void testPersonEntity() throws UIMAException, BaleenException { JCas jCas = JCasSingleton.getJCasInstance(); Class<? extends Entity> c = TypeUtils.getEntityClass("Person", jCas); assertEquals(Person.class, c); }
/** * For a given type name, look through the type system and return the matching class. If two types * of the same name (but different packages) exist, then null will be returned and the package * will need to be included in the typeName. * * @param typeName The name of the type, optionally including the package * @param jCas A JCas object containing the type system * @return The class associated with that type */ public static Class<? extends AnnotationBase> getType(String typeName, JCas jCas) { return getType(typeName, jCas.getTypeSystem()); }
@Test public void testCanGetTypeClass() throws ResourceInitializationException { Set<Class<? extends Entity>> typeClasses = TypeUtils.getTypeClasses(Entity.class, new String[] {Person.class.getSimpleName()}); assertEquals(1, typeClasses.size()); assertTrue(typeClasses.contains(Person.class)); } }
/** * Build the covering index of baleen annotations by structure annotations (lazily) filtered to * only the given structural classes * * @param jCas the jCas * @param structuralClasses the structural classes * @return the covering index */ private static Map<Annotation, Collection<Structure>> buildCovering( JCas jCas, Set<Class<? extends Structure>> structuralClasses) { return Maps.transformValues( JCasUtil.indexCovering(jCas, BaleenAnnotation.class, Structure.class), s -> TypeUtils.filterAnnotations(s, structuralClasses)); } }
/** @return the build {@link DocumentGraphOptions} */ public DocumentGraphOptions build() { if (typeClasses == null) { typeClasses = TypeUtils.getAnnotationClasses(Entity.class); } return new DocumentGraphOptions( contentHashAsId, outputMeta, outputContent, outputDocument, outputReferents, outputRelations, outputRelationsAsLinks, outputEvents, ImmutableSet.copyOf(typeClasses), ImmutableSet.copyOf(stopFeatures), valueCoercer); } }
@Test public void testMissingEntity() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); try { TypeUtils.getEntityClass("Missing", jCas); fail("Expected exception not found"); } catch (BaleenException e) { // Do nothing - exception expected } }
private Type getType(String typeName) { Class<AnnotationBase> typeClass = TypeUtils.getType(typeName, typeSystem); return typeSystem.getType(typeClass.getCanonicalName()); }