Java Code Examples for org.apache.uima.cas.Type#getFeatureByBaseName()

The following examples show how to use org.apache.uima.cas.Type#getFeatureByBaseName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CASArtifact.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
CASArtifact(
    @Nullable LabelAdapters labelAdapters, CAS cas
) {
  this.labelAdapters = labelAdapters;
  this.cas = cas;

  TypeSystem typeSystem = cas.getTypeSystem();
  metadataType = typeSystem.getType("ArtifactMetadata");
  keyFeature = metadataType.getFeatureByBaseName("key");
  valueFeature = metadataType.getFeatureByBaseName("value");

  metadataCas = cas.getView("metadata");
  Type idType = typeSystem.getType("ArtifactID");
  Feature idFeat = idType.getFeatureByBaseName("artifactID");
  FSIndexRepository indexRepository = metadataCas.getIndexRepository();
  artifactID = indexRepository.getIndex("artifactID", idType).iterator().get()
      .getStringValue(idFeat);
  metadataIndex = indexRepository.getIndex("metadata", metadataType);

  casMetadata = new CASMetadata();
}
 
Example 2
Source File: RemoteStringMatchingNerRecommender.java    From inception with Apache License 2.0 6 votes vote down vote up
public String predict(String aPredictionRequestJson) throws IOException, UIMAException,
    SAXException, RecommendationException
{
    PredictionRequest request = deserializePredictionRequest(aPredictionRequestJson);
    CAS cas = deserializeCas(request.getDocument().getXmi(), request.getTypeSystem());

    // Only work on real annotations, not on predictions
    Type predictedType = CasUtil.getType(cas, recommender.getLayer().getName());
    Feature feature = predictedType.getFeatureByBaseName(FEATURE_NAME_IS_PREDICTION);

    for (AnnotationFS fs : CasUtil.select(cas, predictedType)) {
        if (fs.getBooleanValue(feature)) {
            cas.removeFsFromIndexes(fs);
        }
    }

    recommendationEngine.predict(context, cas);

    return buildPredictionResponse(cas);
}
 
Example 3
Source File: Tsv3XCasSchemaAnalyzer.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static boolean isRelationLayer(Type aType)
{
    Feature relSourceFeat = aType.getFeatureByBaseName(FEAT_REL_SOURCE);
    boolean hasSourceFeature = relSourceFeat != null && !isPrimitiveFeature(relSourceFeat);
    Feature relTargetFeat = aType.getFeatureByBaseName(FEAT_REL_TARGET);
    boolean hasTargetFeature = relTargetFeat != null && !isPrimitiveFeature(relTargetFeat);
    
    boolean compatible = true;
    for (Feature feat : aType.getFeatures()) {
        if (
                CAS.FEATURE_BASE_NAME_SOFA.equals(feat.getShortName()) ||
                FEAT_REL_SOURCE.equals(feat.getShortName()) || 
                FEAT_REL_TARGET.equals(feat.getShortName())
        ) {
            continue;
        }
        
        if (!isPrimitiveFeature(feat)) {
            compatible = false;
            //LOG.debug("Incompatible feature in type [" + aType + "]: " + feat);
            break;
        }
    }
    
    return hasSourceFeature && hasTargetFeature && compatible;
}
 
Example 4
Source File: RunAE.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Entity process complete.
 *
 * @param aCas the a cas
 * @param aStatus the a status
 * @see org.apache.uima.collection.StatusCallbackListener#entityProcessComplete(org.apache.uima.cas.CAS,
 *      org.apache.uima.collection.EntityProcessStatus)
 */
public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
  if (aStatus.isException()) {
    Iterator iter = aStatus.getExceptions().iterator();
    while (iter.hasNext()) {
      ((Throwable) iter.next()).printStackTrace();
    }
  } else if (genProgressMessages) {
    // retrieve the filename of the input file from the CAS
    // (it was put there by the FileSystemCollectionReader)
    if (!(xcasInput || xmiInput)) {
      Type fileLocType = aCas.getTypeSystem().getType(
              "org.apache.uima.examples.SourceDocumentInformation");
      Feature fileNameFeat = fileLocType.getFeatureByBaseName("uri");
      FSIterator it = aCas.getAnnotationIndex(fileLocType).iterator();
      FeatureStructure fileLoc = it.get();
      File inFile = new File(fileLoc.getStringValue(fileNameFeat));
      System.out.println("Processed Document " + inFile.getName());
    } else {
      System.out.println("doc" + docsProcessed++ + " processed successfully");
    }
  }
}
 
Example 5
Source File: CasOutputDestination.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
@Override
public void controlWordEncountered(KeywordAction keywordAction) {
  AnnotationFS annotation;
  int currentTextIndex = sofaBuilder.length();
  String controlWord = keywordAction.getControlWord();

  Type type;
  if (annotationTypeForControlWord.containsKey(controlWord)) {
    type = annotationTypeForControlWord.get(controlWord);
  } else {
    return;
  }
  annotation = destinationView.createAnnotation(type, currentTextIndex,
      currentTextIndex);
  Feature paramFeature = type.getFeatureByBaseName("param");
  if (keywordAction.hasParameter()) {
    annotation.setIntValue(paramFeature, keywordAction.getParameter());
  }
  Feature indexFeature = type.getFeatureByBaseName("index");
  annotation.setIntValue(indexFeature, keywordAction.getBegin());
  Feature knownFeature = type.getFeatureByBaseName("known");
  annotation.setBooleanValue(knownFeature, true);

  destinationView.addFsToIndexes(annotation);
}
 
Example 6
Source File: CasMergeTest.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Test
public void copyLinkToEmptyTest()
    throws Exception
{
    JCas mergeCas = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    Type type = mergeCas.getTypeSystem().getType(CurationTestUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");

    AnnotationFS mergeFs = makeLinkHostMultiSPanFeatureFS(mergeCas, 0, 0, feature, "A");

    FeatureStructure copyFS = CurationTestUtils.makeLinkFS(mergeCas, "slot1", 0, 0);

    List<FeatureStructure> linkFs = new ArrayList<>();
    linkFs.add(copyFS);
    WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);

    JCas jcasA = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A",
            makeLinkFS(jcasA, "slot1", 0, 0));

    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(mergeCas.getCas()));
    casByUser.put("user2", asList(jcasA.getCas()));

    DiffResult diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();

    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
}
 
Example 7
Source File: XmiCompare.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void v2FixupMentionType_mi(String t, CASImpl cas) {
  TypeSystem ts = cas.getTypeSystem();
  Type type = ts.getType(t);
  Feature f_mentionType = type.getFeatureByBaseName("mentionType");
  Feature f_componentId = type.getFeatureByBaseName("componentId");
  cas.select(type)
     .allViews()
     .filter(fs -> "R2/2.2.2/Main/UNITOFM/_mi".equals(fs.getStringValue(f_componentId)))
     .forEach(fs -> {
         fs.setStringValue(f_componentId, "R2/2.2.2/Main/UNITOFM/_mile");
         fs.setStringValue(f_mentionType, "CATEGORY");
       });
}
 
Example 8
Source File: SpanAdapter.java    From webanno with Apache License 2.0 5 votes vote down vote up
/**
 * A Helper method to add annotation to CAS
 */
private AnnotationFS createSpanAnnotation(CAS aCas, int aBegin, int aEnd)
    throws AnnotationException
{
    Type type = CasUtil.getType(aCas, getAnnotationTypeName());
    AnnotationFS newAnnotation = aCas.createAnnotation(type, aBegin, aEnd);

    log.trace("Created span annotation {}-{} [{}]", newAnnotation.getBegin(),
            newAnnotation.getEnd(), newAnnotation.getCoveredText());

    // If if the layer attaches to a feature, then set the attach-feature to the newly
    // created annotation.
    if (getAttachFeatureName() != null) {
        Type theType = CasUtil.getType(aCas, getAttachTypeName());
        Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
        if (CasUtil.selectCovered(aCas, theType, aBegin, aEnd).isEmpty()) {
            throw new IllegalPlacementException("No annotation of type [" + getAttachTypeName()
                    + "] to attach to at location [" + aBegin + "-" + aEnd + "].");
        }
        CasUtil.selectCovered(aCas, theType, aBegin, aEnd).get(0)
                .setFeatureValue(attachFeature, newAnnotation);
    }
    
    aCas.addFsToIndexes(newAnnotation);
    
    return newAnnotation;
}
 
Example 9
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
public static <T extends FeatureStructure> T createIntegerList(CAS aCas, int... aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

  Type emptyType = ts.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST);

  if (aValues.length == 0) {
    return aCas.createFS(emptyType);
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST);
  Feature headFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
  Feature tailFeature = nonEmptyType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);

  FeatureStructure head = aCas.createFS(nonEmptyType);
  FeatureStructure list = head;
  int i = 0;
  while (i < aValues.length) {
    head.setIntValue(headFeature, aValues[i]);
    i++;
    if (i < aValues.length) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.createFS(emptyType));
    }
  }

  return (T) list;
}
 
Example 10
Source File: ExternalRecommenderIntegrationTest.java    From inception with Apache License 2.0 5 votes vote down vote up
private void createNamedEntity(CAS aCas, String aValue)
{
    Type neType = getType(aCas, "de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity");
    Feature valueFeature = neType.getFeatureByBaseName("value");
    AnnotationFS ne = aCas.createAnnotation(neType, 0, 42);
    ne.setStringValue(valueFeature, aValue);
    aCas.addFsToIndexes(ne);
}
 
Example 11
Source File: CasCompare.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private List<Runnable> type_feature_to_runnable(CASImpl cas, String typeName, String featureBaseName, BiFunction<TOP, Feature, Runnable> c) {
  TypeSystem ts = cas.getTypeSystem();
  Type type = ts.getType(typeName);
  Feature feat = type.getFeatureByBaseName(featureBaseName);
  return cas.select(type).allViews().map((TOP fs) ->
     c.apply(fs, feat)).collect(Collectors.toList());
}
 
Example 12
Source File: StringMatchingRecommender.java    From inception with Apache License 2.0 5 votes vote down vote up
private List<Sample> extractData(List<CAS> aCasses, String aLayerName, String aFeatureName)
{
    long start = System.currentTimeMillis();
    
    List<Sample> data = new ArrayList<>();
    
    int docNo = 0;
    for (CAS cas : aCasses) {
        Type sentenceType = getType(cas, Sentence.class);
        Type tokenType = getType(cas, Token.class);
        Type annotationType = getType(cas, aLayerName);
        Feature predictedFeature = annotationType.getFeatureByBaseName(aFeatureName);
        
        for (AnnotationFS sentence : select(cas, sentenceType)) {
            List<Span> spans = new ArrayList<>();
            
            for (AnnotationFS annotation : selectCovered(annotationType, sentence)) {
                String label = annotation.getFeatureValueAsString(predictedFeature);
                if (isNotEmpty(label)) {
                    spans.add(new Span(annotation.getBegin(), annotation.getEnd(),
                            annotation.getCoveredText(),
                            annotation.getFeatureValueAsString(predictedFeature), -1.0));
                }
            }
            
            Collection<AnnotationFS> tokens = selectCovered(tokenType, sentence);

            data.add(new Sample(docNo, cas.getDocumentText(), tokens, spans));
        }
        
        docNo++;
    }
    
    log.trace("Extracting data took {}ms", System.currentTimeMillis() - start);
    
    return data;
}
 
Example 13
Source File: PropertyCasMapping.java    From biomedicus with Apache License 2.0 5 votes vote down vote up
@Nullable
AnnotationFS getAnnotation(CAS cas, int begin, int end, int value) {
  if (begin < 0) {
    throw new IllegalArgumentException("Begin: " + begin + "before 0.");
  }

  if (end < begin) {
    throw new IllegalArgumentException(
        annotationClassName + " - illegal annotation span at begin: " + begin
            + " end: " + end);
  }

  if (!zeroLengthEmitted && end == begin) {
    return null;
  }

  TypeSystem typeSystem = cas.getTypeSystem();
  Type type = typeSystem.getType(annotationClassName);
  if (type == null) {
    throw new IllegalStateException("Annotation class not found: " + annotationClassName);
  }
  AnnotationFS annotation = cas.createAnnotation(type, begin, end);
  if (valueIncluded) {
    Feature valueFeature = type.getFeatureByBaseName("value");
    annotation.setIntValue(valueFeature, value);
  }
  return annotation;
}
 
Example 14
Source File: SubjectObjectFeatureSupport.java    From inception with Apache License 2.0 5 votes vote down vote up
@Override
public ArrayList<LinkWithRoleModel> wrapFeatureValue(AnnotationFeature aFeature, CAS aCAS,
        Object aValue)
{
    if (aValue instanceof ArrayFS) {
        ArrayFS array = (ArrayFS) aValue;

        Type linkType = aCAS.getTypeSystem().getType(aFeature.getLinkTypeName());
        Feature roleFeat = linkType.getFeatureByBaseName(aFeature.getLinkTypeRoleFeatureName());
        Feature targetFeat = linkType
                .getFeatureByBaseName(aFeature.getLinkTypeTargetFeatureName());

        ArrayList<LinkWithRoleModel> links = new ArrayList<>();
        for (FeatureStructure link : array.toArray()) {
            LinkWithRoleModel m = new LinkWithRoleModel();
            m.role = link.getStringValue(roleFeat);
            m.targetAddr = WebAnnoCasUtil.getAddr(link.getFeatureValue(targetFeat));
            m.label = ((AnnotationFS) link.getFeatureValue(targetFeat))
                .getCoveredText();
            links.add(m);
        }
        
        return links;
    }
    else if (aValue == null ) {
        return new ArrayList<>();
    }
    else {
        throw new IllegalArgumentException(
                "Unable to handle value [" + aValue + "] of type [" + aValue.getClass() + "]");
    }
}
 
Example 15
Source File: WideLeftAnnotationSideAction.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Widens the annotation and sends and sends an update notification
 * to the provided document.
 *
 * @param document the document
 * @param annotation the annotation
 */
public static void wideLeftAnnotationSide(ICasDocument document, AnnotationFS annotation) {
  Type annotationType = annotation.getType();
  Feature beginFeature = annotationType.getFeatureByBaseName("begin");

  if (annotation.getBegin() > 0) {
    annotation.setIntValue(beginFeature, annotation.getBegin() - 1);
  }

  document.update(annotation);
}
 
Example 16
Source File: CasMergeTest.java    From webanno with Apache License 2.0 4 votes vote down vote up
@Test
public void simpleCopyRelationToEmptyAnnoTest()
    throws Exception
{
    CAS jcas = createJCas().getCas();
    Type type = jcas.getTypeSystem().getType(Dependency.class.getTypeName());

    AnnotationFS originClickedToken = createTokenAnno(jcas, 0, 0);
    AnnotationFS targetClickedToken = createTokenAnno(jcas, 1, 1);

    AnnotationFS originClicked = createPOSAnno(jcas, "NN", 0, 0);
    AnnotationFS targetClicked = createPOSAnno(jcas, "NN", 1, 1);

    jcas.addFsToIndexes(originClicked);
    jcas.addFsToIndexes(targetClicked);

    originClickedToken.setFeatureValue(originClickedToken.getType().getFeatureByBaseName("pos"),
            originClicked);
    targetClickedToken.setFeatureValue(targetClickedToken.getType().getFeatureByBaseName("pos"),
            targetClicked);

    Feature sourceFeature = type.getFeatureByBaseName(FEAT_REL_SOURCE);
    Feature targetFeature = type.getFeatureByBaseName(FEAT_REL_TARGET);

    AnnotationFS clickedFs = jcas.createAnnotation(type, 0, 1);
    clickedFs.setFeatureValue(sourceFeature, originClickedToken);
    clickedFs.setFeatureValue(targetFeature, targetClickedToken);
    jcas.addFsToIndexes(clickedFs);

    CAS mergeCAs = createJCas().getCas();
    AnnotationFS origin = createPOSAnno(mergeCAs, "NN", 0, 0);
    AnnotationFS target = createPOSAnno(mergeCAs, "NN", 1, 1);

    mergeCAs.addFsToIndexes(origin);
    mergeCAs.addFsToIndexes(target);

    AnnotationFS originToken = createTokenAnno(mergeCAs, 0, 0);
    AnnotationFS targetToken = createTokenAnno(mergeCAs, 1, 1);
    originToken.setFeatureValue(originToken.getType().getFeatureByBaseName("pos"), origin);
    targetToken.setFeatureValue(targetToken.getType().getFeatureByBaseName("pos"), target);

    mergeCAs.addFsToIndexes(originToken);
    mergeCAs.addFsToIndexes(targetToken);

    sut.mergeRelationAnnotation(null, null, depLayer, mergeCAs, clickedFs, false);
    
    assertEquals(1, selectCovered(mergeCAs, type, 0, 1).size());
}
 
Example 17
Source File: AnnotationSchemaServiceImpl.java    From webanno with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the current CAS already contains the required type system.
 */
private boolean isUpgradeRequired(CAS aCas, TypeSystemDescription aTargetTypeSystem)
{
    TypeSystem ts = aCas.getTypeSystem();
    boolean upgradeRequired = false;
    nextType: for (TypeDescription tdesc : aTargetTypeSystem.getTypes()) {
        Type t = ts.getType(tdesc.getName());
        
        // Type does not exist
        if (t == null) {
            log.debug("CAS update required: type {} does not exist", tdesc.getName());
            upgradeRequired = true;
            break nextType;
        }
        
        // Super-type does not match
        if (!Objects.equals(tdesc.getSupertypeName(), ts.getParent(t).getName())) {
            log.debug("CAS update required: supertypes of {} do not match: {} <-> {}",
                    tdesc.getName(), tdesc.getSupertypeName(), ts.getParent(t).getName());
            upgradeRequired = true;
            break nextType;
        }
        
        // Check features
        for (FeatureDescription fdesc : tdesc.getFeatures()) {
            Feature f = t.getFeatureByBaseName(fdesc.getName());
            
            // Feature does not exist
            if (f == null) {
                log.debug("CAS update required: feature {} on type {} does not exist",
                        fdesc.getName(), tdesc.getName());
                upgradeRequired = true;
                break nextType;
            }
            
            // Range does not match
            if (CAS.TYPE_NAME_FS_ARRAY.equals(fdesc.getRangeTypeName())) {
                if (!Objects.equals(fdesc.getElementType(),
                        f.getRange().getComponentType().getName())) {
                    log.debug(
                            "CAS update required: ranges of feature {} on type {} do not match: {} <-> {}",
                            fdesc.getName(), tdesc.getName(), fdesc.getRangeTypeName(),
                            f.getRange().getName());
                    upgradeRequired = true;
                    break nextType;
                }
            }
            else {
                if (!Objects.equals(fdesc.getRangeTypeName(), f.getRange().getName())) {
                    log.debug(
                            "CAS update required: ranges of feature {} on type {} do not match: {} <-> {}",
                            fdesc.getName(), tdesc.getName(), fdesc.getRangeTypeName(),
                            f.getRange().getName());
                    upgradeRequired = true;
                    break nextType;
                }
            }
        }
    }
    
    return upgradeRequired;
}
 
Example 18
Source File: SofaExampleAnnotator.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void process(CAS aCas) throws AnalysisEngineProcessException {
  CAS englishView, germanView;

  // get the CAS view for the English document
  englishView = aCas.getView("EnglishDocument");

  // Create the German text Sofa and open its view
  germanView = aCas.createView("GermanDocument");

  // Get some necessary Type System constants
  Type annot = englishView.getAnnotationType();
  Type cross = englishView.getTypeSystem().getType("sofa.test.CrossAnnotation");
  Feature other = cross.getFeatureByBaseName("otherAnnotation");

  // Get the English text
  String engText = englishView.getDocumentText();

  // Setup for translated text
  int engEnd = 0;
  int germBegin = 0;
  int germEnd = 0;
  StringBuffer translation = new StringBuffer();

  // Parse the English text
  StringTokenizer st = new StringTokenizer(engText);
  while (st.hasMoreTokens()) {
    String thisTok = st.nextToken();
    int engBegin = engText.indexOf(thisTok, engEnd);
    engEnd = engBegin + thisTok.length();

    // Create token annotations on English text
    AnnotationFS engAnnot = englishView.createAnnotation(annot, engBegin, engEnd);
    englishView.addFsToIndexes(engAnnot);

    // Simple word-by-word translation
    String germWord = translate(thisTok);

    // Accumulate the translated text
    if (germBegin > 0) {
      translation.append(' ');
      germBegin += 1;
    }
    translation.append(germWord);

    // Create token annotations on German text
    germEnd = germBegin + germWord.length();
    AnnotationFS germAnnot = germanView.createAnnotation(cross, germBegin, germEnd);
    germanView.addFsToIndexes(germAnnot);

    // add link to English text
    germAnnot.setFeatureValue(other, engAnnot);
    germBegin = germEnd;
  }

  // Finally, set the output tranlation Sofa data
  germanView.setDocumentText(translation.toString());

}
 
Example 19
Source File: RelationOverlapBehavior.java    From webanno with Apache License 2.0 4 votes vote down vote up
@Override
public CreateRelationAnnotationRequest onCreate(RelationAdapter aAdapter,
        CreateRelationAnnotationRequest aRequest)
    throws AnnotationException
{
    final AnnotationLayer layer = aAdapter.getLayer();
    final CAS cas = aRequest.getCas();
    final Type type = getType(cas, layer.getName());
    final Feature targetFeature = type.getFeatureByBaseName(aAdapter.getTargetFeatureName());
    final Feature sourceFeature = type.getFeatureByBaseName(aAdapter.getSourceFeatureName());
    
    switch (layer.getOverlapMode()) {
    case ANY_OVERLAP:
        return aRequest;
    case NO_OVERLAP: {
        boolean hasAnyOverlapping = select(cas, type).stream()
            // Check if any of the end-points of the requested relation are already used as
            // end-points in another relation
            .filter(rel -> overlapping(aRequest, rel, sourceFeature, targetFeature))
            .findAny().isPresent();
        
        if (hasAnyOverlapping) {
            throw new IllegalPlacementException("Cannot create another annotation of layer ["
                    + layer.getUiName()
                    + "] at this location - no overlap or stacking is allowed for this layer.");
        }
        break;
    }
    case OVERLAP_ONLY: {
        boolean hasStacking = select(cas, type).stream()
            // Check if the requested relation has the same end-points as an existing
            // relation
            .filter(rel -> stacking(aRequest, rel, sourceFeature, targetFeature))
            .findAny().isPresent();
        
        if (hasStacking) {
            throw new IllegalPlacementException("Cannot create another annotation of layer ["
                    + layer.getUiName()
                    + "] at this location - stacking is not allowed for this layer.");
        }
        break;
    }
    case STACKING_ONLY: {
        boolean hasOverlapping = select(cas, type).stream()
            .filter(rel -> 
                overlapping(aRequest, rel, sourceFeature, targetFeature) &&
                !stacking(aRequest, rel, sourceFeature, targetFeature))
            .findAny().isPresent();
        
        if (hasOverlapping) {
            throw new IllegalPlacementException("Cannot create another annotation of layer ["
                    + layer.getUiName()
                    + "] at this location - only stacking is allowed for this layer.");
        }
        break;
    }
    }

    return aRequest;
}
 
Example 20
Source File: TsvColumn.java    From webanno with Apache License 2.0 4 votes vote down vote up
public TsvColumn(int aIndex, Type aUimaType, LayerType aLayerType, String aUimaFeatureName,
        FeatureType aFeatureType)
{
    this(aIndex, aUimaType, aLayerType, aUimaType.getFeatureByBaseName(aUimaFeatureName),
            aFeatureType);
}