use of org.apache.uima.resource.metadata.TypeSystemDescription in project webanno by webanno.
the class DiffUtils method readXMI.
public static JCas readXMI(String aPath, TypeSystemDescription aType) throws UIMAException, IOException {
CollectionReader reader = createReader(XmiReader.class, XmiReader.PARAM_SOURCE_LOCATION, "src/test/resources/" + aPath);
JCas jcas;
if (aType != null) {
TypeSystemDescription builtInTypes = TypeSystemDescriptionFactory.createTypeSystemDescription();
List<TypeSystemDescription> allTypes = new ArrayList<>();
allTypes.add(builtInTypes);
allTypes.add(aType);
jcas = JCasFactory.createJCas(CasCreationUtils.mergeTypeSystems(allTypes));
} else {
jcas = JCasFactory.createJCas();
}
reader.getNext(jcas.getCas());
return jcas;
}
use of org.apache.uima.resource.metadata.TypeSystemDescription in project webanno by webanno.
the class DiffUtils method createMultiLinkWithRoleTestTypeSytem.
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem() throws Exception {
List<TypeSystemDescription> typeSystems = new ArrayList<>();
TypeSystemDescription tsd = new TypeSystemDescription_impl();
// Link type
TypeDescription linkTD = tsd.addType(LINK_TYPE, "", CAS.TYPE_NAME_TOP);
linkTD.addFeature("role", "", CAS.TYPE_NAME_STRING);
linkTD.addFeature("target", "", Token.class.getName());
// Link host
TypeDescription hostTD = tsd.addType(HOST_TYPE, "", CAS.TYPE_NAME_ANNOTATION);
hostTD.addFeature("links", "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
typeSystems.add(tsd);
typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());
return CasCreationUtils.mergeTypeSystems(typeSystems);
}
use of org.apache.uima.resource.metadata.TypeSystemDescription in project webanno by webanno.
the class CustomTypesTest method testProfType.
@Test
public void testProfType() throws Exception {
TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
CAS cas = CasCreationUtils.createCas(tsd, null, null);
cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes.");
TypeSystem ts = cas.getTypeSystem();
Type profType = ts.getType("de.tud.Prof");
Feature profNameFeature = profType.getFeatureByBaseName("fullName");
Feature profBossFeature = profType.getFeatureByBaseName("boss");
AnnotationFS proemel = cas.createAnnotation(profType, 0, 0);
proemel.setStringValue(profNameFeature, "Hans Juergen Proeml");
cas.addFsToIndexes(proemel);
AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38);
gurevych.setStringValue(profNameFeature, "Iryna Gurevych");
gurevych.setFeatureValue(profBossFeature, proemel);
cas.addFsToIndexes(gurevych);
for (String feature : Arrays.asList("fullName", "boss")) {
Feature someFeature = gurevych.getType().getFeatureByBaseName(feature);
if (someFeature.getRange().isPrimitive()) {
String value = gurevych.getFeatureValueAsString(someFeature);
System.out.println(value);
} else {
FeatureStructure value = gurevych.getFeatureValue(someFeature);
System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature), value.getType());
}
}
}
use of org.apache.uima.resource.metadata.TypeSystemDescription in project webanno by webanno.
the class WebAnnoTsv3WriterTestBase method makeJCas.
private static JCas makeJCas() throws UIMAException {
TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
TypeSystemDescription local = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath("src/test/resources/desc/type/webannoTestTypes.xml");
TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
JCas jcas = JCasFactory.createJCas(merged);
DocumentMetaData.create(jcas).setDocumentId("doc");
return jcas;
}
use of org.apache.uima.resource.metadata.TypeSystemDescription in project webanno by webanno.
the class Tsv3XSerializerTest method makeJCasOneSentence.
private JCas makeJCasOneSentence(String aText) throws UIMAException {
TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
TypeSystemDescription local = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath("src/test/resources/desc/type/webannoTestTypes.xml");
TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
JCas jcas = JCasFactory.createJCas(merged);
DocumentMetaData.create(jcas).setDocumentId("doc");
TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class, Sentence.class);
tb.buildTokens(jcas, aText);
// sentence break
for (Sentence s : select(jcas, Sentence.class)) {
s.removeFromIndexes();
}
// Add a new sentence covering the whole text
new Sentence(jcas, 0, jcas.getDocumentText().length()).addToIndexes();
return jcas;
}
Aggregations