@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; } }
/** * 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()); }
private Type getType(String typeName) { Class<AnnotationBase> typeClass = TypeUtils.getType(typeName, typeSystem); return typeSystem.getType(typeClass.getCanonicalName()); }
/** * 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()); }
private Type getType(String typeName) { Class<AnnotationBase> typeClass = TypeUtils.getType(typeName, typeSystem); return typeSystem.getType(typeClass.getCanonicalName()); }
/** * Get the class of a specified type, that extends from the Entity base class * * @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, which will extend from Entity * @throws BaleenException is thrown if a suitable class can't be found */ @SuppressWarnings("unchecked") public static Class<? extends Entity> getEntityClass(String typeName, JCas jCas) throws BaleenException { Class<? extends AnnotationBase> at = getType(typeName, jCas); if (at == null) { throw new BaleenException("Couldn't find type '" + typeName + "'"); } if (!Entity.class.isAssignableFrom(at)) { throw new BaleenException("Entity type '" + typeName + "' does not inherit from Entity"); } return (Class<? extends Entity>) at; }
/** * Get the class of a specified type, that extends from the Entity base class * * @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, which will extend from Entity * @throws BaleenException is thrown if a suitable class can't be found */ @SuppressWarnings("unchecked") public static Class<? extends Entity> getEntityClass(String typeName, JCas jCas) throws BaleenException { Class<? extends AnnotationBase> at = getType(typeName, jCas); if (at == null) { throw new BaleenException("Couldn't find type '" + typeName + "'"); } if (!Entity.class.isAssignableFrom(at)) { throw new BaleenException("Entity type '" + typeName + "' does not inherit from Entity"); } return (Class<? extends Entity>) at; }
@Test public void testPerson() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); Class<?> c = TypeUtils.getType("Person", jCas); assertEquals(Person.class, c); }
@Test public void testTemporal() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); Class<?> c = TypeUtils.getType("Temporal", jCas); assertEquals(Temporal.class, c); }
@Test public void testMissing() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); Class<?> c = TypeUtils.getType("Missing", jCas); assertEquals(null, c); }
@Test public void testRelation() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); Class<?> c = TypeUtils.getType("Relation", jCas); assertEquals(Relation.class, c); }