本文整理匯總了Java中org.apache.uima.cas.Feature類的典型用法代碼示例。如果您正苦於以下問題:Java Feature類的具體用法?Java Feature怎麽用?Java Feature使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Feature類屬於org.apache.uima.cas包,在下文中一共展示了Feature類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: defaultFeatureMapper
import org.apache.uima.cas.Feature; //導入依賴的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: adaptFile
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void adaptFile(CAS cas, Path path) throws CollectionException {
LOGGER.info("Deserializing an input stream into a cas");
try (InputStream inputStream = Files.newInputStream(path)) {
XmiCasDeserializer.deserialize(inputStream, cas,
!(failOnUnknownType == null || failOnUnknownType));
} catch (SAXException | IOException e) {
LOGGER.error("Failed on document: {}", path);
throw new CollectionException(e);
}
if (addDocumentId != null && addDocumentId) {
CAS metadata = cas.getView("metadata");
Type idType = metadata.getTypeSystem()
.getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
Feature idFeat = idType.getFeatureByBaseName("documentId");
FeatureStructure fs = metadata.createFS(idType);
fs.setStringValue(idFeat, path.getFileName().toString());
metadata.addFsToIndexes(fs);
}
}
示例3: process
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
Type documentIdType = aCAS.getTypeSystem()
.getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
Feature docIdFeat = documentIdType.getFeatureByBaseName("documentId");
String documentId = aCAS.getIndexRepository()
.getAllIndexedFS(documentIdType)
.get()
.getStringValue(docIdFeat);
if (documentId == null) {
documentId = UUID.randomUUID().toString();
}
GridFSInputFile file = gridFS.createFile(documentId + ".xmi");
try (OutputStream outputStream = file.getOutputStream()) {
XmiCasSerializer.serialize(aCAS, outputStream);
} catch (IOException | SAXException e) {
throw new AnalysisEngineProcessException(e);
}
}
示例4: CASDocument
import org.apache.uima.cas.Feature; //導入依賴的package包/類
CASDocument(@Nullable LabelAdapters labelAdapters, CAS cas) {
this.labelAdapters = labelAdapters;
this.cas = cas;
TypeSystem typeSystem = cas.getTypeSystem();
metadataType = typeSystem
.getType("edu.umn.biomedicus.uima.type1_5.DocumentMetadata");
keyFeature = metadataType.getFeatureByBaseName("key");
valueFeature = metadataType.getFeatureByBaseName("value");
metadata = cas.getView("metadata");
Type idType = typeSystem
.getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
Feature idFeat = idType.getFeatureByBaseName("documentId");
documentId = metadata.getIndexRepository()
.getAllIndexedFS(idType)
.get()
.getStringValue(idFeat);
}
示例5: setFeatureValue
import org.apache.uima.cas.Feature; //導入依賴的package包/類
/**
* Sets the feature value based on the type that you're using to set, make sure that your
* primitives are casted to the right type.
*
* @param name the feature name
* @param value the value to set
*/
public void setFeatureValue(String name, @Nullable Object value) {
Feature feature = getFeature(name);
if (value instanceof String) {
featureStructure.setStringValue(feature, (String) value);
} else if (value instanceof Integer) {
featureStructure.setIntValue(feature, ((Integer) value));
} else if (value instanceof Long) {
featureStructure.setLongValue(feature, ((Long) value));
} else if (value instanceof Double) {
featureStructure.setDoubleValue(feature, ((Double) value));
} else if (value instanceof Float) {
featureStructure.setFloatValue(feature, ((Float) value));
} else if (value instanceof FeatureStructure) {
featureStructure.setFeatureValue(feature, ((FeatureStructure) value));
} else if (value instanceof Byte) {
featureStructure.setByteValue(feature, ((Byte) value));
}
}
示例6: getAnnotation
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@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);
AnnotationFS annotation = cas.createAnnotation(type, begin, end);
if (valueIncluded) {
Feature valueFeature = type.getFeatureByBaseName("value");
annotation.setIntValue(valueFeature, value);
}
return annotation;
}
示例7: controlWordEncountered
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@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);
}
示例8: process
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
JCas other;
try {
other = jcas.getView(viewName);
for (Origin origin : JCasUtil.select(other, Origin.class)) {
int relativ = -origin.getBegin() + origin.getOffset();
for (Annotation src : JCasUtil.selectCovered(annotationClass, origin)) {
int tgtBegin = src.getBegin() + relativ;
int tgtEnd = src.getEnd() + relativ;
for (Annotation tgt : JCasUtil.selectCovered(jcas, annotationClass, tgtBegin, tgtEnd)) {
if (tgtBegin == tgt.getBegin() && tgtEnd == tgt.getEnd()) {
Feature feature = tgt.getType().getFeatureByBaseName(featureName);
if (feature.getRange().getName().equalsIgnoreCase("uima.cas.String")) {
tgt.setStringValue(feature, src.getStringValue(feature));
}
}
}
}
}
} catch (CASException e) {
throw new AnalysisEngineProcessException(e);
}
}
示例9: process
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
JCas newView;
try {
newView = jcas.createView(viewName);
} catch (CASException e) {
e.printStackTrace();
throw new AnalysisEngineProcessException(e);
}
JCasBuilder builder = new JCasBuilder(newView);
for (Annotation a : JCasUtil.select(jcas, annotationClass)) {
int relativ = -a.getBegin() + builder.getPosition();
Origin o = builder.add(a.getCoveredText(), Origin.class);
o.setOffset(a.getBegin());
for (Class<Annotation> subClass : subAnnotations) {
for (Annotation sub : JCasUtil.selectCovered(subClass, a)) {
int tgtBegin = sub.getBegin() + relativ, tgtEnd = sub.getEnd() + relativ;
Annotation tgt = AnnotationFactory.createAnnotation(newView, sub.getBegin() + relativ,
sub.getEnd() + relativ, subClass);
for (Feature feature : sub.getType().getFeatures()) {
if (feature.getRange().isPrimitive())
tgt.setFeatureValueFromString(feature, sub.getFeatureValueAsString(feature));
}
tgt.setBegin(tgtBegin);
tgt.setEnd(tgtEnd);
}
}
}
builder.close();
}
示例10: process
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
JCas other;
try {
other = jcas.getView(viewName);
for (Origin origin : JCasUtil.select(other, Origin.class)) {
int relativ = -origin.getBegin() + origin.getOffset();
for (Annotation src : JCasUtil.selectCovered(annotationClass, origin)) {
Annotation tgt = AnnotationFactory.createAnnotation(jcas, src.getBegin() + relativ,
src.getEnd() + relativ, annotationClass);
for (Feature feature : src.getType().getFeatures()) {
if (feature.getRange().isPrimitive()) {
if (feature.getRange().getName().equalsIgnoreCase("uima.cas.String")) {
tgt.setStringValue(feature, src.getStringValue(feature));
}
}
}
}
}
} catch (CASException e) {
throw new AnalysisEngineProcessException(e);
}
}
示例11: copyPrimiteFeature
import org.apache.uima.cas.Feature; //導入依賴的package包/類
private void copyPrimiteFeature(FeatureStructure sourceFs,
FeatureStructure targetFs, Feature feat) {
String rangeName = feat.getRange().getName();
if (CAS.TYPE_NAME_STRING.equals(rangeName)) {
targetFs.setStringValue(feat, sourceFs.getStringValue(feat));
} else if (CAS.TYPE_NAME_INTEGER.equals(rangeName)) {
targetFs.setIntValue(feat, sourceFs.getIntValue(feat));
} else if (CAS.TYPE_NAME_FLOAT.equals(rangeName)) {
targetFs.setFloatValue(feat, sourceFs.getFloatValue(feat));
} else if (CAS.TYPE_NAME_BYTE.equals(rangeName)) {
targetFs.setByteValue(feat, sourceFs.getByteValue(feat));
} else if (CAS.TYPE_NAME_SHORT.equals(rangeName)) {
targetFs.setShortValue(feat, sourceFs.getShortValue(feat));
} else if (CAS.TYPE_NAME_LONG.equals(rangeName)) {
targetFs.setLongValue(feat, sourceFs.getLongValue(feat));
} else if (CAS.TYPE_NAME_DOUBLE.equals(rangeName)) {
targetFs.setDoubleValue(feat, sourceFs.getDoubleValue(feat));
} else if (CAS.TYPE_NAME_BOOLEAN.equals(rangeName)) {
targetFs.setBooleanValue(feat, sourceFs.getBooleanValue(feat));
}
}
示例12: test
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Test
public void test() throws UIMAException, IOException {
SetMultimap<String, String> unitsByClass = HashMultimap.create();
for (JCas jCas : new JCasIterable(reader, tokenizerSentenceSplitter,
unitAnnotator, unitClassifier)) {
CAS aCas = jCas.getCas();
Type unitType = aCas.getTypeSystem().getType(
UnitAnnotator.UNIT_TYPE_NAME);
Feature classFeature = unitType
.getFeatureByBaseName(UnitClassifier.CLASS_FEAT_NAME);
for (AnnotationFS unitAnnotation : CasUtil.select(aCas, unitType)) {
if (unitAnnotation.getStringValue(classFeature) != null) {
unitsByClass.put(
unitAnnotation.getStringValue(classFeature),
unitAnnotation.getCoveredText());
}
}
}
assertEquals(
Sets.newHashSet("Вагнер", "двое", "боевиков", "пособница"),
unitsByClass.get("ru.kfu.itis.issst.evex.Person"));
assertEquals(Sets.newHashSet("ЦСКА"),
unitsByClass.get("ru.kfu.itis.issst.evex.Organization"));
assertEquals(Sets.newHashSet("штурма", "квартиры"),
unitsByClass.get("ru.kfu.itis.issst.evex.Weapon"));
}
示例13: makeAnnotation
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void makeAnnotation(AnnotationFS firstToken, AnnotationFS lastToken, String tag) {
Preconditions.checkArgument(firstToken != null, "firstToken == null");
CAS cas = firstToken.getCAS();
Type targetType = tag2TypeMap.get(tag);
if (targetType == null) {
logger.warn(String.format("Dictionary tag '%s' is not mapped to any annotation type", tag));
} else {
AnnotationFS anno = cas.createAnnotation(targetType, firstToken.getBegin(), lastToken.getEnd());
Feature firstTokenFeature = targetType.getFeatureByBaseName("firstToken");
// TODO doc
if (firstTokenFeature != null) {
anno.setFeatureValue(firstTokenFeature, firstToken);
}
cas.addFsToIndexes(anno);
}
}
示例14: delete
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Override
public void delete(AnnotatorState aState, JCas aJCas, VID aVid)
{
AnnotationFS fs = selectByAddr(aJCas, AnnotationFS.class, aVid.getId());
aJCas.removeFsFromIndexes(fs);
// delete associated attachFeature
if (getAttachTypeName() != null) {
Type theType = CasUtil.getType(aJCas.getCas(), getAttachTypeName());
Feature attachFeature = theType.getFeatureByBaseName(getAttachFeatureName());
if (attachFeature != null) {
CasUtil.selectCovered(aJCas.getCas(), theType, fs.getBegin(), fs.getEnd()).get(0)
.setFeatureValue(attachFeature, null);
}
}
publishEvent(new SpanDeletedEvent(this, aState.getDocument(),
aState.getUser().getUsername(), fs));
}
示例15: simpleCopyToDiffExistingAnnoWithStackingTest
import org.apache.uima.cas.Feature; //導入依賴的package包/類
@Test
public void simpleCopyToDiffExistingAnnoWithStackingTest()
throws Exception
{
AnnotatorState state = new AnnotatorStateImpl(Mode.CURATION);
state.setUser(new User());
posLayer.setAllowStacking(true);
JCas jcas = JCasFactory.createJCas();
Type type = jcas.getTypeSystem().getType(POS.class.getTypeName());
AnnotationFS clickedFs = createPOSAnno(jcas, type, "NN", 0, 0);
JCas mergeCAs = JCasFactory.createJCas();
createTokenAnno(mergeCAs, 0, 0);
AnnotationFS existingFs = mergeCAs.getCas().createAnnotation(type, 0, 0);
Feature posValue = type.getFeatureByBaseName("PosValue");
existingFs.setStringValue(posValue, "NE");
mergeCAs.addFsToIndexes(existingFs);
MergeCas.addSpanAnnotation(state, annotationSchemaService, posLayer, mergeCAs, clickedFs,
true);
assertEquals(2, CasUtil.selectCovered(mergeCAs.getCas(), type, 0, 0).size());
}