本文整理汇总了Java中org.apache.uima.jcas.cas.FSArray类的典型用法代码示例。如果您正苦于以下问题:Java FSArray类的具体用法?Java FSArray怎么用?Java FSArray使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FSArray类属于org.apache.uima.jcas.cas包,在下文中一共展示了FSArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createTreeFromTokens
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
/**
* Creates the ClearNLP Deptree from word tokens for a sentence.
*
* @param tokens
* the tokens
* @return the DEP tree
*/
private static DEPTree createTreeFromTokens(final List<WordToken> tokens) {
// Generate DEPTree from WordTokens
final DEPTree tree = new DEPTree(tokens.size());
int tokenIndex = 0;
for (final WordToken wt : tokens) {
final DEPNode node = new DEPNode(tokenIndex++, wt.getCoveredText());
node.setPOSTag(wt.getPartOfSpeech());
final FSArray lemmas = wt.getLemmas();
if (lemmas != null && lemmas.size() > 0) {
final WordLemma wl = (WordLemma) lemmas.get(0);
node.setLemma(wl.getLemmaForm());
}
tree.add(node);
}
return tree;
}
示例2: outputPattern
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
private void outputPattern(final JCas jCas, final PatternExtract pattern) {
final Pattern a = new Pattern(jCas);
a.setBegin(pattern.getStart());
a.setEnd(pattern.getEnd());
a.setSource(pattern.getFrom());
a.setTarget(pattern.getTo());
final List<WordToken> tokens = pattern.getWordTokens();
final FSArray array = new FSArray(jCas, tokens.size());
int i = 0;
for (final WordToken w : tokens) {
array.set(i, w);
i++;
}
a.setWords(array);
addToJCasIndex(a);
}
示例3: doProcess
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
@Override
protected void doProcess(JCas jCas) throws AnalysisEngineProcessException {
for (WordToken t : JCasUtil.select(jCas, WordToken.class)) {
if (t.getLemmas() == null || t.getLemmas().size() > 0) {
String text = t.getCoveredText();
POS pos = WordNetUtils.toPos(t.getPartOfSpeech());
if (pos != null) {
Optional<IndexWord> lookupWord = wordnet.lookupWord(pos, text);
if (lookupWord.isPresent()) {
t.setLemmas(new FSArray(jCas, 1));
WordLemma wordLemma = new WordLemma(jCas);
wordLemma.setLemmaForm(lookupWord.get().getLemma());
t.setLemmas(0, wordLemma);
}
}
}
}
}
示例4: setSlotValues
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public void setSlotValues(Collection<ClassMention> slotValues) throws InvalidInputException {
List<CCPClassMention> updatedClassMentions = new ArrayList<CCPClassMention>();
for (ClassMention cm : slotValues) {
Object wrappedClassMention = cm.getWrappedObject();
if (wrappedClassMention instanceof CCPClassMention) {
CCPClassMention ccpCM = (CCPClassMention) wrappedClassMention;
updatedClassMentions.add(ccpCM);
} else {
throw new InvalidInputException("Expected CCPClassMention. Cannot add class"
+ wrappedClassMention.getClass().getName()
+ " to the ClassMentions list of a CCPComplexSlotMention");
}
}
FSArray updatedCMs = new FSArray(jcas, updatedClassMentions.size());
for (int i = 0; i < updatedClassMentions.size(); i++) {
updatedCMs.set(i, updatedClassMentions.get(i));
}
wrappedCSM.setClassMentions(updatedCMs);
}
示例5: getSlotMentionByName
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static CCPSlotMention getSlotMentionByName(CCPClassMention ccpClassMention, String slotMentionName) {
FSArray slotMentionsArray = ccpClassMention.getSlotMentions();
if (slotMentionsArray != null) {
CCPSlotMention returnSlotMention = null;
for (int i = 0; i < slotMentionsArray.size(); i++) {
FeatureStructure fs = slotMentionsArray.get(i);
if (fs instanceof CCPSlotMention) {
CCPSlotMention ccpSlotMention = (CCPSlotMention) fs;
if (ccpSlotMention.getMentionName().equals(slotMentionName)) {
returnSlotMention = ccpSlotMention;
break;
}
} else {
logger.error("Expecting CCPSlotMention but got a : " + fs.getClass().getName());
}
}
return returnSlotMention;
} else {
return null;
}
}
示例6: getPrimitiveSlotMentionByName
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static CCPPrimitiveSlotMention getPrimitiveSlotMentionByName(CCPClassMention ccpClassMention,
String slotMentionName) {
FSArray slotMentionsArray = ccpClassMention.getSlotMentions();
if (slotMentionsArray != null) {
CCPPrimitiveSlotMention returnSlotMention = null;
for (int i = 0; i < slotMentionsArray.size(); i++) {
FeatureStructure fs = slotMentionsArray.get(i);
if (fs instanceof CCPPrimitiveSlotMention) {
CCPPrimitiveSlotMention ccpSlotMention = (CCPPrimitiveSlotMention) fs;
if (ccpSlotMention.getMentionName().equals(slotMentionName)) {
returnSlotMention = ccpSlotMention;
break;
}
}
}
return returnSlotMention;
} else {
return null;
}
}
示例7: getComplexSlotMentionByName
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static CCPComplexSlotMention getComplexSlotMentionByName(CCPClassMention ccpClassMention,
String slotMentionName) {
FSArray slotMentionsArray = ccpClassMention.getSlotMentions();
if (slotMentionsArray != null) {
CCPComplexSlotMention returnSlotMention = null;
for (int i = 0; i < slotMentionsArray.size(); i++) {
FeatureStructure fs = slotMentionsArray.get(i);
if (fs instanceof CCPComplexSlotMention) {
CCPComplexSlotMention ccpSlotMention = (CCPComplexSlotMention) fs;
if (ccpSlotMention.getMentionName().equals(slotMentionName)) {
returnSlotMention = ccpSlotMention;
break;
}
}
}
return returnSlotMention;
} else {
return null;
}
}
示例8: removeSlotMentions
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static void removeSlotMentions(CCPClassMention ccpCM, Class slotType, JCas jcas) {
List<CCPSlotMention> slotMentionsToKeep = new ArrayList<CCPSlotMention>();
FSArray slotMentions = ccpCM.getSlotMentions();
if (slotMentions != null) {
for (int i = 0; i < slotMentions.size(); i++) {
if (!(slotType.isInstance(slotMentions.get(i)))) {
slotMentionsToKeep.add((CCPSlotMention) slotMentions.get(i));
}
}
}
FSArray updatedSlotMentions = new FSArray(jcas, slotMentionsToKeep.size());
for (int i = 0; i < slotMentionsToKeep.size(); i++) {
updatedSlotMentions.set(i, slotMentionsToKeep.get(i));
}
ccpCM.setSlotMentions(updatedSlotMentions);
}
示例9: getMultipleSlotMentionsByName
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static List<CCPSlotMention> getMultipleSlotMentionsByName(CCPClassMention ccpClassMention,
String slotMentionName) {
List<CCPSlotMention> returnSlotMentions = new ArrayList<CCPSlotMention>();
FSArray slotMentionsArray = ccpClassMention.getSlotMentions();
if (slotMentionsArray != null) {
FeatureStructure[] slotMentions = slotMentionsArray.toArray();
for (FeatureStructure fs : slotMentions) {
CCPSlotMention ccpSlotMention = (CCPSlotMention) fs;
if (ccpSlotMention.getMentionName().equals(slotMentionName)) {
returnSlotMentions.add(ccpSlotMention);
}
}
return returnSlotMentions;
} else {
return null;
}
}
示例10: addSlotValue
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static void addSlotValue(CCPClassMention ccpClassMention, String slotMentionName,
CCPClassMention slotFillerCM) throws CASException {
CCPComplexSlotMention ccpComplexSlotMention = (CCPComplexSlotMention) UIMA_Util.getSlotMentionByName(
ccpClassMention, slotMentionName);
if (ccpComplexSlotMention == null) { // then we need to create a new
// CCPNonComplexSlotMention
JCas jcas = ccpClassMention.getCAS().getJCas();
ccpComplexSlotMention = new CCPComplexSlotMention(jcas);
ccpComplexSlotMention.setMentionName(slotMentionName);
FSArray classMentions = new FSArray(jcas, 1);
classMentions.set(0, slotFillerCM);
ccpComplexSlotMention.setClassMentions(classMentions);
addSlotMention(ccpClassMention, ccpComplexSlotMention);
} else {
addClassMentionAsCSMSlotFiller(ccpComplexSlotMention, slotFillerCM);
}
}
示例11: validateCCPClassMention
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
/**
* This method checks each slot mention associated with the input class mention for valid slot
* fillers. True is returned if the CCPClassMention has a valid mention structure, false
* otherwise.
*
* @param ccpTA
* @return
*/
public static boolean validateCCPClassMention(CCPClassMention ccpCM) {
boolean isValid = true;
FSArray shouldBeSlotMentions = ccpCM.getSlotMentions();
if (shouldBeSlotMentions != null) {
for (int i = 0; i < shouldBeSlotMentions.size(); i++) {
Object shouldBeSM = shouldBeSlotMentions.get(i);
if (shouldBeSM != null) {
if (shouldBeSM instanceof CCPSlotMention) {
return validateCCPSlotMention((CCPSlotMention) shouldBeSM);
} else {
logger.error("Invalid mention structure detected. Unexpected object found in FSArray holding CCPSlotMentions for the CCPClassMention: \""
+ ccpCM.getMentionName() + "\" -- " + shouldBeSM.getClass().getName());
logger.debug("Returning false from validateCCPClassMention() mid1");
return false;
}
}
}
}
logger.debug("Returning " + isValid + " from validateCCPClassMention() end");
return isValid;
}
示例12: validateCCPComplexSlotMention
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
/**
* This method checks for valid slot fillers of the input CCPComplexSlotMention, i.e. slot
* fillers must be valid CCPClassMentions. True is returned if the CCPClassMention has a valid
* mention structure, false otherwise.
*
* @param ccpTA
* @return
*/
public static boolean validateCCPComplexSlotMention(CCPComplexSlotMention ccpCSM) {
boolean isValid = true;
FSArray slotValues = ccpCSM.getClassMentions();
if (slotValues != null) {
for (int i = 0; i < slotValues.size(); i++) {
Object shouldBeAClassMention = slotValues.get(i);
if (shouldBeAClassMention != null) {
if (shouldBeAClassMention instanceof CCPClassMention) {
isValid = isValid && validateCCPClassMention((CCPClassMention) shouldBeAClassMention);
} else {
logger.error("Invalid mention structure discovered. Instead of a CCPClassMention, this slot filler for this CCPComplexSlotMention is a: "
+ shouldBeAClassMention.getClass().getName());
logger.debug("Returning false from validateCCPComplexSlotMention()");
return false;
}
}
}
}
logger.debug("Returning " + isValid + " from validateCCPComplexSlotMention() end");
return isValid;
}
示例13: createCCPTextAnnotation
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
public static CCPTextAnnotation createCCPTextAnnotation(String mentionType, int[] span, JCas jcas,
CCPAnnotator annotatorInfo, CCPAnnotationSet annotationSetInfo) {
CCPTextAnnotation ccpTA = new CCPTextAnnotation(jcas);
int startIndex = span[0];
int endIndex = span[1];
ccpTA.setBegin(startIndex);
ccpTA.setEnd(endIndex);
/* create span */
FSArray ccpSpans = new FSArray(jcas, 1);
CCPSpan ccpSpan = new CCPSpan(jcas);
ccpSpan.setSpanStart(startIndex);
ccpSpan.setSpanEnd(endIndex);
ccpSpans.set(0, ccpSpan);
ccpTA.setSpans(ccpSpans);
ccpTA.setAnnotator(annotatorInfo);
FSArray asets = new FSArray(jcas, 1);
asets.set(0, annotationSetInfo);
ccpTA.setAnnotationSets(asets);
ccpTA.setDocumentSectionID(-1);
CCPClassMention ccpCM = new CCPClassMention(jcas);
ccpCM.setMentionName(mentionType);
ccpTA.setClassMention(ccpCM);
ccpCM.setCcpTextAnnotation(ccpTA);
ccpTA.addToIndexes();
return ccpTA;
}
示例14: updateAggregateSpan
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
/**
*
* Extracts the aggregate span from the individual CCPSpans in the CCPTextAnnotation span list
*
*
*
* @param ccpTA
*
* @throws KnowledgeRepresentationWrapperException
*/
public static void updateAggregateSpan(CCPTextAnnotation ccpTA) throws KnowledgeRepresentationWrapperException {
FSArray spanList = ccpTA.getSpans();
if (spanList != null) {
int aggregateSpanStart = Integer.MAX_VALUE;
int aggregateSpanEnd = Integer.MIN_VALUE;
for (int i = 0; i < spanList.size(); i++) {
CCPSpan span = getExpectedSpan(spanList.get(i));
if (span.getSpanStart() < aggregateSpanStart) {
aggregateSpanStart = span.getSpanStart();
}
if (span.getSpanEnd() > aggregateSpanEnd) {
aggregateSpanEnd = span.getSpanEnd();
}
}
ccpTA.setBegin(aggregateSpanStart);
ccpTA.setEnd(aggregateSpanEnd);
} else {
throw new KnowledgeRepresentationWrapperException(
"Cannot update aggregate span, the CCPTextAnnotation has no span list.");
}
}
示例15: getLeadingSpan
import org.apache.uima.jcas.cas.FSArray; //导入依赖的package包/类
/**
*
* Returns the left-most CCPSpan in the span list.
*
*
*
* @param ccpTA
*
* @return
*
* @throws KnowledgeRepresentationWrapperException
*/
private static CCPSpan getLeadingSpan(CCPTextAnnotation ccpTA) throws KnowledgeRepresentationWrapperException {
FSArray spanList = ccpTA.getSpans();
if (spanList != null && spanList.size() > 0) {
CCPSpan leadingSpan = getExpectedSpan(spanList.get(0));
for (int i = 1; i < spanList.size(); i++) {
CCPSpan span = getExpectedSpan(spanList.get(i));
if (span.getSpanStart() < leadingSpan.getSpanStart()) {
leadingSpan = span;
}
}
return leadingSpan;
} else {
throw new KnowledgeRepresentationWrapperException(
"Cannot get leading span, the CCPTextAnnotation has no span list.");
}
}