本文整理了Java中org.apache.uima.fit.util.FSUtil.getFeature()
方法的一些代码示例,展示了FSUtil.getFeature()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FSUtil.getFeature()
方法的具体详情如下:
包路径:org.apache.uima.fit.util.FSUtil
类名称:FSUtil
方法名:getFeature
暂无
代码示例来源:origin: org.apache.uima/uimafit-core
public static <T> T getFeature(FeatureStructure aFS, String aFeature, Class<T> aClazz)
{
Feature feat = getMandatoryFeature(aFS, aFeature);
return getFeature(aFS, feat, aClazz);
}
代码示例来源:origin: webanno/webanno
private static void writePrimitiveValue(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
Object value = getFeature(aFS, aCol.uimaFeature, Object.class);
value = value == null ? NULL_VALUE : escapeValue(String.valueOf(value));
aOut.print(value);
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-io-tsv
private static void writePrimitiveValue(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
Object value = getFeature(aFS, aCol.uimaFeature, Object.class);
value = value == null ? NULL_VALUE : escapeValue(String.valueOf(value));
aOut.print(value);
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-io-tsv
private static void writeSlotRole(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
FeatureStructure[] links = getFeature(aFS, aCol.uimaFeature, FeatureStructure[].class);
if (links != null && links.length > 0) {
for (int i = 0; i < links.length; i++) {
if (i > 0) {
aOut.print(SLOT_SEP);
}
String value = getFeature(links[i], TsvSchema.FEAT_SLOT_ROLE, String.class);
value = value == null ? NULL_VALUE : escapeValue(value);
aOut.print(value);
}
}
else {
aOut.print(NULL_COLUMN);
}
writeDisambiguationId(aOut, aDoc, aFS);
}
代码示例来源:origin: webanno/webanno
private static void writeSlotRole(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
FeatureStructure[] links = getFeature(aFS, aCol.uimaFeature, FeatureStructure[].class);
if (links != null && links.length > 0) {
for (int i = 0; i < links.length; i++) {
if (i > 0) {
aOut.print(SLOT_SEP);
}
String value = getFeature(links[i], TsvSchema.FEAT_SLOT_ROLE, String.class);
value = value == null ? NULL_VALUE : escapeValue(value);
aOut.print(value);
}
}
else {
aOut.print(NULL_COLUMN);
}
writeDisambiguationId(aOut, aDoc, aFS);
}
代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.testing-asl
@Override
public boolean check(JCas aJCas, List<Message> aMessages)
{
for (Constituent parent : select(aJCas, Constituent.class)) {
Collection<Annotation> children = select(parent.getChildren(), Annotation.class);
for (Annotation child : children) {
Annotation declParent = FSUtil.getFeature(child, "parent", Annotation.class);
if (declParent == null) {
aMessages.add(new Message(this, ERROR, String.format(
"Child without parent set: %s", child)));
}
else if (declParent != parent) {
aMessages.add(new Message(this, ERROR, String.format(
"Child points to wrong parent: %s", child)));
}
}
}
return aMessages.stream().anyMatch(m -> m.level == ERROR);
}
// end::check-example[]
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-api-annotation
public static boolean isRequiredFeatureMissing(AnnotationFeature aFeature, FeatureStructure aFS)
{
return aFeature.isRequired() && CAS.TYPE_NAME_STRING.equals(aFeature.getType())
&& StringUtils.isBlank(FSUtil.getFeature(aFS, aFeature.getName(), String.class));
}
}
代码示例来源:origin: dkpro/dkpro-core
@Override
public boolean check(JCas aJCas, List<Message> aMessages)
{
for (Constituent parent : select(aJCas, Constituent.class)) {
Collection<Annotation> children = select(parent.getChildren(), Annotation.class);
for (Annotation child : children) {
Annotation declParent = FSUtil.getFeature(child, "parent", Annotation.class);
if (declParent == null) {
aMessages.add(new Message(this, ERROR, String.format(
"Child without parent set: %s", child)));
}
else if (declParent != parent) {
aMessages.add(new Message(this, ERROR, String.format(
"Child points to wrong parent: %s", child)));
}
}
}
return aMessages.stream().anyMatch(m -> m.level == ERROR);
}
// end::check-example[]
代码示例来源:origin: webanno/webanno
public static boolean isRequiredFeatureMissing(AnnotationFeature aFeature, FeatureStructure aFS)
{
return aFeature.isRequired() && CAS.TYPE_NAME_STRING.equals(aFeature.getType())
&& StringUtils.isBlank(FSUtil.getFeature(aFS, aFeature.getName(), String.class));
}
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-io-tsv
private static void writeRelationReference(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
AnnotationFS targetFS = getFeature(aFS, FEAT_REL_TARGET, AnnotationFS.class);
AnnotationFS sourceFS = getFeature(aFS, FEAT_REL_SOURCE, AnnotationFS.class);
// The column contains the ID of the unit from which the relation is pointing to the
// current unit, i.e. the sourceUnit of the relation.
TsvUnit sourceUnit = aDoc.findIdDefiningUnit(sourceFS);
aOut.print(sourceUnit.getId());
// If the source/target is ambiguous, add the disambiguation IDs
Integer sourceId = aDoc.getDisambiguationId(sourceFS);
Integer targetId = aDoc.getDisambiguationId(targetFS);
if (sourceId != null || targetId != null) {
sourceId = sourceId != null ? sourceId : 0;
targetId = targetId != null ? targetId : 0;
aOut.printf("[%d_%d]", sourceId, targetId);
}
}
代码示例来源:origin: webanno/webanno
private static void writeRelationReference(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
AnnotationFS targetFS = getFeature(aFS, FEAT_REL_TARGET, AnnotationFS.class);
AnnotationFS sourceFS = getFeature(aFS, FEAT_REL_SOURCE, AnnotationFS.class);
// The column contains the ID of the unit from which the relation is pointing to the
// current unit, i.e. the sourceUnit of the relation.
TsvUnit sourceUnit = aDoc.findIdDefiningUnit(sourceFS);
aOut.print(sourceUnit.getId());
// If the source/target is ambiguous, add the disambiguation IDs
Integer sourceId = aDoc.getDisambiguationId(sourceFS);
Integer targetId = aDoc.getDisambiguationId(targetFS);
if (sourceId != null || targetId != null) {
sourceId = sourceId != null ? sourceId : 0;
targetId = targetId != null ? targetId : 0;
aOut.printf("[%d_%d]", sourceId, targetId);
}
}
代码示例来源:origin: webanno/webanno
private static void writeChainElement(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
String value = getFeature(aFS, COREFERENCE_TYPE_FEATURE, String.class);
value = value == null ? NULL_VALUE : escapeValue(value);
TsvChain chain = aDoc.getChain(aFS);
aOut.printf("%s[%d]", value, chain.getId());
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-io-tsv
private static void writeChainElement(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
String value = getFeature(aFS, COREFERENCE_TYPE_FEATURE, String.class);
value = value == null ? NULL_VALUE : escapeValue(value);
TsvChain chain = aDoc.getChain(aFS);
aOut.printf("%s[%d]", value, chain.getId());
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-io-tsv
private static void writeChainLink(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
String value = getFeature(aFS, COREFERENCE_RELATION_FEATURE, String.class);
value = value == null ? NULL_VALUE : escapeValue(value);
TsvChain chain = aDoc.getChain(aFS);
aOut.printf("%s->%d-%d", value, chain.getId(), chain.indexOf(aFS) + 1);
}
}
代码示例来源:origin: webanno/webanno
private static void writeChainLink(PrintWriter aOut, TsvDocument aDoc, TsvColumn aCol,
AnnotationFS aFS)
{
String value = getFeature(aFS, COREFERENCE_RELATION_FEATURE, String.class);
value = value == null ? NULL_VALUE : escapeValue(value);
TsvChain chain = aDoc.getChain(aFS);
aOut.printf("%s->%d-%d", value, chain.getId(), chain.indexOf(aFS) + 1);
}
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-api-annotation
private Object getValue(FeatureStructure fs, AnnotationFeature aFeature)
{
Object value;
Feature f = fs.getType().getFeatureByBaseName(aFeature.getName());
if (f.getRange().isPrimitive()) {
value = FSUtil.getFeature(fs, aFeature.getName(), Object.class);
}
else if (FSUtil.isMultiValuedFeature(fs, f)) {
value = FSUtil.getFeature(fs, aFeature.getName(), List.class);
}
else {
value = FSUtil.getFeature(fs, aFeature.getName(), FeatureStructure.class);
}
return value;
}
代码示例来源:origin: webanno/webanno
private Object getValue(FeatureStructure fs, AnnotationFeature aFeature)
{
Object value;
Feature f = fs.getType().getFeatureByBaseName(aFeature.getName());
if (f.getRange().isPrimitive()) {
value = FSUtil.getFeature(fs, aFeature.getName(), Object.class);
}
else if (FSUtil.isMultiValuedFeature(fs, f)) {
value = FSUtil.getFeature(fs, aFeature.getName(), List.class);
}
else {
value = FSUtil.getFeature(fs, aFeature.getName(), FeatureStructure.class);
}
return value;
}
代码示例来源:origin: de.tudarmstadt.ukp.clarin.webanno/webanno-api-annotation
default <V> V getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
Object value;
Feature f = aFS.getType().getFeatureByBaseName(aFeature.getName());
if (f.getRange().isPrimitive()) {
value = FSUtil.getFeature(aFS, aFeature.getName(), Object.class);
}
else if (FSUtil.isMultiValuedFeature(aFS, f)) {
value = FSUtil.getFeature(aFS, aFeature.getName(), List.class);
}
else {
value = FSUtil.getFeature(aFS, aFeature.getName(), FeatureStructure.class);
}
return (V) wrapFeatureValue(aFeature, aFS.getCAS(), value);
}
代码示例来源:origin: webanno/webanno
default <V> V getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS)
{
Object value;
Feature f = aFS.getType().getFeatureByBaseName(aFeature.getName());
if (f.getRange().isPrimitive()) {
value = FSUtil.getFeature(aFS, aFeature.getName(), Object.class);
}
else if (FSUtil.isMultiValuedFeature(aFS, f)) {
value = FSUtil.getFeature(aFS, aFeature.getName(), List.class);
}
else {
value = FSUtil.getFeature(aFS, aFeature.getName(), FeatureStructure.class);
}
return (V) wrapFeatureValue(aFeature, aFS.getCAS(), value);
}
代码示例来源:origin: webanno/webanno
@Test
public void thatRelationAttachmentBehaviorOnCreateWorks() throws Exception
{
TokenBuilder<Token, Sentence> builder = new TokenBuilder<>(Token.class, Sentence.class);
builder.buildTokens(jcas, "This is a test .");
for (Token t : select(jcas, Token.class)) {
POS pos = new POS(jcas, t.getBegin(), t.getEnd());
t.setPos(pos);
pos.addToIndexes();
}
RelationAdapter sut = new RelationAdapter(featureSupportRegistry, null, depLayer,
FEAT_REL_TARGET, FEAT_REL_SOURCE,
asList(dependencyLayerGovernor, dependencyLayerDependent), behaviors);
List<POS> posAnnotations = new ArrayList<>(select(jcas, POS.class));
List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
POS source = posAnnotations.get(0);
POS target = posAnnotations.get(1);
AnnotationFS dep = sut.add(document, username, source, target, jcas, 0,
jcas.getDocumentText().length());
assertThat(FSUtil.getFeature(dep, FEAT_REL_SOURCE, Token.class)).isEqualTo(tokens.get(0));
assertThat(FSUtil.getFeature(dep, FEAT_REL_TARGET, Token.class)).isEqualTo(tokens.get(1));
}
内容来源于网络,如有侵权,请联系作者删除!