本文整理汇总了Java中org.apache.uima.cas.FeatureStructure.getFeatureValue方法的典型用法代码示例。如果您正苦于以下问题:Java FeatureStructure.getFeatureValue方法的具体用法?Java FeatureStructure.getFeatureValue怎么用?Java FeatureStructure.getFeatureValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.uima.cas.FeatureStructure
的用法示例。
在下文中一共展示了FeatureStructure.getFeatureValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultFeatureMapper
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
/**
* {@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);
}
}
}
示例2: getValueOfFS
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
@Override
public UimaPrimitive getValueOfFS(TypeSystem typeSystem, FeatureStructure targetFS) throws NlpTabException {
Collection<Object> values = new LinkedList<>();
FeatureStructure pointer = targetFS;
while (pointer.getType().getName().equals(nonEmptyName)) {
Object value;
try {
value = headMethod.invoke(pointer, headFeature);
} catch (IllegalAccessException | InvocationTargetException e) {
throw new NlpTabException(e);
}
values.add(value);
pointer = pointer.getFeatureValue(tailFeature);
}
Type type = targetFS.getType();
String typeShortName = type.getShortName();
return new UimaPrimitive(values, typeShortName);
}
示例3: writeFS
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
/**
* Write annotation with features (including non-primitives)
*
* @param generator
* the generator
* @param annotation
* the annotation
* @param features
* the features
* @throws IOException
* Signals that an I/O exception has occurred.
*/
private void writeFS(JsonGenerator generator, FeatureStructure annotation, List<Feature> features)
throws IOException {
generator.writeObjectFieldStart("fields");
for (Feature feature : features) {
if (feature.getRange().isPrimitive()) {
writePrimitive(generator, annotation, feature);
} else if (feature.getRange().isArray()) {
writeArray(generator, annotation, feature);
} else {
if ("uima.cas.AnnotationBase:sofa".equals(feature.getName())) {
continue;
}
FeatureStructure featureValue = annotation.getFeatureValue(feature);
if (featureValue != null) {
generator.writeFieldName(feature.getShortName());
writeFS(generator, featureValue);
}
}
}
generator.writeEndObject();
}
示例4: generateSubPositions
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
@Override
public List<? extends Position> generateSubPositions(int aCasId, AnnotationFS aFs,
LinkCompareBehavior aLinkCompareBehavior)
{
List<Position> subPositions = new ArrayList<>();
for (LinkFeatureDecl decl : linkFeatures) {
Feature linkFeature = aFs.getType().getFeatureByBaseName(decl.name);
ArrayFS array = (ArrayFS) aFs.getFeatureValue(linkFeature);
if (array == null) {
continue;
}
for (FeatureStructure linkFS : array.toArray()) {
String role = linkFS.getStringValue(linkFS.getType().getFeatureByBaseName(
decl.roleFeature));
AnnotationFS target = (AnnotationFS) linkFS.getFeatureValue(linkFS.getType()
.getFeatureByBaseName(decl.targetFeature));
Position pos = getPosition(aCasId, aFs, decl.name, role, target.getBegin(),
target.getEnd(), aLinkCompareBehavior);
subPositions.add(pos);
}
}
return subPositions;
}
示例5: getValueOfFeature
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
@Override
public UimaPrimitive getValueOfFeature(TypeSystem typeSystem, Feature feature, FeatureStructure featureStructure) throws NlpTabException {
FeatureStructure targetFS = featureStructure.getFeatureValue(feature);
UimaPrimitive uimaPrimitive;
if (targetFS != null) {
uimaPrimitive = getValueOfFS(typeSystem, targetFS);
} else {
Type range = feature.getRange();
String rangeShortName = range.getShortName();
uimaPrimitive = new UimaPrimitive(null, rangeShortName);
}
return uimaPrimitive;
}
示例6: getCollection
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected Collection<E> getCollection(FeatureStructure anno) {
ArrayFS fsArray = (ArrayFS) anno.getFeatureValue(feature);
if (fsArray == null) {
return null;
}
return (Collection<E>) FSCollectionFactory.create(fsArray);
}
示例7: collectLinks
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
private List<AnnotationFS> collectLinks(FeatureStructure aChain)
{
List<AnnotationFS> links = new ArrayList<>();
// Now we seek the link within the current chain
AnnotationFS linkFs = (AnnotationFS) aChain.getFeatureValue(aChain.getType()
.getFeatureByBaseName(chainFirstFeatureName));
while (linkFs != null) {
links.add(linkFs);
linkFs = getNextLink(linkFs);
}
return links;
}
示例8: getPosition
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
@Override
public Position getPosition(int aCasId, FeatureStructure aFS, String aFeature, String aRole,
int aLinkTargetBegin, int aLinkTargetEnd, LinkCompareBehavior aLinkCompareBehavior)
{
Type type = aFS.getType();
AnnotationFS sourceFS = (AnnotationFS) aFS.getFeatureValue(type
.getFeatureByBaseName(sourceFeature));
AnnotationFS targetFS = (AnnotationFS) aFS.getFeatureValue(type
.getFeatureByBaseName(targetFeature));
String collectionId = null;
String documentId = null;
try {
DocumentMetaData dmd = DocumentMetaData.get(aFS.getCAS());
collectionId = dmd.getCollectionId();
documentId = dmd.getDocumentId();
}
catch (IllegalArgumentException e) {
// We use this information only for debugging - so we can ignore if the information
// is missing.
}
String linkTargetText = null;
if (aLinkTargetBegin != -1 && aFS.getCAS().getDocumentText() != null) {
linkTargetText = aFS.getCAS().getDocumentText()
.substring(aLinkTargetBegin, aLinkTargetEnd);
}
return new ArcPosition(collectionId, documentId, aCasId, getType(),
sourceFS != null ? sourceFS.getBegin() : -1,
sourceFS != null ? sourceFS.getEnd() : -1,
sourceFS != null ? sourceFS.getCoveredText() : null,
targetFS != null ? targetFS.getBegin() : -1,
targetFS != null ? targetFS.getEnd() : -1,
targetFS != null ? targetFS.getCoveredText() : null,
aFeature, aRole, aLinkTargetBegin, aLinkTargetEnd, linkTargetText,
aLinkCompareBehavior);
}
示例9: getPrimitiveArrayFeatureValue
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
private static Object[] getPrimitiveArrayFeatureValue(
JCas view,
FeatureStructure featureStructure,
Feature feature) throws CleartkExtractorException {
TypeSystem typeSystem = view.getTypeSystem();
Type type = feature.getRange();
if (type.isArray()) {
Type componentType = type.getComponentType();
FeatureStructure featureValue = featureStructure.getFeatureValue(feature);
if (componentType.equals(typeSystem.getType("uima.cas.String"))) {
return ((StringArray) featureValue).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Boolean"))) {
return Arrays.asList(((BooleanArray) featureValue).toArray()).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Double"))) {
return Arrays.asList(((DoubleArray) featureValue).toArray()).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Float"))) {
return Arrays.asList(((FloatArray) featureValue).toArray()).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Byte"))) {
return Arrays.asList(((ByteArray) featureValue).toArray()).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Short"))) {
return Arrays.asList(((ShortArray) featureValue).toArray()).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Integer"))) {
return Arrays.asList(((IntegerArray) featureValue).toArray()).toArray();
} else if (componentType.equals(typeSystem.getType("uima.cas.Long"))) {
return Arrays.asList(((LongArray) featureValue).toArray()).toArray();
}
} else
throw CleartkExtractorException.notPrimitiveArray(feature);
return null;
}
示例10: getValue
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private E getValue(FeatureStructure fs) {
E featureValue = (E) fs.getFeatureValue(feature);
return featureValue;
}
示例11: setChainAnnotation
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
private void setChainAnnotation(JCas aJCas)
{
for (String l : chainLayers) {
if (l.equals(Token.class.getName())) {
continue;
}
Map<AnnotationUnit, List<List<String>>> annotationsPertype = null;
Type type = getType(aJCas.getCas(), l + CHAIN);
Feature chainFirst = type.getFeatureByBaseName(FIRST);
int chainNo = 1;
for (FeatureStructure chainFs : selectFS(aJCas.getCas(), type)) {
AnnotationFS linkFs = (AnnotationFS) chainFs.getFeatureValue(chainFirst);
AnnotationUnit unit = getUnit(linkFs.getBegin(), linkFs.getEnd(),
linkFs.getCoveredText());
Type lType = linkFs.getType();
// this is the layer with annotations
l = lType.getName();
if (annotationsPerPostion.get(l) == null) {
annotationsPertype = new HashMap<>();
}
else {
annotationsPertype = annotationsPerPostion.get(l);
}
Feature linkNext = linkFs.getType().getFeatureByBaseName(NEXT);
int linkNo = 1;
while (linkFs != null) {
AnnotationFS nextLinkFs = (AnnotationFS) linkFs.getFeatureValue(linkNext);
if (nextLinkFs != null) {
addChinFeatureAnno(annotationsPertype, lType, linkFs, unit, linkNo,
chainNo);
}
else {
addChinFeatureAnno(annotationsPertype, lType, linkFs, unit, linkNo,
chainNo);
}
linkFs = nextLinkFs;
linkNo++;
if (nextLinkFs != null) {
unit = getUnit(linkFs.getBegin(), linkFs.getEnd(), linkFs.getCoveredText());
}
}
if (annotationsPertype.keySet().size() > 0) {
annotationsPerPostion.put(l, annotationsPertype);
}
chainNo++;
}
}
}
示例12: isSameAnno
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
/**
* Return true if these two annotations agree on every non slot features
*/
public static boolean isSameAnno(FeatureStructure aFirstFS, FeatureStructure aSeconFS)
{
for (Feature f : getAllFeatures(aFirstFS)) {
// the annotations are already in the same position
if (isBasicFeature(f)) {
continue;
}
if (!isLinkMode(aFirstFS, f)) {
// check if attache type exists
try {
FeatureStructure attachFs1 = aFirstFS.getFeatureValue(f);
FeatureStructure attachFs2 = aSeconFS.getFeatureValue(f);
if (!isSameAnno(attachFs1, attachFs2)) {
return false;
}
}
catch (Exception e) {
// no attach tyep -- continue
}
// assume null as equal
if (getFeatureValue(aFirstFS, f) == null && getFeatureValue(aSeconFS, f) == null) {
continue;
}
if (getFeatureValue(aFirstFS, f) == null && getFeatureValue(aSeconFS, f) != null) {
return false;
}
if (getFeatureValue(aFirstFS, f) != null && getFeatureValue(aSeconFS, f) == null) {
return false;
}
if (!getFeatureValue(aFirstFS, f).equals(getFeatureValue(aSeconFS, f))) {
return false;
}
}
}
return true;
}
示例13: getFeatureValue
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
default public <T> T getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
Feature feature = aFS.getType().getFeatureByBaseName(aFeature.getName());
switch (aFeature.getMultiValueMode()) {
case NONE: {
final String effectiveType;
if (aFeature.isVirtualFeature()) {
effectiveType = CAS.TYPE_NAME_STRING;
}
else {
effectiveType = aFeature.getType();
}
// Sanity check
if (!Objects.equals(effectiveType, feature.getRange().getName())) {
throw new IllegalArgumentException("Actual feature type ["
+ feature.getRange().getName() + "]does not match expected feature type ["
+ effectiveType + "].");
}
// switch (aFeature.getType()) {
// case CAS.TYPE_NAME_STRING:
// return (T) aFS.getStringValue(feature);
// case CAS.TYPE_NAME_BOOLEAN:
// return (T) (Boolean) aFS.getBooleanValue(feature);
// case CAS.TYPE_NAME_FLOAT:
// return (T) (Float) aFS.getFloatValue(feature);
// case CAS.TYPE_NAME_INTEGER:
// return (T) (Integer) aFS.getIntValue(feature);
// default:
// throw new IllegalArgumentException("Cannot get value of feature ["
// + aFeature.getName() + "] with type [" + feature.getRange().getName() + "]");
// }
return WebAnnoCasUtil.getFeature(aFS, aFeature.getName());
}
case ARRAY: {
switch (aFeature.getLinkMode()) {
case WITH_ROLE: {
// Get type and features - we need them later in the loop
Feature linkFeature = aFS.getType().getFeatureByBaseName(aFeature.getName());
Type linkType = aFS.getCAS().getTypeSystem().getType(aFeature.getLinkTypeName());
Feature roleFeat = linkType.getFeatureByBaseName(aFeature
.getLinkTypeRoleFeatureName());
Feature targetFeat = linkType.getFeatureByBaseName(aFeature
.getLinkTypeTargetFeatureName());
List<LinkWithRoleModel> links = new ArrayList<>();
ArrayFS array = (ArrayFS) aFS.getFeatureValue(linkFeature);
if (array != null) {
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 (T) links;
}
default:
throw new IllegalArgumentException("Cannot get value of feature ["
+ aFeature.getName() + "] with link mode [" + aFeature.getMultiValueMode()
+ "]");
}
}
default:
throw new IllegalArgumentException("Unsupported multi-value mode ["
+ aFeature.getMultiValueMode() + "] on feature [" + aFeature.getName() + "]");
}
}
示例14: getFirstLink
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
/**
* Get the first link of a chain from the chain head feature structure.
*/
private AnnotationFS getFirstLink(FeatureStructure aChain)
{
return (AnnotationFS) aChain.getFeatureValue(aChain.getType().getFeatureByBaseName(
chainFirstFeatureName));
}
示例15: getFeatureFS
import org.apache.uima.cas.FeatureStructure; //导入方法依赖的package包/类
/**
* Get a feature value.
*
* @param aFS
* the feature structure.
* @param aFeatureName
* the feature within the annotation whose value to set.
* @return the feature value.
*/
public static FeatureStructure getFeatureFS(FeatureStructure aFS, String aFeatureName)
{
return aFS.getFeatureValue(aFS.getType().getFeatureByBaseName(aFeatureName));
}