use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.
the class AnnotationSchemaServiceImpl method getProjectTypes.
@Override
public TypeSystemDescription getProjectTypes(Project aProject) {
// Create a new type system from scratch
TypeSystemDescription tsd = new TypeSystemDescription_impl();
for (AnnotationLayer type : listAnnotationLayer(aProject)) {
if (type.getType().equals(SPAN_TYPE) && !type.isBuiltIn()) {
TypeDescription td = tsd.addType(type.getName(), "", CAS.TYPE_NAME_ANNOTATION);
generateFeatures(tsd, td, type);
} else if (type.getType().equals(RELATION_TYPE) && !type.isBuiltIn()) {
TypeDescription td = tsd.addType(type.getName(), "", CAS.TYPE_NAME_ANNOTATION);
AnnotationLayer attachType = type.getAttachType();
td.addFeature(WebAnnoConst.FEAT_REL_TARGET, "", attachType.getName());
td.addFeature(WebAnnoConst.FEAT_REL_SOURCE, "", attachType.getName());
generateFeatures(tsd, td, type);
} else if (type.getType().equals(CHAIN_TYPE) && !type.isBuiltIn()) {
TypeDescription tdChains = tsd.addType(type.getName() + "Chain", "", CAS.TYPE_NAME_ANNOTATION_BASE);
tdChains.addFeature("first", "", type.getName() + "Link");
// Custom features on chain layers are currently not supported
// generateFeatures(tsd, tdChains, type);
TypeDescription tdLink = tsd.addType(type.getName() + "Link", "", CAS.TYPE_NAME_ANNOTATION);
tdLink.addFeature("next", "", type.getName() + "Link");
tdLink.addFeature("referenceType", "", CAS.TYPE_NAME_STRING);
tdLink.addFeature("referenceRelation", "", CAS.TYPE_NAME_STRING);
}
}
return tsd;
}
use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.
the class SlotFeatureSupport method generateFeature.
@Override
public void generateFeature(TypeSystemDescription aTSD, TypeDescription aTD, AnnotationFeature aFeature) {
// Link type
TypeDescription linkTD = aTSD.addType(aFeature.getLinkTypeName(), "", CAS.TYPE_NAME_TOP);
linkTD.addFeature(aFeature.getLinkTypeRoleFeatureName(), "", CAS.TYPE_NAME_STRING);
linkTD.addFeature(aFeature.getLinkTypeTargetFeatureName(), "", aFeature.getType());
// Link feature
aTD.addFeature(aFeature.getName(), "", CAS.TYPE_NAME_FS_ARRAY, linkTD.getName(), false);
}
use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.
the class TypeSystemAnalysis method analyzeType.
private void analyzeType(TypeSystem aTS, TypeSystemDescription aTSD, TypeDescription aTD) {
log.trace("Analyzing [{}]", aTD.getName());
Type type = aTS.getType(aTD.getName());
// Skip built-in UIMA types
if (aTD.getName().startsWith("uima.tcas.")) {
log.debug("[{}] is a built-in UIMA type. Skipping.", aTD.getName());
return;
}
// Skip document metadata types
if (aTS.subsumes(aTS.getType(CAS.TYPE_NAME_DOCUMENT_ANNOTATION), type)) {
log.debug("[{}] is a document-level annotation. Skipping.", type.getName());
return;
}
// Skip DKPro Core Token and Sentence which as handled specially by WebAnno
if ("de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence".equals(aTD.getName()) || "de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token".equals(aTD.getName())) {
log.debug("[{}] is a DKPro Core segmentation type. Skipping.", aTD.getName());
return;
}
Optional<RelationDetails> relationDetails = analyzeRelationLayer(aTS, type);
Optional<ChainDetails> chainDetails = analyzeChainLayer(aTS, type);
boolean isChain = chainDetails.isPresent();
// Layers must be sub-types of Annotation (unless they are chains)
if (!isChain && !aTS.subsumes(aTS.getType(CAS.TYPE_NAME_ANNOTATION), type)) {
log.debug("[{}] is not an annotation type. Skipping.", aTD.getName());
return;
}
// because WebAnno presently does not support DKPro Core elevated types (e.g. NOUN).
if (isElevatedType(aTS, type)) {
log.debug("[{}] looks like an elevated type. Skipping.", aTD.getName());
return;
}
AnnotationLayer layer = new AnnotationLayer();
Optional<? extends LayerDetails> details;
if (isChain) {
details = chainDetails;
layer.setName(removeEnd(aTD.getName(), "Chain"));
layer.setUiName(removeEnd(type.getShortName(), "Chain"));
layer.setType(CHAIN_TYPE);
chainDetailMap.put(layer.getName(), chainDetails.get());
} else if (relationDetails.isPresent()) {
details = relationDetails;
layer.setName(aTD.getName());
layer.setUiName(type.getShortName());
layer.setType(RELATION_TYPE);
relationDetailMap.put(layer.getName(), relationDetails.get());
} else if (isSpanLayer(aTS, type)) {
details = Optional.empty();
layer.setName(aTD.getName());
layer.setUiName(type.getShortName());
layer.setType(SPAN_TYPE);
} else {
log.debug("Unable to determine layer type for [{}]", type.getName());
return;
}
log.debug("[{}] seems to be a {}", aTD.getName(), layer.getType());
layer.setDescription(trimToNull(aTD.getDescription()));
layer.setEnabled(true);
layer.setBuiltIn(false);
// We cannot determine good values for these without looking at actual annotations, thus
// we choose the most relaxed/permissive configuration here.
layer.setAllowStacking(true);
layer.setCrossSentence(true);
layer.setLockToTokenOffset(false);
layer.setMultipleTokens(false);
layer.setLinkedListBehavior(false);
layers.add(layer);
// any features for it - instead we record the features of the link type.
if (CHAIN_TYPE.equals(layer.getType())) {
TypeDescription linkTypeDescription = aTSD.getType(layer.getName() + "Link");
analyzeFeatures(layer, aTS, linkTypeDescription, details);
} else {
analyzeFeatures(layer, aTS, aTD, details);
}
}
use of org.apache.uima.resource.metadata.TypeDescription in project webanno by webanno.
the class DiffUtils method createMultiLinkWithRoleTestTypeSytem.
public static TypeSystemDescription createMultiLinkWithRoleTestTypeSytem(String... aFeatures) 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);
for (String feature : aFeatures) {
hostTD.addFeature(feature, "", CAS.TYPE_NAME_STRING);
}
typeSystems.add(tsd);
typeSystems.add(TypeSystemDescriptionFactory.createTypeSystemDescription());
return CasCreationUtils.mergeTypeSystems(typeSystems);
}
use of org.apache.uima.resource.metadata.TypeDescription 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);
}
Aggregations