本文整理汇总了Java中org.apache.uima.fit.util.JCasUtil.select方法的典型用法代码示例。如果您正苦于以下问题:Java JCasUtil.select方法的具体用法?Java JCasUtil.select怎么用?Java JCasUtil.select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.uima.fit.util.JCasUtil
的用法示例。
在下文中一共展示了JCasUtil.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath("../desc/TypeSystem.xml");
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText("Patient is a 30-year-old man named Leroy Butler from Green Bay, WI.");
AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription(MistAnalysisEngine.class,
MistAnalysisEngine.PARAM_MODEL_PATH,
"SHARP/model/model");
SimplePipeline.runPipeline(jcas, aed);
for(Annotation annot : JCasUtil.select(jcas, Annotation.class)){
System.out.println("Found annotation: " + annot.getCoveredText());
}
JCas deidView = jcas.getView(MistAnalysisEngine.DEID_VIEW_NAME);
System.out.println("Deidentified version:");
System.out.println(deidView.getDocumentText());
}
示例2: createConceptLines
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
static private Collection<String> createConceptLines( final JCas jcas,
final String patient, final String encounter, final String provider ) {
final Collection<IdentifiedAnnotation> annotations = JCasUtil.select( jcas, IdentifiedAnnotation.class );
if ( annotations.isEmpty() ) {
return Collections.emptyList();
}
final ConceptLinesBuilder conceptLinesBuilder = new ConceptLinesBuilder();
conceptLinesBuilder.patient( patient ).encounter( encounter ).provider( provider );
final Collection<String> annotationDataLines = new ArrayList<>();
for ( IdentifiedAnnotation annotation : annotations ) {
conceptLinesBuilder
.clearAttributes()
.value( annotation.getCoveredText() )
.attribute( MODIFIER_CD_BEGIN, annotation.getBegin() )
.attribute( MODIFIER_CD_END, annotation.getEnd() )
.attribute( MODIFIER_CD_POLARITY, annotation.getPolarity() < 0 ? NEGATED : AFFIRMED )
.attribute( MODIFIER_CD_SUBJECT, annotation.getSubject() )
.attribute( MODIFIER_CD_SECTION, annotation.getSegmentID() )
.attribute( MODIFIER_CD_UNCERTAINTY, annotation.getUncertainty() )
.attribute( MODIFIER_CD_BODY_LOCATION, null )
.attribute( MODIFIER_CD_SEVERITY, null )
.attribute( MODIFIER_CD_DOC_TIME_REL, getDocTimeRel( annotation ) )
.attribute( MODIFIER_CD_SENT, getSentenceCoverage(jcas, annotation ) );
// At this time the codes are all that change
final Collection<String> codes = OntologyConceptUtil.getCodes( annotation );
codes.addAll( OntologyConceptUtil.getCuis( annotation ) );
for ( String code : codes ) {
conceptLinesBuilder.code( code );
annotationDataLines.addAll( conceptLinesBuilder.buildLines() );
}
}
return annotationDataLines;
}
示例3: process
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override public void process(JCas jCas)
throws AnalysisEngineProcessException
{
try (OutputStream docOS = getOutputStream(jCas, ".txt")) {
Collection<BIOTokenArgumentAnnotation> bioTokenArgumentAnnotations = JCasUtil
.select(jCas, BIOTokenArgumentAnnotation.class);
if (bioTokenArgumentAnnotations.isEmpty()) {
throw new IllegalStateException(
"No annotations of type BIOTokenArgumentAnnotation found. Make sure you run ArgumentTokenBIOAnnotator in the pipeline.");
}
PrintWriter pw = new PrintWriter(docOS, true);
for (BIOTokenArgumentAnnotation tokenAnnotation : bioTokenArgumentAnnotations) {
pw.printf("%s\t%s%n", tokenAnnotation.getCoveredText(), tokenAnnotation.getTag());
}
IOUtils.closeQuietly(docOS);
}
catch (Exception e) {
throw new AnalysisEngineProcessException(e);
}
}
示例4: extractSentences
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static List<HITSentence> extractSentences(StandaloneArgument argument)
throws IOException
{
// extract sentences
List<HITSentence> result = new ArrayList<>();
ArrayList<Sentence> sentences = new ArrayList<>(
JCasUtil.select(argument.getJCas(), Sentence.class));
for (int i = 0; i < sentences.size(); i++) {
Sentence sentence = sentences.get(i);
HITSentence s = new HITSentence();
// position
s.position = i;
// create unique id by combining argument id and sentence position
s.sentenceId = StandaloneArgument.getSentenceID(argument, s.position);
s.text = sentence.getCoveredText();
result.add(s);
}
return result;
}
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:26,代码来源:AbstractArgumentHITCreator.java
示例5: extractSentenceIDsAndContent
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static SortedMap<String, Sentence> extractSentenceIDsAndContent(
StandaloneArgument argument)
throws IOException
{
JCas jCas = argument.getJCas();
// extract sentences
SortedMap<String, Sentence> result = new TreeMap<>();
ArrayList<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));
for (int i = 0; i < sentences.size(); i++) {
Sentence sentence = sentences.get(i);
// create unique id by combining argument id and sentence position
String sentenceId = getSentenceID(argument, i);
result.put(sentenceId, sentence);
}
// System.out.println("extractSentenceIDsAndContent result keys: " + result.keySet());
return result;
}
示例6: copyParagraphAndTokenAnnotations
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
private static void copyParagraphAndTokenAnnotations(JCas source, JCas target)
{
if (!source.getDocumentText().equals(target.getDocumentText())) {
throw new IllegalArgumentException("Source and target have different content");
}
for (Paragraph p : JCasUtil.select(source, Paragraph.class)) {
Paragraph paragraph = new Paragraph(target);
paragraph.setBegin(p.getBegin());
paragraph.setEnd(p.getEnd());
paragraph.addToIndexes();
}
for (Token t : JCasUtil.select(source, Token.class)) {
Token token = new Token(target);
token.setBegin(t.getBegin());
token.setEnd(t.getEnd());
token.addToIndexes();
}
}
示例7: keepArgument
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
boolean keepArgument(JCas jCas)
{
Collection<Token> tokens = JCasUtil.select(jCas, Token.class);
int oovWords = 0;
for (Token token : tokens) {
if (!vocabulary.contains(token.getCoveredText())) {
oovWords++;
}
}
frequency.addValue(oovWords);
// System.out.println(frequency);
return oovWords <= THRESHOLD;
}
示例8: keepArgument
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
public boolean keepArgument(JCas jCas)
{
List<Sentence> sentences = new ArrayList<>(JCasUtil.select(jCas, Sentence.class));
// remove one-sentence arguments
if (sentences.size() == 1) {
return false;
}
for (Sentence s : sentences) {
if (s.getCoveredText().length() > MAX_SENTENCE_LENGTH) {
return false;
}
}
return true;
}
示例9: buildCorefMap
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
protected void buildCorefMap(JCas jcas) {
if (this.getDocId(jcas).equals(this.corefDocId))
return;
this.corefMap = new HashMap<CoreferenceLink, CoreferenceLink>();
for (CoreferenceChain chain : JCasUtil.select(jcas, CoreferenceChain.class)) {
List<CoreferenceLink> links = this.getLinks(chain);
if (links.size() > 1) {
int i;
for (i = 0; i < links.size() && links.get(i).getReferenceType().equals("PRONOMINAL"); i++)
;
CoreferenceLink head = i < links.size() ? links.get(i) : null;
if (head != null) {
for (CoreferenceLink link : links)
corefMap.put(link, head);
}
}
}
this.corefDocId = this.getDocId(jcas);
}
示例10: testRules1
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Test
public void testRules1() throws Exception {
org.apache.uima.fit.pipeline.JCasIterator iter = SimplePipeline.iteratePipeline(
CollectionReaderFactory.createReaderDescription(XmiReader.class, XmiReader.PARAM_SOURCE_LOCATION,
"src/test/resources/SpeakerAssignmentRules/tx4z.0.xmi", XmiReader.PARAM_LENIENT, true),
AnalysisEngineFactory.createEngineDescription(FigureReferenceAnnotator.class),
AnalysisEngineFactory.createEngineDescription(SpeakerAssignmentRules.class,
SpeakerAssignmentRules.PARAM_RULE_FILE_URL,
new File("src/test/resources/SpeakerAssignmentRules/speaker-assignment-mapping.tsv").toURI()
.toURL()))
.iterator();
if (iter.hasNext()) {
JCas jcas = iter.next();
for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
if (speaker.getCoveredText().equalsIgnoreCase("carlos"))
assertNotNull(speaker.getCoveredText(), speaker.getFigure());
}
}
}
示例11: doProcess
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
protected void doProcess(final JCas jCas) throws AnalysisEngineProcessException {
for (final Pattern pattern : JCasUtil.select(jCas, Pattern.class)) {
final Base source = pattern.getSource();
final Base target = pattern.getTarget();
if (source instanceof Entity && target instanceof Entity) {
final DBObject object = new BasicDBObject()
.append("source", saveEntity((Entity) source))
.append("target", saveEntity((Entity) target))
.append("words", saveWords(pattern));
dbCollection.save(object);
}
}
}
示例12: checkSanity
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
public static void checkSanity(JCas jcas) {
assertTrue(JCasUtil.exists(jcas, Drama.class));
assertTrue(JCasUtil.exists(jcas, Figure.class));
assertTrue(JCasUtil.exists(jcas, Act.class));
assertTrue(JCasUtil.exists(jcas, Scene.class));
assertTrue(JCasUtil.exists(jcas, Speaker.class));
assertTrue(JCasUtil.exists(jcas, DramatisPersonae.class));
assertTrue(JCasUtil.exists(jcas, Author.class));
if (JCasUtil.exists(jcas, ActHeading.class)) {
for (Act act : JCasUtil.select(jcas, Act.class)) {
assertEquals(1, JCasUtil.selectCovered(ActHeading.class, act).size());
}
}
// check that speaker annotations are not empty
for (Speaker speaker : JCasUtil.select(jcas, Speaker.class)) {
assertNotEquals(speaker.getBegin(), speaker.getEnd());
}
// check that figure annotations are not empty
for (Figure figure : JCasUtil.select(jcas, Figure.class)) {
assertNotEquals(figure.getBegin(), figure.getEnd());
}
}
示例13: doProcess
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
protected void doProcess(final JCas jCas) throws AnalysisEngineProcessException {
for (final Relation relation : JCasUtil.select(jCas, Relation.class)) {
final Set<RelationConstraint> rcs = constraints.get(relation.getRelationshipType());
boolean remove;
if (rcs == null || rcs.isEmpty()) {
// In strict mode we remove
if (strict) {
remove = true;
} else {
remove = false;
}
} else {
remove = check(rcs, relation);
}
if (remove) {
relation.removeFromIndexes();
}
}
}
示例14: process
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
@Override
public void process(JCas jcas) throws AnalysisEngineProcessException {
JCas other;
try {
other = jcas.getView(viewName);
for (Origin origin : JCasUtil.select(other, Origin.class)) {
int relativ = -origin.getBegin() + origin.getOffset();
for (Annotation src : JCasUtil.selectCovered(annotationClass, origin)) {
int tgtBegin = src.getBegin() + relativ;
int tgtEnd = src.getEnd() + relativ;
for (Annotation tgt : JCasUtil.selectCovered(jcas, annotationClass, tgtBegin, tgtEnd)) {
if (tgtBegin == tgt.getBegin() && tgtEnd == tgt.getEnd()) {
Feature feature = tgt.getType().getFeatureByBaseName(featureName);
if (feature.getRange().getName().equalsIgnoreCase("uima.cas.String")) {
tgt.setStringValue(feature, src.getStringValue(feature));
}
}
}
}
}
} catch (CASException e) {
throw new AnalysisEngineProcessException(e);
}
}
示例15: getGoodTokens
import org.apache.uima.fit.util.JCasUtil; //导入方法依赖的package包/类
/**
* Retrieves all good (in particular stopwords are excluded) tokens
* from a given JCas, for each token obtain respective lemma
* (only if mLemmatize is set to true).
*
* @param jCas input jCas
* @param isStrict if true, use a stricter definition of a good term.
* @return two things in a single object instance:
* (1) an array of good tokens;
* (2) a map, where token object references are mapped to token string values.
*/
public GoodTokens getGoodTokens(final JCas jCas, boolean isStrict) {
GoodTokens res = new GoodTokens();
for (Token tok : JCasUtil.select(jCas, Token.class)) {
String text = tok.getCoveredText().toLowerCase();
if (mLemmatize) {
text = getTokenLemma(tok);
}
if (!text.isEmpty() &&
isGoodWord(text, isStrict) &&
!mStopWords.contains(text))
{
res.mMap.put(tok, text);
res.mList.add(tok);
}
}
return res;
}