use of org.apache.uima.cas.Feature in project webanno by webanno.
the class WebAnnoCasUtil method setLinkFeature.
private static void setLinkFeature(FeatureStructure aFS, AnnotationFeature aFeature, List<LinkWithRoleModel> aValue, Feature feature) {
Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName());
Feature roleFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeRoleFeatureName());
Feature targetFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeTargetFeatureName());
// Create all the links
// FIXME: actually we could re-use existing link link feature structures
List<FeatureStructure> linkFSes = new ArrayList<>();
if (aValue != null) {
// remove duplicate links
Set<LinkWithRoleModel> links = new HashSet<>(aValue);
for (LinkWithRoleModel e : links) {
// set
if (e.targetAddr == -1) {
continue;
}
FeatureStructure link = aFS.getCAS().createFS(linkType);
link.setStringValue(roleFeat, e.role);
link.setFeatureValue(targetFeat, selectByAddr(aFS.getCAS(), e.targetAddr));
linkFSes.add(link);
}
}
setLinkFeatureValue(aFS, feature, linkFSes);
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class RemoteApiController2 method forceSetFeatureValue.
private static void forceSetFeatureValue(FeatureStructure aFS, String aFeatureName, String aValue) {
CASImpl casImpl = (CASImpl) aFS.getCAS().getLowLevelCAS();
TypeSystemImpl ts = (TypeSystemImpl) aFS.getCAS().getTypeSystem();
Feature feat = aFS.getType().getFeatureByBaseName(aFeatureName);
int featCode = ((FeatureImpl) feat).getCode();
int thisType = ((TypeImpl) aFS.getType()).getCode();
if (!ts.isApprop(thisType, featCode)) {
throw new IllegalArgumentException("Feature structure does not have that feature");
}
if (!ts.subsumes(ts.getType(CAS.TYPE_NAME_STRING), feat.getRange())) {
throw new IllegalArgumentException("Not a string feature!");
}
casImpl.ll_setStringValue(casImpl.ll_getFSRef(aFS), featCode, aValue);
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class TypeSystemAnalysis method analyzeRelationLayer.
private Optional<RelationDetails> analyzeRelationLayer(TypeSystem aTS, Type aType) {
// A UIMA type can be a relation layer if...
// ... there are exactly two non-primitive features
// ... both have the same range
// ... the range is a span layer
List<Feature> nonPrimitiveFeatures = aType.getFeatures().stream().filter(f -> !isBuiltInFeature(f)).filter(f -> !f.getRange().isPrimitive()).collect(Collectors.toList());
// ... there are exactly two non-primitive features
if (nonPrimitiveFeatures.size() != 2) {
return Optional.empty();
}
Feature ref1 = nonPrimitiveFeatures.get(0);
Feature ref2 = nonPrimitiveFeatures.get(1);
// Relations must use the names "Governor" and "Dependent" for its references because
// these names are hardcoded throughout WebAnno.
List<String> validNames = asList(FEAT_REL_SOURCE, FEAT_REL_TARGET);
if (!validNames.contains(ref1.getShortName()) || !validNames.contains(ref2.getShortName())) {
return Optional.empty();
}
// ... both have the same range
if (!ref1.getRange().getName().equals(ref2.getRange().getName())) {
return Optional.empty();
}
// Annotation should be fine.
if (!aTS.subsumes(aTS.getType(CAS.TYPE_NAME_ANNOTATION), ref1.getRange())) {
return Optional.empty();
}
RelationDetails details = new RelationDetails();
details.attachLayer = ref1.getRange().getName();
details.sourceFeature = WebAnnoConst.FEAT_REL_SOURCE;
details.targetFeature = WebAnnoConst.FEAT_REL_TARGET;
// Hm, ok, so this looks like a relation layer.
return Optional.of(details);
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class TypeSystemAnalysis method analyzeChainLayer.
private Optional<ChainDetails> analyzeChainLayer(TypeSystem aTS, Type aType) {
// DKPro Core CoreferenceChain - we expect that all chains follow this convention.
if (!aType.getName().endsWith("Chain")) {
return Optional.empty();
}
// There must be an initial chain feature. The name of this feature is currently
// hard-coded in WebAnno to the one used by the DKPro Core CoreferenceChain
Feature first = aType.getFeatureByBaseName("first");
if (first == null) {
return Optional.empty();
}
// The initial chain features must be a non-primitive
if (first.getRange().isPrimitive()) {
return Optional.empty();
}
// The chain link must contain a feature named "next" used to connect to the next link
Feature next = first.getRange().getFeatureByBaseName("next");
if (next == null || !next.getRange().equals(first.getRange())) {
return Optional.empty();
}
// AnnotationBase
if (!aTS.getParent(aType).equals(aTS.getType(CAS.TYPE_NAME_ANNOTATION_BASE))) {
return Optional.empty();
}
ChainDetails details = new ChainDetails();
details.nextFeature = "next";
// Hm, ok, so this looks like a chain layer.
return Optional.of(details);
}
use of org.apache.uima.cas.Feature in project webanno by webanno.
the class TypeSystemAnalysis method analyzeFeatures.
private void analyzeFeatures(AnnotationLayer aLayer, TypeSystem aTS, TypeDescription aTD, Optional<? extends LayerDetails> aDetails) {
Type type = aTS.getType(aTD.getName());
for (FeatureDescription fd : aTD.getFeatures()) {
Feature feat = type.getFeatureByBaseName(fd.getName());
// We do not need to set up built-in features
if (isBuiltInFeature(feat)) {
continue;
}
if (aDetails.isPresent() && aDetails.get().isHiddenFeature(feat)) {
continue;
}
AnnotationFeature f = analyzeFeature(aTS, fd, feat);
features.put(aLayer.getName(), f);
}
}
Aggregations