org.apache.uima.cas.FeatureStructure Java Examples

The following examples show how to use org.apache.uima.cas.FeatureStructure. 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: FsCopiers.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience constructor which only needs the callback for encountered feature structures.
 *
 * @param featureStructureEncounteredCallback callback for encountered feature structures
 */
FsCopiers(UnaryOperator<FeatureStructure> featureStructureEncounteredCallback,
    FeatureCopiers featureCopiers) {
  this.featureCopiers = featureCopiers;
  this.featureStructureEncounteredCallback = featureStructureEncounteredCallback;

  fsCopiers = new HashMap<>();
  fsCopiers.put(CAS.TYPE_NAME_BOOLEAN_ARRAY, copyArray(BooleanArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_BYTE_ARRAY, copyArray(ByteArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_DOUBLE_ARRAY, copyArray(DoubleArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FLOAT_ARRAY, copyArray(FloatArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_FS_ARRAY, this::copyFsArray);
  fsCopiers.put(CAS.TYPE_NAME_LONG_ARRAY, copyArray(LongArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_INTEGER_ARRAY, copyArray(IntArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_SHORT_ARRAY, copyArray(ShortArrayFS.class));
  fsCopiers.put(CAS.TYPE_NAME_STRING_ARRAY, copyArray(StringArrayFS.class));
}
 
Example #2
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void checkDeltaWithAllMods() {
  makeRandomFss(casSrc, mSrc, Akof1, 7);
  TTypeSystem m = getTT(EqTwoTypes);
  remoteCas = setupCas(m);
  loadCas(casSrc, mSrc);
  ReuseInfo ri[] = serializeDeserialize(casSrc, remoteCas, null, null);
  MarkerImpl marker = (MarkerImpl) remoteCas.createMarker();

  lfs = getIndexedFSs(remoteCas, m);

  makeRandomFss(remoteCas, m, Akof1, 8);

  int i = 0;
  for (FeatureStructure fs : lfs) {
    if (((i++) % 2) == 0) {
      maybeSetFeature(fs, m, lfs.get(random.nextInt(lfs.size())));
    }
  }

  makeRandomUpdatesBelowMark(remoteCas, m, Akof1);

  verifyDelta(marker, ri);

}
 
Example #3
Source File: CASArtifact.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
CASArtifact(
    @Nullable LabelAdapters labelAdapters,
    CAS cas,
    String artifactID
) {
  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 = artifactID;
  FeatureStructure documentIdFs = metadataCas.createFS(idType);
  documentIdFs.setStringValue(idFeat, artifactID);
  metadataCas.addFsToIndexes(documentIdFs);
  metadataIndex = metadataCas.getIndexRepository().getIndex("metadata", metadataType);

  casMetadata = new CASMetadata();
}
 
Example #4
Source File: WebAnnoCasUtil.java    From webanno with Apache License 2.0 6 votes vote down vote up
/**
 * Get the feature value of this {@code Feature} on this annotation
 */
private static Object getFeatureValue(FeatureStructure aFS, Feature aFeature)
{
    switch (aFeature.getRange().getName()) {
    case CAS.TYPE_NAME_STRING:
        return aFS.getFeatureValueAsString(aFeature);
    case CAS.TYPE_NAME_BOOLEAN:
        return aFS.getBooleanValue(aFeature);
    case CAS.TYPE_NAME_FLOAT:
        return aFS.getFloatValue(aFeature);
    case CAS.TYPE_NAME_INTEGER:
        return aFS.getIntValue(aFeature);
    case CAS.TYPE_NAME_BYTE:
        return aFS.getByteValue(aFeature);
    case CAS.TYPE_NAME_DOUBLE:
        return aFS.getDoubleValue(aFeature);
    case CAS.TYPE_NAME_LONG:
        aFS.getLongValue(aFeature);
    case CAS.TYPE_NAME_SHORT:
        aFS.getShortValue(aFeature);
    default:
        return null;
    // return aFS.getFeatureValue(aFeature);
    }
}
 
Example #5
Source File: StringSubtypeTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testCas() {
   CAS cas = this.jcas.getCas();
   TypeSystem ts = cas.getTypeSystem();
   Type annotType = ts.getType(annotationTypeName);
   FeatureStructure fs = cas.createFS(annotType);
   Feature stringSetFeat = ts.getFeatureByFullName(annotationTypeName
+ TypeSystem.FEATURE_SEPARATOR + stringSetFeatureName);
   fs.setStringValue(stringSetFeat, definedValue1);
   fs.setStringValue(stringSetFeat, definedValue2);
   fs.setStringValue(stringSetFeat, definedValue3);
   // next should be ok https://issues.apache.org/jira/browse/UIMA-1839
   fs.setStringValue(stringSetFeat, null);
   boolean exCaught = false;
   try {
     fs.setStringValue(stringSetFeat, undefinedValue);
   } catch (CASRuntimeException e) {
     exCaught = true;
   }
   assertTrue(exCaught);
 }
 
Example #6
Source File: AbstractPrintConsumer.java    From baleen with Apache License 2.0 6 votes vote down vote up
/**
 * Convert an SFArray to a string.
 *
 * @param <S> the generic type
 * @param array the array
 * @param clazz the clazz
 * @param toString the to string
 * @param separator the separator
 * @return the string
 */
// NOTE This is checked by the filter
@SuppressWarnings("unchecked")
protected <S> String asString(
    FSArray array, Class<S> clazz, Function<S, String> toString, String separator) {
  if (array == null) {
    return "";
  }

  final FeatureStructure[] fses = array.toArray();

  if (fses == null) {
    return "";
  }

  return Arrays.stream(fses)
      .filter(Objects::nonNull)
      .filter(fs -> clazz.isAssignableFrom(fs.getClass()))
      .map(fs -> toString.apply((S) fs))
      .collect(Collectors.joining(separator));
}
 
Example #7
Source File: Contact_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Contact_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Contact_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Contact(addr, Contact_Type.this);
   Contact_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Contact(addr, Contact_Type.this);
}
 
Example #8
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 #9
Source File: Relation_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Relation_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Relation_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Relation(addr, Relation_Type.this);
   Relation_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Relation(addr, Relation_Type.this);
}
 
Example #10
Source File: PER_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (PER_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = PER_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new PER(addr, PER_Type.this);
   PER_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new PER(addr, PER_Type.this);
}
 
Example #11
Source File: WebAnnoTsv3WriterTestBase.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static FeatureStructure makeLinkFS(JCas aJCas, String aType, String aSlotLabel,
        AnnotationFS aTarget)
{
    Type linkType = aJCas.getTypeSystem().getType(aType);
    FeatureStructure linkA1 = aJCas.getCas().createFS(linkType);
    linkA1.setStringValue(linkType.getFeatureByBaseName("role"), aSlotLabel);
    linkA1.setFeatureValue(linkType.getFeatureByBaseName("target"), aTarget);
    aJCas.getCas().addFsToIndexes(linkA1);

    return linkA1;
}
 
Example #12
Source File: ART_Inverse_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (ART_Inverse_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = ART_Inverse_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new ART_Inverse(addr, ART_Inverse_Type.this);
   ART_Inverse_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new ART_Inverse(addr, ART_Inverse_Type.this);
}
 
Example #13
Source File: POSWh_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (POSWh_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = POSWh_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new POSWh(addr, POSWh_Type.this);
   POSWh_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new POSWh(addr, POSWh_Type.this);
}
 
Example #14
Source File: ViewCopier.java    From biomedicus with Apache License 2.0 5 votes vote down vote up
@Override
public void migrate(JCas source, JCas target) {
  target.setDocumentText(source.getDocumentText());

  FeatureStructureCopyingQueue featureStructureCopyingQueue = new FeatureStructureCopyingQueue(
      source.getCas(),
      target.getCas());

  FSIterator<FeatureStructure> allFs = source.getIndexRepository()
      .getAllIndexedFS(source.getCasType(TOP.type));
  while (allFs.hasNext()) {
    featureStructureCopyingQueue.enqueue(allFs.next());
  }
  featureStructureCopyingQueue.run();
}
 
Example #15
Source File: ArticleText_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (ArticleText_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = ArticleText_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new ArticleText(addr, ArticleText_Type.this);
   ArticleText_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new ArticleText(addr, ArticleText_Type.this);
}
 
Example #16
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void createDoubleA(CASImpl cas, TTypeSystem m, FeatureStructure fs, double x) {
  DoubleArrayFS fafs = cas.createDoubleArrayFS(6);
  fafs.set(0, Double.MAX_VALUE - x);
  // fafs.set(1, Double.MIN_NORMAL + x);
  fafs.set(2, Double.MIN_VALUE + x);
  fafs.set(3, Double.NaN);
  fafs.set(4, Double.NEGATIVE_INFINITY);
  fafs.set(5, Double.POSITIVE_INFINITY);
  maybeSetFeatureKind(fs, m, "Adouble", fafs);
}
 
Example #17
Source File: Protein_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Protein_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Protein_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Protein(addr, Protein_Type.this);
   Protein_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Protein(addr, Protein_Type.this);
}
 
Example #18
Source File: AgreementUtils.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static Object extractValueForAgreement(FeatureStructure aFs, String aFeature,
        int aLinkIndex, LinkCompareBehavior aLCB)
{
    boolean isPrimitiveFeature = aFs.getType().getFeatureByBaseName(aFeature).getRange()
            .isPrimitive();

    // If the feature on a position is set, then it is a subposition
    boolean isSubPosition = aLinkIndex != -1;

    // BEGIN PARANOIA
    assert aFs.getType().getFeatureByBaseName(aFeature).getRange()
            .isPrimitive() == isPrimitiveFeature;
    // primitive implies not subposition - if this is primitive and subposition, we
    // should never have gotten here in the first place.
    assert !isPrimitiveFeature || !isSubPosition; 
    // END PARANOIA
    
    if (isPrimitiveFeature && !isSubPosition) {
        // Primitive feature / primary position
        return getFeature(aFs, aFeature);
    }
    else if (!isPrimitiveFeature && isSubPosition) {
        // Link feature / sub-position
        return extractLinkFeatureValueForAgreement(aFs, aFeature, aLinkIndex, aLCB);
    }
    else {
        throw new IllegalStateException("Should never get here: primitive: "
                + aFs.getType().getFeatureByBaseName(aFeature).getRange()
                        .isPrimitive() + "; subpos: " + isSubPosition);
    }
}
 
Example #19
Source File: ProteinTrigger_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (ProteinTrigger_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = ProteinTrigger_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new ProteinTrigger(addr, ProteinTrigger_Type.this);
   ProteinTrigger_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new ProteinTrigger(addr, ProteinTrigger_Type.this);
}
 
Example #20
Source File: SerDesTest6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void createLongA(CASImpl cas, TTypeSystem m, FeatureStructure fs, long x) {
  LongArrayFS lafs = cas.createLongArrayFS(4);
  lafs.set(0, Long.MAX_VALUE - x);
  lafs.set(1, Long.MIN_VALUE + x);
  lafs.set(2, -45 + x);
  maybeSetFeatureKind(fs, m, "Along", lafs);
}
 
Example #21
Source File: AnnotationDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Call is forwarded to the set document.
 *
 * @param annotations the annotations
 */
@Override
public void updateFeatureStructure(Collection<? extends FeatureStructure> annotations) {
  mDocument.updateFeatureStructure(annotations);

  fireDocumentChanged();
}
 
Example #22
Source File: UiucKnownName_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (UiucKnownName_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = UiucKnownName_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new UiucKnownName(addr, UiucKnownName_Type.this);
   UiucKnownName_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new UiucKnownName(addr, UiucKnownName_Type.this);
}
 
Example #23
Source File: DateAnnot_Type.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
  if (instanceOf_Type.useExistingInstance) {
    // Return eq fs instance if already created
    FeatureStructure fs = instanceOf_Type.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new DateAnnot(addr, instanceOf_Type);
      instanceOf_Type.jcas.putJfsFromCaddr(addr, fs);
      return fs;
    }
    return fs;
  } else
    return new DateAnnot(addr, instanceOf_Type);
}
 
Example #24
Source File: DictTerm_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (DictTerm_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = DictTerm_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new DictTerm(addr, DictTerm_Type.this);
   DictTerm_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new DictTerm(addr, DictTerm_Type.this);
}
 
Example #25
Source File: MarkerImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public boolean isNew(FeatureStructure fs) {
	//check if same CAS instance
	if (!isValid || !cas.isInCAS(fs)) {
		throw new CASRuntimeException(CASRuntimeException.CAS_MISMATCH, "FS and Marker are not from the same CAS.");
	}
	return isNew(fs._id());
}
 
Example #26
Source File: Chunk_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (Chunk_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = Chunk_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new Chunk(addr, Chunk_Type.this);
   Chunk_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new Chunk(addr, Chunk_Type.this);
}
 
Example #27
Source File: PosDictionaryMatch_Type.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (PosDictionaryMatch_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = PosDictionaryMatch_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new PosDictionaryMatch(addr, PosDictionaryMatch_Type.this);
   PosDictionaryMatch_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new PosDictionaryMatch(addr, PosDictionaryMatch_Type.this);
}
 
Example #28
Source File: WebAnnoTsv3WriterTestBase.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static void makeChainHead(Type aType, AnnotationFS first)
{
    CAS cas = first.getCAS();
    FeatureStructure h = cas.createFS(aType);
    FSUtil.setFeature(h, "first", first);
    cas.addFsToIndexes(h);
}
 
Example #29
Source File: DocumentAnnotation_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (DocumentAnnotation_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = DocumentAnnotation_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new DocumentAnnotation(addr, DocumentAnnotation_Type.this);
   DocumentAnnotation_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new DocumentAnnotation(addr, DocumentAnnotation_Type.this);
}
 
Example #30
Source File: EventMention_Type.java    From bluima with Apache License 2.0 5 votes vote down vote up
public FeatureStructure createFS(int addr, CASImpl cas) {
 if (EventMention_Type.this.useExistingInstance) {
   // Return eq fs instance if already created
    FeatureStructure fs = EventMention_Type.this.jcas.getJfsFromCaddr(addr);
    if (null == fs) {
      fs = new EventMention(addr, EventMention_Type.this);
   EventMention_Type.this.jcas.putJfsFromCaddr(addr, fs);
   return fs;
    }
    return fs;
   } else return new EventMention(addr, EventMention_Type.this);
}