Java源码示例:org.apache.uima.cas.Feature

示例1
/**
 * Recursively collect referenced FSes and also record for each the last indexed FS that refers
 * the them.
 */
public static void collect(Map<FeatureStructure, FeatureStructure> aFSes,
        Set<FeatureStructure> aIndexed, FeatureStructure aFS, FeatureStructure aLastIndexed)
{
    if (aFS != null && !aFSes.containsKey(aFS)) {
        // We might find an annotation indirectly. In that case make sure we consider it as 
        // an indexed annotation instead of wrongly recording it as non-indexed
        if (aIndexed.contains(aFS)) {
            aFSes.put(aFS, aFS);
        }
        else {
            aFSes.put(aFS, aLastIndexed);
        }

        for (Feature f : aFS.getType().getFeatures()) {
            if (!f.getRange().isPrimitive()
                    && !CAS.FEATURE_BASE_NAME_SOFA.equals(f.getShortName())) {
                collect(aFSes, aIndexed, aFS.getFeatureValue(f),
                        aIndexed.contains(aFS) ? aFS : aLastIndexed);
            }
        }
    }
}
 
示例2
@Override
public void predict(RecommenderContext aContext, CAS aCas) throws RecommendationException
{
    Trie<DictEntry> dict = aContext.get(KEY_MODEL).orElseThrow(() -> 
            new RecommendationException("Key [" + KEY_MODEL + "] not found in context"));

    Type predictedType = getPredictedType(aCas);
    Feature predictedFeature = getPredictedFeature(aCas);
    Feature isPredictionFeature = getIsPredictionFeature(aCas);
    Feature scoreFeature = getScoreFeature(aCas);

    List<Sample> data = predict(0, aCas, dict);
    
    for (Sample sample : data) {
        for (Span span : sample.getSpans()) {
            AnnotationFS annotation = aCas.createAnnotation(predictedType, span.getBegin(),
                    span.getEnd());
            annotation.setStringValue(predictedFeature, span.getLabel());
            annotation.setDoubleValue(scoreFeature, span.getScore());
            annotation.setBooleanValue(isPredictionFeature, true);
            aCas.addFsToIndexes(annotation);
        }
    }
}
 
示例3
private static List<String> getAnnotation(TypeAdapter aAdapter, AnnotationFS aSentence,
        AnnotationFeature aFeature)
{
    CAS cas = aSentence.getCAS();
    
    Type type = getType(cas, aAdapter.getAnnotationTypeName());
    List<String> annotations = new ArrayList<>();

    for (AnnotationFS token : selectTokensCovered(aSentence)) {
        List<AnnotationFS> tokenLevelAnnotations = selectCovered(type, token);
        if (tokenLevelAnnotations.size() > 0) {
            AnnotationFS anno = tokenLevelAnnotations.get(0);
            Feature labelFeature = anno.getType().getFeatureByBaseName(aFeature.getName());
            annotations.add(anno.getFeatureValueAsString(labelFeature));
        }
        else {
            annotations.add(NILL);
        }
    }
    return annotations;
}
 
示例4
/**
 * 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");
    }
  }
}
 
示例5
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();
}
 
示例6
@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);
}
 
示例7
@Override
public boolean verify(FeatureStructure featureStructure, ParsedConstraints parsedConstraints)
{

    boolean isOk = false;
    Type type = featureStructure.getType();
    for (Feature feature : type.getFeatures()) {
        if (feature.getRange().isPrimitive()) {
            String scopeName = featureStructure.getFeatureValueAsString(feature);
            List<Rule> rules = parsedConstraints.getScopeByName(scopeName).getRules();

            // Check if all the feature values are ok according to the
            // rules;
        }
        else {
            // Here some recursion would be in order
        }
    }
    return isOk;
}
 
示例8
public static Object integerListToArray(FeatureStructure fs) {
  List<Integer> list = new ArrayList<>();
  TypeSystem ts = fs.getCAS().getTypeSystem();
  Type emptyFSList = ts.getType("uima.cas.EmptyIntegerList");
  Feature headFeature = ts.getFeatureByFullName("uima.cas.NonEmptyIntegerList:head");
  Feature tailFeature = ts.getFeatureByFullName("uima.cas.NonEmptyIntegerList:tail");

  Set<FeatureStructure> alreadySeen = new HashSet<>();
  FeatureStructure nextFs;
  for (FeatureStructure currentFs = fs; currentFs.getType() != emptyFSList; currentFs = nextFs) {
    list.add(currentFs.getIntValue(headFeature));
    nextFs = currentFs.getFeatureValue(tailFeature);
    if (alreadySeen.contains(nextFs)) {
      return loopInList(list);
    }
    alreadySeen.add(nextFs);
  }
  int[] intArray = new int[list.size()];
  for (int i = 0; i < intArray.length; i++) {
    intArray[i] = list.get(i);
  }
  return intArray;
}
 
示例9
private void populateFeaturesForAnnotation(
    final JCas jCas,
    final BaleenAnnotation annotation,
    final Map<String, Object> map,
    final List<ReferencedFeatures> featuresToDereference) {
  for (final Feature f : annotation.getType().getFeatures()) {
    try {
      populateFeature(jCas, map, annotation, f, featuresToDereference);
    } catch (final Exception e) {
      getMonitor()
          .warn(
              "Couldn't populate {} to map. Type '{}' isn't supported.",
              f.getName(),
              f.getRange().getShortName(),
              e);
    }
  }
}
 
示例10
private AnnotationFS createRelationAnnotation(CAS cas, AnnotationFS originFS,
        AnnotationFS targetFS)
    throws AnnotationException
{
    if (targetFS == null || originFS == null) {
        throw new IllegalPlacementException("Relation must have a source and a target!");
    }

    // Set the relation offsets in DKPro Core style - the relation recieves the offsets from
    // the dependent
    // If origin and target spans are multiple tokens, dependentFS.getBegin will be the
    // the begin position of the first token and dependentFS.getEnd will be the End
    // position of the last token.
    final Type type = getType(cas, getLayer().getName());
    final Feature dependentFeature = type.getFeatureByBaseName(targetFeatureName);
    final Feature governorFeature = type.getFeatureByBaseName(sourceFeatureName);

    AnnotationFS newAnnotation = cas.createAnnotation(type, targetFS.getBegin(),
            targetFS.getEnd());
    newAnnotation.setFeatureValue(dependentFeature, targetFS);
    newAnnotation.setFeatureValue(governorFeature, originFS);
    cas.addFsToIndexes(newAnnotation);
    return newAnnotation;
}
 
示例11
/**
 * 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)
 */
@Override
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");
    }
  }
}
 
示例12
@Test
public void testStringArrayToObject() {
  DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs();
  StringArray rel = new StringArray(jCas, 3);
  rel.set(0, "true");
  rel.set(1, "2");
  rel.set(2, "0.45");
  da.setDocumentReleasability(rel);

  Feature f = da.getType().getFeatureByBaseName(DOCUMENT_RELEASABILITY);

  Object[] o = FeatureUtils.featureToArray(f, da);
  assertEquals(3, o.length);
  assertTrue(o[0] instanceof Boolean);
  assertTrue((Boolean) o[0]);
  assertTrue(o[1] instanceof Integer);
  assertEquals(new Integer(2), (Integer) o[1]);
  assertTrue(o[2] instanceof Double);
  assertEquals(new Double(0.45), (Double) o[2]);
}
 
示例13
private void subStringRangeCheck(Feature feat, String v) {
  Type range = feat.getRange();
  if (range instanceof TypeImpl_stringSubtype) {
    if (v != null) { // null values always OK
      ((TypeImpl_stringSubtype)range).validateIsInAllowedValues(v);
    }
  }     
}
 
示例14
private static void requireSingleValue(Feature aFeature, Object aArray)
{
  if (aArray == null) {
    throw new IllegalArgumentException("Cannot set [" + aFeature.getName() + "] to a null value.");
  }
  
  if (Array.getLength(aArray) != 1) {
    throw new IllegalArgumentException("Feature [" + aFeature.getName()
            + "] requires a single value but got " + asList(aArray));
  }
}
 
示例15
private void applyToTypeFeature_inner(CASImpl cas, String typeName, String featureBaseName, Consumer2<TOP, Feature> c) {
  TypeSystem ts = cas.getTypeSystem();
  Type type = ts.getType(typeName);
  Feature feat = type.getFeatureByBaseName(featureBaseName);
  
  cas.select(type).allViews().forEach(fs -> c.accept2(fs, feat));
  
}
 
示例16
@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() + "]");
    }
}
 
示例17
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages)
{
    Set<FeatureStructure> nonIndexed = getNonIndexedFSes(aCas);
    
    Set<FeatureStructure> toDelete = new LinkedHashSet<>();
    
    for (AnnotationFS fs : aCas.getAnnotationIndex()) {
        Type t = fs.getType();
        
        Feature sourceFeat = t.getFeatureByBaseName(WebAnnoConst.FEAT_REL_SOURCE);
        Feature targetFeat = t.getFeatureByBaseName(WebAnnoConst.FEAT_REL_TARGET);
        
        // Is this a relation?
        if (!(sourceFeat != null && targetFeat != null)) {
            continue;
        }
        
        FeatureStructure source = fs.getFeatureValue(sourceFeat);
        FeatureStructure target = fs.getFeatureValue(targetFeat);
        
        // Does it point to deleted spans?
        if (nonIndexed.contains(source) || nonIndexed.contains(target)) {
            toDelete.add(fs);
        }
    }

    // Delete those relations that pointed to deleted spans
    if (!toDelete.isEmpty()) {
        toDelete.forEach(aCas::removeFsFromIndexes);
        aMessages.add(new LogMessage(this, LogLevel.INFO, "Removed [%d] dangling relations.",
                nonIndexed.size()));
    }
}
 
示例18
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);
}
 
示例19
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());
}
 
示例20
/**
 * Write primitive value.
 *
 * @param generator the generator
 * @param annotation the annotation
 * @param feature the feature
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void writePrimitiveValue(
    JsonGenerator generator, FeatureStructure annotation, Feature feature) throws IOException {
  String range = feature.getRange().getName();
  switch (range) {
    case CAS.TYPE_NAME_INTEGER:
      generator.writeNumber(annotation.getIntValue(feature));
      break;
    case CAS.TYPE_NAME_FLOAT:
      generator.writeNumber(annotation.getFloatValue(feature));
      break;
    case CAS.TYPE_NAME_STRING:
      generator.writeString(annotation.getStringValue(feature));
      break;
    case CAS.TYPE_NAME_BOOLEAN:
      generator.writeBoolean(annotation.getBooleanValue(feature));
      break;
    case CAS.TYPE_NAME_BYTE:
      generator.writeNumber(annotation.getByteValue(feature));
      break;
    case CAS.TYPE_NAME_SHORT:
      generator.writeNumber(annotation.getShortValue(feature));
      break;
    case CAS.TYPE_NAME_LONG:
      generator.writeNumber(annotation.getLongValue(feature));
      break;
    case CAS.TYPE_NAME_DOUBLE:
      generator.writeNumber(annotation.getDoubleValue(feature));
      break;
    default:
      getMonitor().warn("Unexpected primitive type: " + range);
      break;
  }
}
 
示例21
public static long getLastChanged(CAS aCas)
{
    Type casMetadataType = getType(aCas, CASMetadata.class);
    Feature feature = casMetadataType.getFeatureByBaseName("lastChangedOnDisk");
    return aCas.select(casMetadataType)
            .map(cmd -> cmd.getLongValue(feature))
            .findFirst()
            .orElse(-1l);
}
 
示例22
/**
 * Do not check on agreement on Position and SOfa feature - already checked
 */
private static boolean isBasicFeature(Feature aFeature)
{
    // FIXME The two parts of this OR statement seem to be redundant. Also the order
    // of the check should be changes such that equals is called on the constant.
    return aFeature.getName().equals(CAS.FEATURE_FULL_NAME_SOFA)
            || aFeature.toString().equals("uima.cas.AnnotationBase:sofa");
}
 
示例23
CASArtifact(
    @Nullable LabelAdapters labelAdapters,
    Artifact artifact,
    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.createView("metadata");
  metadataCas.setDocumentText("");

  Type idType = typeSystem.getType("ArtifactID");
  Feature idFeat = idType.getFeatureByBaseName("artifactID");
  this.artifactID = artifact.getArtifactID();
  FeatureStructure documentIdFs = metadataCas.createFS(idType);
  documentIdFs.setStringValue(idFeat, artifactID);
  metadataCas.addFsToIndexes(documentIdFs);
  metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType);

  casMetadata = new CASMetadata();
  casMetadata.putAll(artifact.getMetadata());

  copyDocuments(artifact);
}
 
示例24
public static void clearAnnotations(CAS aCas, AnnotationFeature aFeature)
    throws IOException
{
    // Check if annotation layer is attached to another layer
    String attachTypeName = aFeature.getLayer().getAttachType() == null ? null : aFeature
            .getLayer().getAttachType().getName();
    Type attachType = null;
    Feature attachFeature = null;
    if (attachTypeName != null) {
        attachType = CasUtil.getType(aCas, attachTypeName);
        attachFeature = attachType
                .getFeatureByBaseName(aFeature.getLayer().getAttachFeature().getName());
    }
    
    List<AnnotationFS> annotationsToRemove = new ArrayList<>();
    Type type = CasUtil.getType(aCas, aFeature.getLayer().getName());
    annotationsToRemove.addAll(select(aCas, type));
    
    for (AnnotationFS annotation : annotationsToRemove) {
        if (attachFeature != null) {
            // Unattach the annotation to be removed
            for (AnnotationFS attach : selectCovered(attachType, annotation)) {
                FeatureStructure existing = attach.getFeatureValue(attachFeature);
                if (annotation.equals(existing)) {
                    attach.setFeatureValue(attachFeature, null);
                }
            }
        }
        aCas.removeFsFromIndexes(annotation);
    }
}
 
示例25
/**
 * {@code FeatureCopier} used for features which are references to {@code FeatureStructure}s.
 *
 * @param fromFeature the {@link Feature}
 * @param fromFs the {@link FeatureStructure} to copy from
 * @param toFs the {@link FeatureStructure} to copy to
 */
private void defaultFeatureMapper(Feature fromFeature, FeatureStructure fromFs,
    FeatureStructure toFs) {
  TypeSystem typeSystem = fromFs.getCAS().getTypeSystem();
  if (typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), fromFeature.getRange())) {
    STRING_COPIER.copy(fromFeature, fromFs, toFs);
  } else {
    FeatureStructure fromFeatureValue = fromFs.getFeatureValue(fromFeature);
    if (fromFeatureValue != null) {
      FeatureStructure toFeatureValue = fsEncounteredCallback.apply(fromFeatureValue);
      Feature toFeature = toFs.getType().getFeatureByBaseName(fromFeature.getShortName());
      toFs.setFeatureValue(toFeature, toFeatureValue);
    }
  }
}
 
示例26
public static <T extends FeatureStructure> T createFloatList(CAS aCas, Collection<Float> aValues) {
  if (aValues == null) {
    return null;
  }
  
  TypeSystem ts = aCas.getTypeSystem();

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

  if (aValues.size() == 0) {
    return aCas.createFS(emptyType);
  }
  
  Type nonEmptyType = ts.getType(CAS.TYPE_NAME_NON_EMPTY_FLOAT_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;
  Iterator<Float> i = aValues.iterator();
  while (i.hasNext()) {
    head.setFloatValue(headFeature, i.next());
    if (i.hasNext()) {
      FeatureStructure tail = aCas.createFS(nonEmptyType);
      head.setFeatureValue(tailFeature, tail);
      head = tail;
    } else {
      head.setFeatureValue(tailFeature, aCas.createFS(emptyType));
    }
  }

  return (T) list;
}
 
示例27
@Test
public void multiLinkMultiSpanRoleDiffTest()
    throws Exception
{
    JCas jcasA = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    Type type = jcasA.getTypeSystem().getType(HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");

    makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A",
            makeLinkFS(jcasA, "slot1", 0, 0));

    JCas jcasB = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostMultiSPanFeatureFS(jcasB, 0, 0, feature, "A",
            makeLinkFS(jcasB, "slot2", 0, 0));

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

    JCas curatorCas = createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    curatorCas.setDocumentText(casByUser.values().stream().flatMap(Collection::stream)
            .findFirst().get().getDocumentText());

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

    // result.print(System.out);

    sut.reMergeCas(result, document, null, curatorCas.getCas(), getSingleCasByUser(casByUser));

    Type hostType = curatorCas.getTypeSystem().getType(HOST_TYPE);

    assertThat(select(curatorCas.getCas(), hostType))
            .hasSize(1);
}
 
示例28
private void copyFeatures(SourceDocument aDocument, String aUsername, TypeAdapter aAdapter,
        FeatureStructure aTargetFS, FeatureStructure aSourceFs)
    throws AnnotationException
{
    // Cache the feature list instead of hammering the database
    List<AnnotationFeature> features = featureCache.computeIfAbsent(aAdapter.getLayer(),
        key -> schemaService.listSupportedFeatures(key));
    for (AnnotationFeature feature : features) {
        Type sourceFsType = aAdapter.getAnnotationType(aSourceFs.getCAS());
        Feature sourceFeature = sourceFsType.getFeatureByBaseName(feature.getName());

        if (sourceFeature == null) {
            throw new IllegalStateException("Target CAS type [" + sourceFsType.getName()
                    + "] does not define a feature named [" + feature.getName() + "]");
        }

        if (shouldIgnoreFeatureOnMerge(aSourceFs, sourceFeature)) {
            continue;
        }

        Object value = aAdapter.getFeatureValue(feature, aSourceFs);
        
        try {
            aAdapter.setFeatureValue(aDocument, aUsername, aTargetFS.getCAS(),
                    getAddr(aTargetFS), feature, value);
        }
        catch (IllegalArgumentException e) {
            // This happens e.g. if the value we try to set is not in the tagset and the tagset
            // cannot be extended.
            throw new IllegalFeatureValueException("Cannot set value of feature ["
                    + feature.getUiName() + "] to [" + value + "]: " + e.getMessage(), e);
        }
    }
}
 
示例29
public void testRemovalSpeed() throws Exception {
    // create an instance of an annotation type
    Feature beginFeat = this.typeSystem.getFeatureByFullName(CASTestSetup.TOKEN_TYPE + ":begin");
    Type fsType = this.typeSystem.getType(CASTestSetup.TOKEN_TYPE);
    FeatureStructure[] fsa = new FeatureStructure[NBR_ITEMS];
    // create 40000 tokens
    for (int i = 0; i < fsa.length; i++) {
      fsa[i] = this.cas.createFS(fsType);
      fsa[i].setIntValue(beginFeat,  i);
    }
    
    // warmup and jit
    timeAdd2Indexes(fsa, false);
    timeRemoveFromIndexes(fsa);
    
    long a2i = timeAdd2Indexes(fsa, false);
    long rfi = timeRemoveFromIndexes(fsa);
    
    long a2i2 = timeAdd2Indexes(fsa, false);
    long rfir = timeRemoveFromIndexesReverse(fsa);
    
    System.out.format("Timing add/remv from indexes: add1: %,d microsec, add2: %,d microsec, rmv: %,d microsec, rmvReversed: %,d microsec%n", 
        a2i/1000, a2i2/1000, rfi/1000, rfir/1000);
// big loop for doing profiling by hand and checking space recovery by hand   
    
//    for (int i = 0; i < 10000; i++) {
//      timeAdd2Indexes(fsa);
//      timeRemoveFromIndexesReverse(fsa);
//    }
  }
 
示例30
/**
 * Check the range is appropriate for this type/feature. Throws
 * LowLevelException if it isn't.
 * 
 * @param domType
 *                domain type
 * @param ranType
 *                range type
 * @param feat
 *                feature
 */
public final void checkTypingConditions(Type domType, Type ranType, Feature feat) {
  TypeImpl domainTi = (TypeImpl) domType;
  FeatureImpl fi = (FeatureImpl) feat;
  checkTypeHasFeature(domainTi, fi);
  if (!((TypeImpl) fi.getRange()).subsumes((TypeImpl) ranType)) {
    throw new LowLevelException(LowLevelException.FEAT_RAN_ERROR,
        fi.getCode(),
        feat.getName(),
        ((TypeImpl) ranType).getCode(),
        ranType.getName());
  }
}