本文整理汇总了Java中org.apache.uima.cas.FSIterator类的典型用法代码示例。如果您正苦于以下问题:Java FSIterator类的具体用法?Java FSIterator怎么用?Java FSIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FSIterator类属于org.apache.uima.cas包,在下文中一共展示了FSIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CasViewProcessor
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
@Inject
CasViewProcessor(Client client,
FeatureStructureProcessorFactory featureStructureProcessorFactory,
@Assisted CasProcessorSettings casProcessorSettings,
@Assisted SofaData sofaData) throws InterruptedException {
this.client = client;
this.featureStructureProcessorFactory = featureStructureProcessorFactory;
this.casProcessorSettings = casProcessorSettings;
typeSystemInfo = casProcessorSettings.getTypeSystemInfo();
casProcessingDelegate = casProcessorSettings.getCasProcessingDelegate();
this.sofaData = sofaData;
this.fsRefQueue = sofaData.getFsRefQueue();
CAS cas = sofaData.getCas();
lowLevelCAS = cas.getLowLevelCAS();
Type topType = cas.getTypeSystem().getTopType();
FSIterator<FeatureStructure> allIndexedFS = cas.getIndexRepository().getAllIndexedFS(topType);
while (allIndexedFS.hasNext()) {
sofaData.getIdentifierForFs(allIndexedFS.next());
}
}
示例2: removeInvalids
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Postprocessing: Remove invalid timex expressions. These are already
* marked as invalid: timexValue().equals("REMOVE")
*
* @param jcas
*/
public void removeInvalids(JCas jcas) {
/*
* Iterate over timexes and add invalids to HashSet
* (invalids cannot be removed directly since iterator is used)
*/
FSIterator iterTimex = jcas.getAnnotationIndex(Timex3.type).iterator();
HashSet<Timex3> hsTimexToRemove = new HashSet<Timex3>();
while (iterTimex.hasNext()) {
Timex3 timex = (Timex3) iterTimex.next();
if (timex.getTimexValue().equals("REMOVE")) {
hsTimexToRemove.add(timex);
}
}
// remove invalids, finally
for (Timex3 timex3 : hsTimexToRemove) {
timex3.removeFromIndexes();
this.timex_counter--;
Logger.printDetail(timex3.getTimexId()+" REMOVING PHASE: "+"found by:"+timex3.getFoundByRule()+" text:"+timex3.getCoveredText()+" value:"+timex3.getTimexValue());
}
}
示例3: getPosFromMatchResult
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Identify the part of speech (POS) of a MarchResult.
* @param tokBegin
* @param tokEnd
* @param s
* @param jcas
* @return
*/
public String getPosFromMatchResult(int tokBegin, int tokEnd, Sentence s, JCas jcas) {
// get all tokens in sentence
HashMap<Integer, Token> hmTokens = new HashMap<Integer, Token>();
FSIterator iterTok = jcas.getAnnotationIndex(Token.type).subiterator(s);
while (iterTok.hasNext()) {
Token token = (Token) iterTok.next();
hmTokens.put(token.getBegin(), token);
}
// get correct token
String pos = "";
if (hmTokens.containsKey(tokBegin)) {
Token tokenToCheck = hmTokens.get(tokBegin);
pos = tokenToCheck.getPos();
}
return pos;
}
示例4: isValidDCT
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Check whether or not a jcas object has a correct DCT value.
* If there is no DCT present, we canonically return true since
* fallback calculation takes care of that scenario.
* @param jcas
* @return Whether or not the given jcas contains a valid DCT
*/
private Boolean isValidDCT(JCas jcas) {
FSIterator dctIter = jcas.getAnnotationIndex(Dct.type).iterator();
if(!dctIter.hasNext()) {
return true;
} else {
Dct dct = (Dct) dctIter.next();
String dctVal = dct.getValue();
if(dctVal == null)
return false;
if(dctVal.matches("\\d{8}") // Something like 20041224
|| dctVal.matches("\\d{4}.\\d{2}.\\d{2}.*")) { // Something like 2004-12-24
return true;
} else {
return false;
}
}
}
示例5: process
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
@Override
public void process(JCas jcas)
throws AnalysisEngineProcessException {
try {
FSIterator ccptaIterator = jcas.getAnnotationIndex(CCPTextAnnotation.type).iterator();
while (ccptaIterator.hasNext()) {
CCPTextAnnotation ccpta = (CCPTextAnnotation) ccptaIterator.next();
String ccptaMentionName = ccpta.getClassMention().getMentionName();
if (ccptaMentionName != null) {
Matcher m = mentionTypeInPattern.matcher(ccptaMentionName);
if ( m.matches() ) {
CCPClassMention ccpcm = ccpta.getClassMention();
ccpcm.setMentionName(mentionTypeOut);
UIMA_Util.addSlotValue(ccpcm, "ID", ccptaMentionName);
}
}
}
} catch (CASException e) {
e.printStackTrace();
throw new AnalysisEngineProcessException();
}
}
示例6: printEntityAnnotations
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* outputs the Tx lines from BioNLP. Where in BioNLP '09, they were just labelled
* "Protein", these may be other classes of things. The ID is mapped to such
* classes by the function mapUimaToBionlp().
*
* Ex. T1<tab>entity-class-name 21 29<tab>covered text
*
* Ex. T1 Protein 21 29 P41
*/
private void printEntityAnnotations(JCas jcas) throws IOException {
FSIterator taIterator = jcas.getAnnotationIndex(CCPTextAnnotation.type).iterator();
while (taIterator.hasNext()) {
CCPTextAnnotation ta = (CCPTextAnnotation) taIterator.next();
entityCount++;
String mentionName = ta.getClassMention().getMentionName();
String entityClassName = mapUimaToBionlp(mentionName);
if (entityClassName != null) {
// T1<tab>class-name 21 29<tab>covered text
String entityStr = "T" + entityCount + "\t" + entityClassName + " " + ta.getBegin() + " " + ta.getEnd()
+ "\t" + ta.getCoveredText().replaceAll("\\n"," ").trim();
logger.debug("[" + ta.getBegin() + ".." + ta.getEnd() + "] " + entityClassName + " " + entityCount + " from mentioname: " + mentionName);
FileWriterUtil.printLines(CollectionsUtil.createList(entityStr), entityWriter);
}
else {
logger.warn("No mapping for class mention name: " + mentionName);
}
}
}
示例7: checkForTheSameBoundaries
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
public static void checkForTheSameBoundaries(CAS cas, Class<? extends AnnotationFS> typeClass) {
Type type = CasUtil.getType(cas, typeClass);
FSIterator<AnnotationFS> iter = cas.getAnnotationIndex(type).iterator();
iter.moveToFirst();
if (!iter.isValid()) {
return;
}
AnnotationOffsetComparator<AnnotationFS> cmp =
AnnotationOffsetComparator.instance(AnnotationFS.class);
AnnotationFS lastAnno = iter.get();
iter.moveToNext();
while (iter.isValid()) {
AnnotationFS anno = iter.get();
if (cmp.compare(anno, lastAnno) == 0) {
throw new IllegalStateException(String.format(
"Annotations %s and %s have the same boundaries",
lastAnno, anno));
}
iter.moveToNext();
}
}
示例8: getNext
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Return next element if exists.
*
* @param iter iterator
* @param anchor an anchor
* @return next element if exists or null otherwise
*/
private static Token getNext(FSIterator<Token> iter, TokenBase anchor) {
iter.moveTo(anchor);
// now the current fs either greater (for tokens seq it means 'after') or equal to the anchor
if (iter.isValid()) {
Token result = iter.get();
if (result.equals(anchor)) {
iter.moveToNext();
if (iter.isValid()) {
return iter.get();
} else {
return null;
}
} else {
return result;
}
} else {
return null;
}
}
示例9: getPrevious
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Return previous element if exists.
*
* @param iter iterator
* @param anchor an anchor
* @return previous element if exists or null otherwise
*/
private static Token getPrevious(FSIterator<Token> iter, TokenBase anchor) {
iter.moveTo(anchor);
// now the current fs either greater (for tokens seq it means 'after') or equal to the anchor
if (iter.isValid()) {
// in any case we should move backward (true for disjoint token segmentation)
iter.moveToPrevious();
if (iter.isValid()) {
return iter.get();
} else {
return null;
}
} else {
// check for a case when anchor is after the last visible token
iter.moveToLast();
if (iter.isValid()) {
return iter.get();
} else {
return null;
}
}
}
示例10: normalizeSpaceBetween
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
private String normalizeSpaceBetween(FSIterator<TokenBase> tbIter, final Token x, final Token y) {
// X must be before Y
Preconditions.checkArgument(x == null || y == null || x.getCAS().getAnnotationIndex().compare(x, y) < 0);
if (x == null) {
tbIter.moveToFirst();
} else {
tbIter.moveTo(x);
}
while (// if Y is null then iterate till the end
(y == null && tbIter.isValid())
// else - iterate till the Y
|| (y != null && !tbIter.get().equals(y))) {
if (tbIter.get() instanceof BREAK) {
return "\n";
}
tbIter.moveToNext();
}
return " ";
}
示例11: get
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Get the {@link org.dkpro.argumentation.types.WebArgumentMetadata} from the JCas.
*
* @throws IllegalArgumentException if no {@link DocumentMetaData} exists in the jCas
*/
public static WebArgumentMetadata get(final JCas jCas)
{
FSIterator<FeatureStructure> iterator = jCas.getCas().getIndexRepository().getAllIndexedFS(
CasUtil.getType(jCas.getCas(), WebArgumentMetadata.class));
if (!iterator.hasNext()) {
throw new IllegalArgumentException(new Throwable("CAS does not contain any "
+ WebArgumentMetadata.class.getName()));
}
WebArgumentMetadata result = (WebArgumentMetadata) iterator.next();
if (iterator.hasNext()) {
throw new IllegalArgumentException(new Throwable("CAS contains more than one "
+ WebArgumentMetadata.class.getName()));
}
return result;
}
示例12: doProcess
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
@Override
public void doProcess(JCas jCas) throws AnalysisEngineProcessException {
FSIterator<Annotation> iter = jCas.getAnnotationIndex(Entity.type).iterator();
while (iter.hasNext()) {
Entity e = (Entity) iter.next();
if (Strings.isNullOrEmpty(e.getValue())) {
getMonitor().debug("No value set for entity '{}' - skipping", e.getCoveredText());
continue;
}
if (this.shouldNormalize(e)) {
String normalized = this.normalize(e);
if (!normalized.equals(e.getValue())) {
e.setValue(normalized);
e.setIsNormalised(true);
}
}
}
}
示例13: doProcess
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
@Override
public void doProcess(JCas aJCas) throws AnalysisEngineProcessException {
List<Entity> toRemove = new ArrayList<Entity>();
FSIterator<Annotation> iter = aJCas.getAnnotationIndex(Entity.type).iterator();
while(iter.hasNext()){
Entity e = (Entity) iter.next();
if(e.getConfidence() < confidenceThreshold && (!ignoreZeroConfidence || e.getConfidence() > 0.0)){
toRemove.add(e);
getMonitor().debug("Low confidence entity found (ID: {}) - this entity will be removed", e.getInternalId());
}
}
removeFromJCasIndex(toRemove);
}
示例14: getLastSentenceInDisplayWindow
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
/**
* Get the last sentence CAS address in the current display window
*
* @param aJcas
* the JCas.
* @param aFirstSentenceAddress
* the CAS address of the first sentence in the display window
* @param aWindowSize
* the window size
* @return The address of the last sentence address in the current display window.
*/
public static Sentence getLastSentenceInDisplayWindow(JCas aJcas, int aFirstSentenceAddress,
int aWindowSize)
{
int count = 0;
FSIterator<Sentence> si = seekByAddress(aJcas, Sentence.class, aFirstSentenceAddress);
Sentence s = si.get();
while (count < aWindowSize - 1) {
si.moveToNext();
if (si.isValid()) {
s = si.get();
}
else {
break;
}
count++;
}
return s;
}
示例15: getNonIndexedFSesWithOwner
import org.apache.uima.cas.FSIterator; //导入依赖的package包/类
public static Map<FeatureStructure, FeatureStructure> getNonIndexedFSesWithOwner(CAS aCas)
{
TypeSystem ts = aCas.getTypeSystem();
LowLevelCAS llcas = aCas.getLowLevelCAS();
Set<FeatureStructure> allIndexedFS = collectIndexed(aCas);
Map<FeatureStructure, FeatureStructure> allReachableFS = new TreeMap<>(
Comparator.comparingInt(llcas::ll_getFSRef));
FSIterator<FeatureStructure> i = aCas.getIndexRepository().getAllIndexedFS(
aCas.getTypeSystem().getTopType());
i.forEachRemaining(fs -> collect(allReachableFS, allIndexedFS, fs, fs));
// Remove all that are not annotations
allReachableFS.entrySet().removeIf(e ->
!ts.subsumes(aCas.getAnnotationType(), e.getKey().getType()));
// Remove all that are indexed
allReachableFS.entrySet().removeIf(e -> e.getKey() == e.getValue());
// All that is left are non-index annotations
return allReachableFS;
}