本文整理汇总了Java中org.uimafit.util.JCasUtil类的典型用法代码示例。如果您正苦于以下问题:Java JCasUtil类的具体用法?Java JCasUtil怎么用?Java JCasUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JCasUtil类属于org.uimafit.util包,在下文中一共展示了JCasUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.");
}
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:24,代码来源:DuplicateAnnotationRemovalFilter_AE.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:24,代码来源:BagOfDepsScoring.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:17,代码来源:BagOfDepsScoring.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:26,代码来源:CasTreeConverter.java
示例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)));
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:19,代码来源:CasTreeConverter.java
示例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);
}
}
开发者ID:tudarmstadt-lt,项目名称:TWSI-UIMA,代码行数:12,代码来源:SubstitutionValidator.java
示例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);
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:47,代码来源:CasPairDataConverter.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:44,代码来源:LinkUtils.java
示例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());
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:33,代码来源:DKProSimilaritySimpleEDA.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:45,代码来源:MeteorPhraseResourceAligner.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:14,代码来源:MeteorPhraseResourceAligner.java
示例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));
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:18,代码来源:LexicalAligner.java
示例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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:33,代码来源:BagOfWordsScoring.java
示例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);
}
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:41,代码来源:PosTaggerAE.java
示例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)
}
}
}
}
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:40,代码来源:CasTreeConverterTester.java
示例16: verifyToken
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
private void verifyToken(Token token, TestTokenInfo info) throws LAPVerificationException {
if (!info.text.equals(token.getCoveredText()))
throw new LAPVerificationException("Bad token text for " + info.id + ":" + info.text + ", expected \"" + info.text + "\", got \"" + token.getCoveredText() + "\"");
if (info.begin!=token.getBegin())
throw new LAPVerificationException("Bad token begin index for " + info.id + ":" + info.text + ", expected " + info.begin + ", got " + token.getBegin());
if (info.end!=token.getEnd())
throw new LAPVerificationException("Bad token end index for " + info.id + ":" + info.text + ", expected " + info.end + ", got " + token.getEnd());
if (!info.lemma.equals(token.getLemma().getValue()))
throw new LAPVerificationException("Bad token lemma for " + info.id + ":" + info.text + ", expected \"" + info.lemma + "\", got \"" + token.getLemma().getValue() + "\"");
if (!info.posType.equals(token.getPos().getType().getShortName()))
throw new LAPVerificationException("Bad token POS type for " + info.id + ":" + info.text + ", expected " + info.posType + ", got " + token.getPos().getType().getShortName());
if (!info.posValue.equals(token.getPos().getPosValue()))
throw new LAPVerificationException("Bad token POS value for " + info.id + ":" + info.text + ", expected \"" + info.posValue + "\", got \"" + token.getPos().getPosValue() + "\"");
String nerType = null;
List<NamedEntity> ners = JCasUtil.selectCovered(NamedEntity.class, token);
if (ners.size() == 1) {
nerType = ners.get(0).getType().getShortName();
}
else if (ners.size() > 1) {
throw new LAPVerificationException("Got more than one NER annotation for " + info.id + ":" + info.text + " - " + ners);
}
if (!Objects.equals(info.nerType, nerType))
throw new LAPVerificationException("Bad token NER value for " + info.id + ":" + info.text + ", expected \"" + info.nerType + "\", got \"" + nerType + "\"");
Set<TestDependencyInfo> infoDependencies = new HashSet<TestDependencyInfo>(Arrays.asList(info.dependencies));
if (!infoDependencies.equals(governors.get(token)))
throw new LAPVerificationException("Bad token dependencies for " + info.id + ":" + info.text + ", expected " + infoDependencies + ", got " + governors.get(token));
System.out.println("Verified token: " + info);
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:32,代码来源:BIU_LAP_Test.java
示例17: testBuildCmOffsetTokAggregate
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Test
public void testBuildCmOffsetTokAggregate() throws UIMAException, IOException {
CaseMatchParamValue caseMatchParamValue = CaseMatchParamValue.CASE_INSENSITIVE;
/* Init the tokenizer */
Object[] tokenizerConfigData = OffsetTokenizerFactory.buildConfigurationData(caseMatchParamValue);
AnalysisEngineDescription offsetTokenizerDescription = OffsetTokenizerFactory.buildOffsetTokenizerDescription(
tsd, tokenizerConfigData);
/* Init the concept mapper */
SearchStrategyParamValue searchStrategyParamValue = SearchStrategyParamValue.CONTIGUOUS_MATCH;
Class<? extends Annotation> spanFeatureStructureClass = Sentence.class;
Class<? extends Stemmer> stemmerClass = null;
String[] stopwords = new String[0];
boolean orderIndependentLookup = false;
boolean replaceCommaWithAnd = false;
boolean findAllMatches = false;
AnalysisEngineDescription conceptMapperDescription = ConceptMapperFactory.buildConceptMapperDescription(tsd,
dictionaryFile, caseMatchParamValue, searchStrategyParamValue, stemmerClass, stopwords,
orderIndependentLookup, findAllMatches, replaceCommaWithAnd, spanFeatureStructureClass,
offsetTokenizerDescription);
System.out.println("offset == null: " + (offsetTokenizerDescription == null));
System.out.println("cm == null: " + (conceptMapperDescription == null));
System.out.println("offset: " + offsetTokenizerDescription.toString());
System.out.println("offset op: "
+ offsetTokenizerDescription.getAnalysisEngineMetaData().getOperationalProperties()
.isMultipleDeploymentAllowed());
System.out.println("cm op: "
+ conceptMapperDescription.getAnalysisEngineMetaData().getOperationalProperties()
.isMultipleDeploymentAllowed());
/* Init the aggregate engine */
AnalysisEngineDescription cmAggregateDescription = AnalysisEngineFactory.createAggregateDescription(
offsetTokenizerDescription, conceptMapperDescription);
AnalysisEngine cmAggregateEngine = AnalysisEngineFactory.createAggregate(cmAggregateDescription);
cmAggregateEngine.process(jcas);
List<OntologyTerm> termList = CollectionsUtil.createList(JCasUtil.iterator(jcas, OntologyTerm.class));
assertEquals("Two ontology terms should have been found", 2, termList.size());
assertEquals("NEF1 complex", termList.get(0).getCoveredText());
assertEquals("GO:0000110", termList.get(0).getID());
assertEquals("nucleotide-excision repair complex", termList.get(1).getCoveredText());
assertEquals("GO:0000109", termList.get(1).getID());
}
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:50,代码来源:ConceptMapperFactoryTest.java
示例18: testBuildCmOffsetTokAggregate_3
import org.uimafit.util.JCasUtil; //导入依赖的package包/类
@Test
public void testBuildCmOffsetTokAggregate_3() throws UIMAException, IOException {
/* Init the tokenizer using the XML descriptor file */
CaseMatchParamValue caseMatchParamValue = CaseMatchParamValue.CASE_INSENSITIVE;
Object[] tokenizerConfigData = OffsetTokenizerFactory.buildConfigurationData(caseMatchParamValue);
AnalysisEngineDescription offsetTokenizerDescription = (AnalysisEngineDescription) ResourceCreationSpecifierFactory
.createResourceCreationSpecifier(tokenizerXmlFile.getAbsolutePath(), tokenizerConfigData);
offsetTokenizerDescription.getAnalysisEngineMetaData().setTypeSystem(tsd);
/*
* Init the concept mapper using the ConceptMapperFactory's method that does NOT use an XML
* file. (using one for the tokenizer is more difficult to avoid)
*/
SearchStrategyParamValue searchStrategyParamValue = SearchStrategyParamValue.CONTIGUOUS_MATCH;
Class<? extends Annotation> spanFeatureStructureClass = Sentence.class;
Class<? extends Stemmer> stemmerClass = null;
String[] stopwords = new String[0];
boolean orderIndependentLookup = false;
boolean replaceCommaWithAnd = false;
boolean findAllMatches = false;
AnalysisEngineDescription conceptMapperDescription = ConceptMapperFactory.buildConceptMapperDescription(tsd,
dictionaryFile, caseMatchParamValue, searchStrategyParamValue, stemmerClass, stopwords,
orderIndependentLookup, findAllMatches, replaceCommaWithAnd, spanFeatureStructureClass,
tokenizerXmlFile);
AnalysisEngine tokenizerEngine = UIMAFramework.produceAnalysisEngine(offsetTokenizerDescription);
AnalysisEngine conceptMapperEngine = UIMAFramework.produceAnalysisEngine(conceptMapperDescription);
tokenizerEngine.process(jcas);
conceptMapperEngine.process(jcas);
List<OntologyTerm> termList = CollectionsUtil.createList(JCasUtil.iterator(jcas, OntologyTerm.class));
assertEquals("Two ontology terms should have been found", 2, termList.size());
assertEquals("NEF1 complex", termList.get(0).getCoveredText());
assertEquals("GO:0000110", termList.get(0).getID());
assertEquals("nucleotide-excision repair complex", termList.get(1).getCoveredText());
assertEquals("GO:0000109", termList.get(1).getID());
}
开发者ID:UCDenver-ccp,项目名称:ccp-nlp,代码行数:42,代码来源:ConceptMapperFactoryTest.java
示例19: 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;
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:49,代码来源:FixedWeightTreeEditDistance.java
示例20: 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());
}
}
开发者ID:hltfbk,项目名称:Excitement-TDMLEDA,代码行数:67,代码来源:LexicalAlignerTest.java
注:本文中的org.uimafit.util.JCasUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论