org.apache.uima.cas.text.AnnotationFS.getStringValue()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(93)

本文整理了Java中org.apache.uima.cas.text.AnnotationFS.getStringValue()方法的一些代码示例,展示了AnnotationFS.getStringValue()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AnnotationFS.getStringValue()方法的具体详情如下:
包路径:org.apache.uima.cas.text.AnnotationFS
类名称:AnnotationFS
方法名:getStringValue

AnnotationFS.getStringValue介绍

暂无

代码示例

代码示例来源:origin: apache/opennlp

sentenceWithPos.append(token.getCoveredText());
sentenceWithPos.append('\\');
sentenceWithPos.append(token.getStringValue(this.posFeature));
sentenceWithPos.append(' ');

代码示例来源:origin: org.apache.uima/ConceptMapper

private String getTokenText(AnnotationFS token) {
  if (tokenTextFeature == null) {
   return token.getCoveredText();
  } else {
   return token.getStringValue(tokenTextFeature);
  }
 }
}

代码示例来源:origin: org.apache.uima/ConceptMapper

/**
 * @param token
 *          tokenClass to look up
 * @return true if in includedTokenClasses or if both includedTokenClasses and
 *         excludedTokenClasses are unset, of if excludedTokenClasses does not contain an entry
 *         for tokenClass parameter
 */
public boolean checkTokenClass(AnnotationFS token) {
 boolean returnValue = true;
 if (tokenClassFeature != null) {
  String tokenClass = token.getStringValue(tokenClassFeature);
  if (tokenClass != null) {
   returnValue = isOK_TokenClass(tokenClass);
  }
 }
 // System.err.println ("checkTokenClass, token = " + token.getCoveredText() + ", returnValue: "
 // + returnValue);
 return returnValue;
}

代码示例来源:origin: de.tudarmstadt.ukp.inception.app/inception-concept-linking

private Collection<ImmutablePair<String, Collection<AnnotationFS>>> extractNamedEntities(
  List<CAS> aCasList)
{
  Type tokenType = org.apache.uima.fit.util.CasUtil
    .getType(aCasList.get(0), recommender.getLayer().getName());
  Feature feature = tokenType.getFeatureByBaseName(recommender.getFeature().getName());
  Collection<ImmutablePair<String, Collection<AnnotationFS>>> nameSamples = new HashSet<>();
  for (CAS cas : aCasList) {
    Collection<AnnotationFS> namesPerDocument = new ArrayList<>();
    Type sentenceType = getType(cas, Sentence.class);
    Map<AnnotationFS, Collection<AnnotationFS>> sentences = indexCovered(cas, sentenceType,
      tokenType);
    for (Map.Entry<AnnotationFS, Collection<AnnotationFS>> e : sentences.entrySet()) {
      Collection<AnnotationFS> tokens = e.getValue().stream()
        // If the identifier has not been set
        .filter(a -> a.getStringValue(feature) == null)
        .collect(Collectors.toSet());
      namesPerDocument.addAll(tokens);
    }
    // TODO #176 use the document Id once it is available in the CAS
    nameSamples.add(
      new ImmutablePair<>(DocumentMetaData.get(cas).getDocumentUri(), namesPerDocument));
  }
  return nameSamples;
}

代码示例来源:origin: org.apache.uima/ruta-core

@Override
public void visitEndTag(Tag tag) {
 String name = getName(tag);
 AnnotationFS found = null;
 for (int i = annotationStack.size() - 1; i >= 0; i--) {
  AnnotationFS each = annotationStack.get(i);
  Feature nameFeature = each.getType().getFeatureByBaseName("name");
  String eachName = each.getStringValue(nameFeature);
  if (name.equals(eachName)) {
   int endOffset = getEndOffset(tag);
   Feature endFeature = each.getType().getFeatureByBaseName("end");
   each.setIntValue(endFeature, endOffset);
   found = each;
   break;
  }
 }
 if (found != null) {
  annotationStack.remove(found);
  annotations.add(found);
 }
}

代码示例来源:origin: inception-project/inception

private Collection<ImmutablePair<String, Collection<AnnotationFS>>> extractNamedEntities(
  List<CAS> aCasList)
{
  Type tokenType = org.apache.uima.fit.util.CasUtil
    .getType(aCasList.get(0), recommender.getLayer().getName());
  Feature feature = tokenType.getFeatureByBaseName(recommender.getFeature().getName());
  Collection<ImmutablePair<String, Collection<AnnotationFS>>> nameSamples = new HashSet<>();
  for (CAS cas : aCasList) {
    Collection<AnnotationFS> namesPerDocument = new ArrayList<>();
    Type sentenceType = getType(cas, Sentence.class);
    Map<AnnotationFS, Collection<AnnotationFS>> sentences = indexCovered(cas, sentenceType,
      tokenType);
    for (Map.Entry<AnnotationFS, Collection<AnnotationFS>> e : sentences.entrySet()) {
      Collection<AnnotationFS> tokens = e.getValue().stream()
        // If the identifier has not been set
        .filter(a -> a.getStringValue(feature) == null)
        .collect(Collectors.toSet());
      namesPerDocument.addAll(tokens);
    }
    // TODO #176 use the document Id once it is available in the CAS
    nameSamples.add(
      new ImmutablePair<>(DocumentMetaData.get(cas).getDocumentUri(), namesPerDocument));
  }
  return nameSamples;
}

代码示例来源:origin: org.apache.uima/ruta-core

private File getOutputFile(CAS cas) {
 if (StringUtils.isBlank(outputLocation)) {
  return null;
 }
 Type sdiType = cas.getTypeSystem().getType(RutaEngine.SOURCE_DOCUMENT_INFORMATION);
 String filename = "output.modified.html";
 File file = new File(outputLocation, filename);
 if (sdiType != null) {
  FSIterator<AnnotationFS> sdiit = cas.getAnnotationIndex(sdiType).iterator();
  if (sdiit.isValid()) {
   AnnotationFS annotationFS = sdiit.get();
   Feature uriFeature = sdiType.getFeatureByBaseName("uri");
   String stringValue = annotationFS.getStringValue(uriFeature);
   File f = new File(stringValue);
   String name = f.getName();
   if (!name.endsWith(".modified.html")) {
    name = name + ".modified.html";
   }
   file = new File(outputLocation, name);
  }
 }
 return file;
}

代码示例来源:origin: org.apache.uima/textmarker-core

private File getOutputFile(CAS cas) {
 if (StringUtils.isBlank(outputLocation)) {
  return null;
 }
 Type sdiType = cas.getTypeSystem().getType(TextMarkerEngine.SOURCE_DOCUMENT_INFORMATION);
 String filename = "output.modified.html";
 File file = new File(outputLocation, filename);
 if (sdiType != null) {
  FSIterator<AnnotationFS> sdiit = cas.getAnnotationIndex(sdiType).iterator();
  if (sdiit.isValid()) {
   AnnotationFS annotationFS = sdiit.get();
   Feature uriFeature = sdiType.getFeatureByBaseName("uri");
   String stringValue = annotationFS.getStringValue(uriFeature);
   File f = new File(stringValue);
   String name = f.getName();
   if (!name.endsWith(".modified.html")) {
    name = name + ".modified.html";
   }
   file = new File(outputLocation, name);
  }
 }
 return file;
}

代码示例来源:origin: org.apache.uima/textmarker-core

public void visitEndTag(Tag tag) {
 String name = getName(tag);
 AnnotationFS found = null;
 for (int i = annotationStack.size() - 1; i >= 0; i--) {
  AnnotationFS each = (AnnotationFS) annotationStack.get(i);
  // // Java 6:
  // Iterator<AnnotationFS> descendingIterator = annotationStack.descendingIterator();
  // while (descendingIterator.hasNext()) {
  // AnnotationFS each = (AnnotationFS) descendingIterator.next();
  Feature nameFeature = each.getType().getFeatureByBaseName("name");
  String eachName = each.getStringValue(nameFeature);
  if (name.equals(eachName)) {
   int endOffset = getEndOffset(tag);
   Feature endFeature = each.getType().getFeatureByBaseName("end");
   each.setIntValue(endFeature, endOffset);
   found = each;
   break;
  }
 }
 if (found != null) {
  annotationStack.remove(found);
  annotations.add(found);
 }
}

代码示例来源:origin: org.apache.uima/ruta-core

AnnotationFS annotationFS = sdiit.get();
Feature uriFeature = sdiType.getFeatureByBaseName("uri");
String stringValue = annotationFS.getStringValue(uriFeature);
File f = new File(stringValue);
String name = f.getName();

代码示例来源:origin: org.apache.uima/textmarker-core

AnnotationFS annotationFS = sdiit.get();
Feature uriFeature = sdiType.getFeatureByBaseName("uri");
String stringValue = annotationFS.getStringValue(uriFeature);
File f = new File(stringValue);
String name = f.getName();

代码示例来源:origin: Ailab403/ailab-mltk4j

public void processCas(CAS cas) throws ResourceProcessException {
 
 FSIndex categoryIndex = cas.getAnnotationIndex(mCategoryType);
 
 if (categoryIndex.size() > 0) {
  AnnotationFS categoryAnnotation  = 
    (AnnotationFS) categoryIndex.iterator().next();
  
  // add to event collection
  
  DocumentSample sample = new DocumentSample(
    categoryAnnotation.getStringValue(mCategoryFeature), 
    cas.getDocumentText());
  
  documentSamples.add(sample);
 }
}

代码示例来源:origin: org.apache.uima/ruta-core

AnnotationFS annotationFS = sdiit.get();
Feature uriFeature = sdiType.getFeatureByBaseName("uri");
String stringValue = annotationFS.getStringValue(uriFeature);
File f = new File(stringValue);
String name = f.getName();

代码示例来源:origin: fr.univ-nantes.julestar/uima-tokens-regex

private Object getValue(AnnotationFS annotation) {
  switch(valueType) {
  case TYPE_BOOLEAN:
    return annotation.getBooleanValue(getFeature(annotation));
  case TYPE_STRING:
    return annotation.getStringValue(getFeature(annotation));
  case TYPE_INT:
    return annotation.getIntValue(getFeature(annotation));
  case TYPE_FLOAT:
    return annotation.getFloatValue(getFeature(annotation));
  default:
    throw new IllegalStateException("Unknown value type: " + this.valueType);
  }
}

代码示例来源:origin: org.apache.uima/ruta-core

AnnotationFS annotationFS = sdiit.get();
Feature uriFeature = sdiType.getFeatureByBaseName("uri");
String stringValue = annotationFS.getStringValue(uriFeature);
File f = new File(stringValue);
String name = f.getName();

代码示例来源:origin: org.apache.uima/textmarker-core

AnnotationFS annotationFS = sdiit.get();
Feature uriFeature = sdiType.getFeatureByBaseName("uri");
String stringValue = annotationFS.getStringValue(uriFeature);
File f = new File(stringValue);
String name = f.getName();

代码示例来源:origin: de.tudarmstadt.ukp.dkpro.core/de.tudarmstadt.ukp.dkpro.core.api.io-asl

public IobEncoder(CAS aCas, Type aType, Feature aValueFeature, boolean aIob1)
{
  iob1 = aIob1;
  
  // fill map for whole JCas in order to efficiently encode IOB
  iobBeginMap = new Int2ObjectOpenHashMap<String>();
  iobInsideMap = new Int2ObjectOpenHashMap<String>();
  Map<AnnotationFS, Collection<AnnotationFS>> idx = CasUtil.indexCovered(aCas, aType,
      CasUtil.getType(aCas, Token.class));
  
  String lastValue = null;
  for (AnnotationFS chunk : CasUtil.select(aCas, aType)) {
    String value = chunk.getStringValue(aValueFeature);
    for (AnnotationFS token : idx.get(chunk)) {
      if (
          token.getBegin() == chunk.getBegin() && 
          (!iob1 || (lastValue != null && lastValue.equals(value)))
      ) {
        iobBeginMap.put(token.getBegin(), value);
      }
      else {
        iobInsideMap.put(token.getBegin(), value);
      }
    }
    
    lastValue = value;
  }
}

代码示例来源:origin: CLLKazan/UIMA-Ext

/**
 * search for a {@link DocumentMetadata} annotation in given CAS and return
 * its 'sourceUri' feature value
 *
 * @param cas
 * @return sourceUri value or null if there is no a DocumentMetadata
 *         annotation
 */
public static String getDocumentUri(CAS cas) {
  TypeSystem ts = cas.getTypeSystem();
  Type docMetaType = ts.getType(getMetadataTypeName());
  if (docMetaType == null) {
    return null;
  }
  Feature sourceUriFeat;
  try {
    sourceUriFeat = featureExist(docMetaType, "sourceUri");
  } catch (AnalysisEngineProcessException e) {
    throw new IllegalStateException(e);
  }
  FSIterator<AnnotationFS> dmIter = cas.getAnnotationIndex(docMetaType).iterator();
  if (dmIter.hasNext()) {
    AnnotationFS docMeta = dmIter.next();
    return docMeta.getStringValue(sourceUriFeat);
  } else {
    return null;
  }
}

代码示例来源:origin: dkpro/dkpro-core

public IobEncoder(CAS aCas, Type aType, Feature aValueFeature, boolean aIob1)
{
  iob1 = aIob1;
  
  // fill map for whole JCas in order to efficiently encode IOB
  iobBeginMap = new Int2ObjectOpenHashMap<String>();
  iobInsideMap = new Int2ObjectOpenHashMap<String>();
  Map<AnnotationFS, Collection<AnnotationFS>> idx = CasUtil.indexCovered(aCas, aType,
      CasUtil.getType(aCas, Token.class));
  
  String lastValue = null;
  for (AnnotationFS chunk : CasUtil.select(aCas, aType)) {
    String value = chunk.getStringValue(aValueFeature);
    for (AnnotationFS token : idx.get(chunk)) {
      if (
          token.getBegin() == chunk.getBegin() && 
          (!iob1 || (lastValue != null && lastValue.equals(value)))
      ) {
        iobBeginMap.put(token.getBegin(), value);
      }
      else {
        iobInsideMap.put(token.getBegin(), value);
      }
    }
    
    lastValue = value;
  }
}

代码示例来源:origin: org.apache.uima/ConceptMapper

public DictionaryToken(AnnotationFS annotation, Feature tokenTypeFeature, Feature tokenClassFeature) {
 super();
 if (tokenTypeFeature == null)
 {
  this.setTokenTypeFeatureDefined(false);
 }
 else
 {
  this.setTokenTypeFeatureDefined(true);
  this.setType(annotation.getIntValue(tokenTypeFeature));
 }
 if (tokenClassFeature == null)
 {
  this.setTokenClassFeatureDefined(false);
 }
 else
 {
  this.setTokenClassFeatureDefined(true);
  this.setTokenClass(annotation.getStringValue(tokenClassFeature));
 }
 this.setText(annotation.getCoveredText());
}

相关文章