本文整理汇总了Java中org.uimafit.util.JCasUtil.select方法的典型用法代码示例。如果您正苦于以下问题:Java JCasUtil.select方法的具体用法?Java JCasUtil.select怎么用?Java JCasUtil.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.uimafit.util.JCasUtil
的用法示例。
在下文中一共展示了JCasUtil.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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));
}
示例9: 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);
}
}
示例10: 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)
}
}
}
}
}
示例11: getAlignments
import org.uimafit.util.JCasUtil; //导入方法依赖的package包/类
private Map<String,Link> getAlignments(JCas jcas) throws Exception {
Map<String,Link> result = new HashMap<String,Link>();
try {
// Call the aligner component to get the alignments between T and H
if (this.aligner != null) {
logger.finer("\ngetting the alignments ...");
aligner.annotate(jcas);
logger.finer("done.");
}
logger.finer("\n\nalignments list:\n");
//get the HYPOTHESIS view
JCas hypoView = jcas.getView(LAP_ImplBase.HYPOTHESISVIEW);
//cycle through the alignments
for (Link link : JCasUtil.select(hypoView, Link.class)) {
logger.finer(String.format("\nText phrase: %s, " +
"Hypothesis phrase: %s, " +
"id: %s, confidence: %f, direction: %s",
link.getTSideTarget().getCoveredText(),
link.getHSideTarget().getCoveredText(),
link.getID(), link.getStrength(),
link.getDirection().toString()));
String key = link.getTSideTarget().getCoveredText() +
"__" +
link.getHSideTarget().getCoveredText();
//for a couple of tokens it can save a type of alignment only in the
//order as provided by the aligner component.
if (!result.containsKey(key))
result.put(key, link);
}
} catch (Exception e) {
throw new Exception(e.getMessage());
}
return result;
}
示例12: test1
import org.uimafit.util.JCasUtil; //导入方法依赖的package包/类
@Test
public void test1() {
try {
// Annotate the first pair with tokens and lemmas
logger.info("Tokenize and lemmatize the sentence pair #1");
JCas pair1 = lap.generateSingleTHPairCAS(t1, h1);
// Call the aligner to align T and H of pair 1
logger.info("Aligning pair #1");
aligner.annotate(pair1);
logger.info("Finished aligning pair #1");
// Print the alignment of pair 1
JCas hypoView = pair1.getView(LAP_ImplBase.HYPOTHESISVIEW);
logger.info("Pair 1:");
logger.info("T: " + t1);
logger.info("H: " + h1);
boolean assassinKiller = false, deathPenaltyCapitalPunishment = false;
for (Link link : JCasUtil.select(hypoView, Link.class)) {
logger.info(String.format("Text phrase: %s, " +
"hypothesis phrase: %s, " +
"id: %s, confidence: %f, direction: %s",
link.getTSideTarget().getCoveredText(),
link.getHSideTarget().getCoveredText(),
link.getID(), link.getStrength(),
link.getDirection().toString()));
assassinKiller = assassinKiller || ((link.getTSideTarget().getBegin() == 4) &&
(link.getTSideTarget().getEnd() == 12) &&
(link.getHSideTarget().getBegin() == 4) &&
(link.getHSideTarget().getEnd() == 10));
deathPenaltyCapitalPunishment = deathPenaltyCapitalPunishment ||
((link.getTSideTarget().getBegin() == 44) &&
(link.getTSideTarget().getEnd() == 57) &&
(link.getHSideTarget().getBegin() == 52) &&
(link.getHSideTarget().getEnd() == 70));
}
// Make sure the alignments contain the alignment of
// "assassin" to "killer"
if (!assassinKiller) {
fail("There is no alignment link between 'assassin' and 'killer'." +
" This alignment link appears in: WordNet, BAP, Lin Dependency," +
" Lin Proximity and Wikipedia. " +
" Make sure that at least some of these resources were loaded correctly.");
}
// Make sure the alignments contain the alignment of
// "death penalty" to "capital punishment"
if (!deathPenaltyCapitalPunishment) {
fail("There is no alignment link between 'death penalty' and 'capital punishment'." +
" This alignment link appears in: WordNet and Wikipedia. " +
" Make sure that at least one of these resources was loaded correctly.");
}
} catch (Exception e) {
logger.info("Could not process first pair. " + e.getMessage());
}
}
示例13: test2
import org.uimafit.util.JCasUtil; //导入方法依赖的package包/类
@Test
public void test2() {
try {
// Annotate the first pair with tokens and lemmas
logger.info("Tokenize and lemmatize the sentence pair #2");
JCas pair2 = lap.generateSingleTHPairCAS(t2, h2);
// Call the aligner to align T and H of pair 2
logger.info("Aligning pair #2");
aligner.annotate(pair2);
logger.info("Finished aligning pair #2");
// Print the alignment of pair 1
JCas hypoView = pair2.getView(LAP_ImplBase.HYPOTHESISVIEW);
logger.info("Pair 2:");
logger.info("T: " + t2);
logger.info("H: " + h2);
boolean killedWounded = false, dallasTexas = false;
for (Link link : JCasUtil.select(hypoView, Link.class)) {
logger.info(String.format("Text phrase: %s, " +
"hypothesis phrase: %s, " +
"id: %s, confidence: %f, direction: %s",
link.getTSideTarget().getCoveredText(),
link.getHSideTarget().getCoveredText(),
link.getID(), link.getStrength(),
link.getDirection().toString()));
killedWounded = killedWounded || ((link.getTSideTarget().getBegin() == 12) &&
(link.getTSideTarget().getEnd() == 18) &&
(link.getHSideTarget().getBegin() == 12) &&
(link.getHSideTarget().getEnd() == 19));
dallasTexas = dallasTexas || ((link.getTSideTarget().getBegin() == 22) &&
(link.getTSideTarget().getEnd() == 28) &&
(link.getHSideTarget().getBegin() == 32) &&
(link.getHSideTarget().getEnd() == 37));
}
// Make sure the alignments contain the alignment of
// "killed" to "wounded"
if (!killedWounded) {
fail("There is no alignment link between 'killed' and 'wounded'." +
" This alignment link appears in VerbOcean." +
" Make sure that this resource was loaded correctly.");
}
// Make sure the alignments contain the alignment of
// "Dallas" to "Texas"
if (!dallasTexas) {
fail("There is no alignment link between 'Dallas' and 'Texas'." +
" This alignment link appears in: WordNet and GEO. " +
" Make sure that at least one of these resources was loaded correctly.");
}
} catch (Exception e) {
logger.info("Could not process first pair. " + e.getMessage());
}
}
示例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<NamedEntityWord> taggedTokens;
synchronized (innerTool) {
innerTool.setSentence(tokenStrings);
innerTool.recognize();
taggedTokens = innerTool.getAnnotatedSentence();
}
if (taggedTokens.size() != tokens.size()) {
throw new NamedEntityRecognizerException("Got NER 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 (NamedEntityWord taggedToken : taggedTokens) {
Token tokenAnno = tokenIter.next();
if (taggedToken.getNamedEntity() != null) {
// 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)
String tagString = taggedToken.getNamedEntity().toString();
// Get an annotation with the appropriate UIMA type via the mappingProvider
Type nerTag = mappingProvider.getTagType(tagString);
NamedEntity nerAnnotation = (NamedEntity) cas.createAnnotation(nerTag, tokenAnno.getBegin(), tokenAnno.getEnd());
nerAnnotation.setValue(tagString);
nerAnnotation.addToIndexes();
}
}
}
} catch (NamedEntityRecognizerException e) {
throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION, null, e);
}
}
示例15: checkAnnotations
import org.uimafit.util.JCasUtil; //导入方法依赖的package包/类
private void checkAnnotations(JCas doc) {
Collection<Second> seconds = JCasUtil.select(doc, Second.class);
Second s1 = null;
Second s2 = null;
assertTrue(seconds.size() == 2);
for (Second s : seconds) {
if (s.getBegin() == 6) {
assertTrue(s.getEnd() == 10);
s1 = s;
}
if (s.getBegin() == 5) {
assertTrue(s.getEnd() == 9);
s2 = s;
}
}
DocumentAnnotation docAnnot = JCasUtil.selectSingle(
doc,
DocumentAnnotation.class);
assertTrue(docAnnot != null);
Collection<First> firsts = JCasUtil.select(doc, First.class);
assertTrue(firsts.size() == 2);
for (First f : firsts) {
if (f.getBegin() == 1) {
assertTrue(f.getEnd() == 3);
assertTrue(f.getAnnot() == s1);
assertTrue(f.getBool());
assertFalse(f.getBoolArray(0));
assertTrue(f.getBoolArray(2));
assertTrue(f.getDocAnnot() == docAnnot);
assertTrue(f.getFirst() == f);
assertTrue(f.getInteger() == 123);
assertTrue(f.getIntegerList().getNthElement(0) == 5467);
assertTrue(f.getIntegerList().getNthElement(1) == 345);
assertTrue(f.getRefToSofa() == doc.getSofa());
assertTrue(f.getSecond() == s2);
assertTrue(f.getString().equals("String value"));
}
if (f.getBegin() == 0) {
assertTrue(f.getFirst() != null);
}
}
}