本文整理汇总了Java中org.uimafit.util.JCasUtil类的典型用法代码示例。如果您正苦于以下问题:Java JCasUtil类的具体用法?Java JCasUtil怎么用?Java JCasUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JCasUtil类属于org.uimafit.util包,在下文中一共展示了JCasUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
Collection<CCPTextAnnotation> allAnnotations = new ArrayList<CCPTextAnnotation>();
for (Iterator<Annotation> annotIter = JCasUtil.iterator(jcas, Annotation.class); annotIter.hasNext();) {
Object possibleAnnot = annotIter.next();
if (possibleAnnot instanceof CCPTextAnnotation) {
allAnnotations.add((CCPTextAnnotation) possibleAnnot);
} else {
logger.warn("CCPTextAnnotation expected but instead got " + possibleAnnot.getClass().getName());
}
}
Collection<CCPTextAnnotation> redundantAnnotations = getRedundantAnnotations(allAnnotations);
int count = 0;
for (CCPTextAnnotation ccpTA : redundantAnnotations) {
ccpTA.removeFromIndexes();
count++;
}
logger.info("DuplicateAnnotationRemovalFilter Removed " + count + " duplicate annotations.");
}
示例2: indexDepTree
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
protected Map<String, String> indexDepTree(JCas text) {
Map<String, String> depTree = new HashMap<String, String>();
// format: key: 1 ### word ### pos; value: dep_rel ## 2 ### word ### pos
// escape: .replace("#", "\\#")
// depTree.put("1 ### The ### Det", "DET ## 2 ### dog ### N");
// depTree.put("2 ### dog ### N", "SUBJ ## 3 ### chases ### V");
// depTree.put("3 ### chases ### V", "ROOT ## 0 ### NULL ### NULL");
// depTree.put("4 ### The ### Det", "DET ## 5 ### cat ### N");
// depTree.put("5 ### cat ### N", "OBJ ## 3 ### chases ### V");
for (Dependency dep : JCasUtil.select(text, Dependency.class)) {
Token child = dep.getDependent();
Token parent = dep.getGovernor();
depTree.put(child.getBegin() + " ### "
+ child.getCoveredText().replace("#", "\\#") + " ### "
+ child.getPos().getPosValue(), dep.getDependencyType()
+ " ## " + parent.getBegin() + " ### "
+ parent.getCoveredText().replace("#", "\\#") + " ### "
+ parent.getPos().getPosValue());
}
return depTree;
}
示例3: indexLemmaDepTree
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
protected Map<String, String> indexLemmaDepTree(JCas text) {
Map<String, String> depTree = new HashMap<String, String>();
for (Dependency dep : JCasUtil.select(text, Dependency.class)) {
Token child = dep.getDependent();
Token parent = dep.getGovernor();
depTree.put(child.getBegin() + " ### "
+ child.getLemma().getValue().replace("#", "\\#") + " ### "
+ child.getPos().getPosValue(), dep.getDependencyType()
+ " ## " + parent.getBegin() + " ### "
+ parent.getLemma().getValue().replace("#", "\\#")
+ " ### " + parent.getPos().getPosValue());
}
return depTree;
}
示例4: convertCasToTrees
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
/**
*
* @param jcas a JCas created by an EOP LAP
* @return A list of roots, each belonging to a BIU dependency parse tree of a sentence in the CAS. Trees are ordered by sentence order.
* @throws CasTreeConverterException
* @throws UnsupportedPosTagStringException
*/
public List<BasicNode> convertCasToTrees(JCas jcas) throws CasTreeConverterException, UnsupportedPosTagStringException {
Collection<Sentence> sentenceAnnotations = JCasUtil.select(jcas, Sentence.class);
lastSentenceList = new ArrayList<Sentence>(sentenceAnnotations);
lastTokenToNodeBySentence = new LinkedHashMap<Sentence, OneToManyBidiMultiHashMap<Token,BasicNode>>();
lastRootList = new ArrayList<BasicNode>(sentenceAnnotations.size());
lastSentenceToRoot = new DualHashBidiMap<>();
for (Sentence sentenceAnno : lastSentenceList) {
BasicNode root = convertSentenceToTree(jcas, sentenceAnno);
lastSentenceToRoot.put(sentenceAnno, root);
lastRootList.add(root);
OneToManyBidiMultiHashMap<Token,BasicNode> tokenToNodeCopy = new OneToManyBidiMultiHashMap<Token,BasicNode>(tokenToNode);
lastTokenToNodeBySentence.put(sentenceAnno, tokenToNodeCopy);
}
return lastRootList;
}
示例5: buildNodeInfo
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
private static NodeInfo buildNodeInfo(JCas jcas, Token tokenAnno, int serial) throws CasTreeConverterException, UnsupportedPosTagStringException {
String word = tokenAnno.getCoveredText();
String lemma = tokenAnno.getLemma().getValue();
String pos = tokenAnno.getPos().getPosValue();
// We rely on the fact the NamedEntity enum values have the same names as the ones
// specified in the DKPro mapping (e.g. PERSON, ORGANIZATION)
eu.excitementproject.eop.common.representation.parse.representation.basic.NamedEntity namedEntity=null;
List<NamedEntity> namedEntities = JCasUtil.selectCovered(NamedEntity.class, tokenAnno);
switch (namedEntities.size()) {
case 0: break; // if no NER - ignore and move on
case 1: namedEntity = eu.excitementproject.eop.common.representation.parse.representation.basic.NamedEntity.valueOf(namedEntities.get(0).getValue());
break;
default: throw new CasTreeConverterException(String.format("Got %d NamedEntity annotations for token %s", namedEntities.size(), tokenAnno));
}
return new DefaultNodeInfo(word, lemma, serial, namedEntity, new DefaultSyntacticInfo(new PennPartOfSpeech(pos)));
}
示例6: process
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Override
public void process(JCas aCAS) throws AnalysisEngineProcessException {
Token t;
this.jcas=aCAS;
for(Substitution s : JCasUtil.select(jcas, Substitution.class)) {
System.out.println(s.toString());
assert(s.getSenseclass().equals("[email protected]@1"));
assert(s.getBegin()==37);
}
}
示例7: convertCasToPairData
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
/**
* Converts a JCas created by an EOP LAP, to BIU's PairData.
* @param jcas
* @return
* @throws CasTreeConverterException
* @throws UnsupportedPosTagStringException
* @throws CASException
* @throws EDAException
*/
public static PairData convertCasToPairData(JCas jcas) throws CasTreeConverterException, UnsupportedPosTagStringException, CASException, EDAException {
Pair pairAnno = JCasUtil.selectSingle(jcas, Pair.class);
Text textAnno = pairAnno.getText();
Hypothesis hypothesisAnno = pairAnno.getHypothesis();
JCas textView = jcas.getView(LAP_ImplBase.TEXTVIEW);
JCas hypothesisView = jcas.getView(LAP_ImplBase.HYPOTHESISVIEW);
Integer id = null;
String stringID = pairAnno.getPairID();
try {
id = Integer.valueOf(stringID);
}
catch (NumberFormatException e) {
// Ignore
}
RTEClassificationType gold = null;
String goldString = pairAnno.getGoldAnswer();
if (goldString != null) {
DecisionLabel goldDecision = DecisionLabel.getLabelFor(goldString);
gold = DecisionTypeMap.toRTEClassificationType(goldDecision);
}
CasTreeConverter converter = new CasTreeConverter();
List<BasicNode> textTrees = converter.convertCasToTrees(textView);
Map<BasicNode, String> mapTreesToSentences = converter.getTreesToSentences();
Sentence hypothesisSentence = JCasUtil.selectSingle(hypothesisView, Sentence.class);
BasicNode hypothesisTree = converter.convertSingleSentenceToTree(hypothesisView, hypothesisSentence);
// Currently not supporting coreference information - using empty map
TreeCoreferenceInformation<BasicNode> coreferenceInformation = new TreeCoreferenceInformation<BasicNode>();
TextHypothesisPair pair = new TextHypothesisPair(textAnno.getCoveredText(), hypothesisAnno.getCoveredText(), id, gold, null);
return new PairData(pair, textTrees, hypothesisTree, mapTreesToSentences, coreferenceInformation);
}
示例8: selectLinksWith
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
/**
* This utility method fetches alignment.Link instances that links the give
* "Type" of annotations. More specifically, the method returns all link
* instances that connects Targets, which holds the give "type".
*
* For example, a call with type=Token.class will return all Link instances
* where either of its TSideTarget or HSideTarget holds "Token" annotation.
*
* The method will return all link instances, if one of its Targets hold
* the given the type.
*
* @param jCas the JCas with EOP views
* @param type target annotation class.
* @return a List<Link> that holds all links that satisfy the condition. If none satisfy the condition, it will return an empty List.
*/
public static <T extends TOP> List<Link> selectLinksWith(JCas aJCas, Class<T> type) throws CASException
{
List<Link> resultList = new ArrayList<Link>();
JCas hypoView = aJCas.getView("HypothesisView");
// get Links that satisfy the condition by iterating all Links just once.
for (Link l : JCasUtil.select(hypoView, Link.class))
{
// is this link holds type object in either of its target?
Target tt = l.getTSideTarget();
Target ht = l.getHSideTarget();
if (JCasUtil.select(tt.getTargetAnnotations(), type).size() > 0)
{
// T side target does hold at least one of type instance.
resultList.add(l);
continue; // no need to check h side target
}
if (JCasUtil.select(ht.getTargetAnnotations(), type).size() > 0)
{
// H side target does hold at least one of type instance.
resultList.add(l);
}
}
return resultList;
}
示例9: process
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Override
public ClassificationTEDecision process(JCas jcas)
throws EDAException, ComponentException
{
Pair pair = JCasUtil.selectSingle(jcas, Pair.class);
// Compute similarity scores with all components
List<Double> scores = new ArrayList<Double>();
for (ScoringComponent component : getComponents())
{
Vector<Double> subscores = component.calculateScores(jcas);
scores.addAll(subscores);
}
// If multiple components have been used, we use the highest score
// to determine the Entailment/NonEntailment relationship.
// This is intended for illustration purposes only, as the similarity
// scores are not normally distributed.
double maxScore = Collections.max(scores);
DecisionLabel label;
if (maxScore >= threshold)
label = DecisionLabel.Entailment;
else
label = DecisionLabel.NonEntailment;
return new ClassificationTEDecision(label,
scores.get(0),
pair.getPairID());
}
示例10: getPhraseCandidatesFromSOFA
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
/**
* This method is a helper utility that is required to look up Meteor Phrase tables.
*
* Basically, returns all possible phrase candidates up to N words in a List<String>
*
* The method uses Token annotation in JCas to generate possible candidates. Thus,
* a tokenization annotator should have annotated this JCas before.
*
* @param JCas aJCas The view, that holds the sentence(s) to be analyzed.
* @param int uptoN The maximum number of
* @return
*/
public static List<String> getPhraseCandidatesFromSOFA(JCas aJCas, int uptoN)
{
// sanity check
assert(aJCas !=null);
assert(uptoN > 0);
// list for result,
List<String> result = new ArrayList<String>();
// ok. work. first;
// get all Tokens (by appearing orders...)
Collection<Token> t = JCasUtil.select(aJCas, Token.class);
Token[] tokens = t.toArray(new Token[t.size()]);
// then;
// for each Token, start uptoN process.
for(int i=0; i < tokens.length; i++)
{
for(int j=0; (j < uptoN) && (i+j < tokens.length); j++ )
{
Token leftEnd = tokens[i];
Token rightEnd = tokens[i+j];
String text = aJCas.getDocumentText().substring(leftEnd.getBegin(), rightEnd.getEnd());
// and store in lower case.
result.add(text.toLowerCase());
}
}
// done
// all candidates are store here.
return result;
}
示例11: tokensBetween
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
private static List<Token> tokensBetween(JCas aJCas, int from, int to)
{
List<Token> tokenList = new ArrayList<Token>();
for (Token token: JCasUtil.select(aJCas, Token.class))
{
if ( (token.getBegin() >= from) && (token.getEnd() <= to))
{
tokenList.add(token);
}
}
return tokenList;
}
示例12: getTokenAnnotations
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
/**
* Uses the annotations in the CAS and extracts the tokens and
* their lemmas from the text and hypothesis views
* @param aJCas The JCas object of the text and hypothesis,
* after tokenization and lemmatization.
* @throws CASException
*/
private void getTokenAnnotations(JCas aJCas) throws CASException {
// Get the text and hypothesis views
JCas textView = aJCas.getView(LAP_ImplBase.TEXTVIEW);
JCas hypoView = aJCas.getView(LAP_ImplBase.HYPOTHESISVIEW);
// Get the tokens
textTokens = new ArrayList<Token>(JCasUtil.select(textView, Token.class));
hypoTokens = new ArrayList<Token>(JCasUtil.select(hypoView, Token.class));
}
示例13: calculateScores
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Override
public Vector<Double> calculateScores(JCas cas)
throws ScoringComponentException {
// all the values: (T&H/H), (T&H/T), and ((T&H/H)*(T&H/T))
Vector<Double> scoresVector = new Vector<Double>();
try {
JCas tView = cas.getView("TextView");
HashMap<String, Integer> tBag = countTokens(tView);
JCas hView = cas.getView("HypothesisView");
HashMap<String, Integer> hBag = countTokens(hView);
scoresVector.addAll(calculateSimilarity(tBag, hBag));
String task = JCasUtil.select(cas, EntailmentMetadata.class).iterator().next().getTask();
if (null == task) {
scoresVector.add(0d);
scoresVector.add(0d);
scoresVector.add(0d);
scoresVector.add(0d);
} else {
scoresVector.add(isTaskIE(task));
scoresVector.add(isTaskIR(task));
scoresVector.add(isTaskQA(task));
scoresVector.add(isTaskSUM(task));
}
} catch (CASException e) {
throw new ScoringComponentException(e.getMessage());
}
return scoresVector;
}
示例14: process
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
try {
CAS cas = jcas.getCas();
mappingProvider.configure(cas);
for (Sentence sentenceAnno : JCasUtil.select(jcas, Sentence.class)) {
List<Token> tokens = JCasUtil.selectCovered(jcas, Token.class, sentenceAnno);
List<String> tokenStrings = JCasUtil.toText(tokens);
List<PosTaggedToken> taggedTokens;
synchronized (innerTool) {
innerTool.setTokenizedSentence(tokenStrings);
innerTool.process();
taggedTokens = innerTool.getPosTaggedTokens();
}
if (taggedTokens.size() != tokens.size()) {
throw new PosTaggerException("Got pos tagging for " + taggedTokens.size() +
" tokens, should have gotten according to the total number of tokens in the sentence: " + tokens.size());
}
Iterator<Token> tokenIter = tokens.iterator();
for (PosTaggedToken taggedToken : taggedTokens) {
Token tokenAnno = tokenIter.next();
String tagString = taggedToken.getPartOfSpeech().getStringRepresentation();
// Get an annotation with the appropriate UIMA type via the mappingProvider
Type posTag = mappingProvider.getTagType(tagString);
POS posAnnotation = (POS) cas.createAnnotation(posTag, tokenAnno.getBegin(), tokenAnno.getEnd());
posAnnotation.setPosValue(tagString);
posAnnotation.addToIndexes();
tokenAnno.setPos(posAnnotation);
}
}
} catch (PosTaggerException e) {
throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null, e);
}
}
示例15: assertTokenToNodes
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
private static void assertTokenToNodes(JCas jcas, List<BasicNode> testedTrees, Map<Sentence, OneToManyBidiMultiHashMap<Token, BasicNode>> tokenToNodesBySentence) {
Collection<Sentence> sentences = JCasUtil.select(jcas, Sentence.class);
assertOrderedFeatureStructureCollectionsEqual(sentences, tokenToNodesBySentence.keySet());
assertEquals(testedTrees.size(), tokenToNodesBySentence.size());
Iterator<BasicNode> rootIter = testedTrees.iterator();
for (Entry<Sentence, OneToManyBidiMultiHashMap<Token, BasicNode>> entry : tokenToNodesBySentence.entrySet()) {
OneToManyBidiMultiHashMap<Token, BasicNode> tokenToNodes = entry.getValue();
List<Token> tokens = JCasUtil.selectCovered(jcas, Token.class, entry.getKey());
assertUnorderedFeatureStructureCollectionsEqual(tokens, tokenToNodes.keySet());
BasicNode root = rootIter.next();
Set<BasicNode> nodes = AbstractNodeUtils.treeToSet(root);
// Remove null-word nodes, since this is the "fake" root node, and we don't need it
// for the comparison (it is not present in the tokenToNodes map)
for (Iterator<BasicNode> iterNodes = nodes.iterator(); iterNodes.hasNext();) {
if (iterNodes.next().getInfo().getNodeInfo().getWord()==null) {
iterNodes.remove();
}
}
assertEquals(nodes, new HashSet<BasicNode>(tokenToNodes.values()));
for (Entry<Token, Collection<BasicNode>> tokenNodesEntry : tokenToNodes.entrySet()) {
List<BasicNode> nodeList = (List<BasicNode>) tokenNodesEntry.getValue();
for (int i=0; i<nodeList.size(); i++) {
assertEquals(tokenNodesEntry.getKey().getLemma().getValue(), nodeList.get(i).getInfo().getNodeInfo().getWordLemma());
if (i==0) {
assertNull(nodeList.get(i).getAntecedent()); // only first element is non-deep node (no antecedent)
}
else {
assertNotNull(nodeList.get(i).getAntecedent()); // all other element are deep (have antecedent)
}
}
}
}
}