当前位置: 首页>>代码示例>>Java>>正文


Java JCasUtil类代码示例

本文整理汇总了Java中org.apache.uima.fit.util.JCasUtil的典型用法代码示例。如果您正苦于以下问题:Java JCasUtil类的具体用法?Java JCasUtil怎么用?Java JCasUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JCasUtil类属于org.apache.uima.fit.util包,在下文中一共展示了JCasUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: process

import org.apache.uima.fit.util.JCasUtil; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {

	for (Segment segment : JCasUtil.select(jCas, Segment.class)) {
		String instanceId = FeaturesUtil.getFeatureValue("instanceid", segment);
		// prediction as feature (if a prediction has been made for this
		// segment)
		if (instanceId.startsWith("\"") && instanceId.endsWith("\"")) {
			instanceId = instanceId.substring(1, instanceId.length()-1);
		}
		if (predictions.containsKey(instanceId)) {
			FeaturesUtil.addFeature(featureName, predictions.get(instanceId), jCas, segment);
		}
	}

}
 
开发者ID:annefried,项目名称:sitent,代码行数:17,代码来源:AddCrfppPredictions.java

示例2: 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());
    }
 
开发者ID:tmills,项目名称:ctakes-docker,代码行数:17,代码来源:TestMistAnalysisEngine.java

示例3: 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;
}
 
开发者ID:tmills,项目名称:ctakes-docker,代码行数:34,代码来源:I2b2ReadyFileWriter.java

示例4: 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);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:25,代码来源:TokenTabBIOArgumentWriter.java

示例5: 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

示例6: argAnnotationBegins

import org.apache.uima.fit.util.JCasUtil; //导入依赖的package包/类
/**
 * Returns true, if the argument component annotation begins at this token
 *
 * @param t    token
 * @param jCas jcas
 * @return boolean
 */
public static ArgumentComponent argAnnotationBegins(Token t, JCas jCas)
{
    List<ArgumentComponent> argumentAnnotations = new ArrayList<>();

    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Claim.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Backing.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Premise.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Rebuttal.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Refutation.class, t.getBegin(), t.getEnd()));

    if (!argumentAnnotations.isEmpty() && argumentAnnotations.get(0).getBegin() == t
            .getBegin()) {
        return argumentAnnotations.get(0);
    }

    return null;
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:30,代码来源:ArgumentPrinterUtils.java

示例7: argAnnotationEnds

import org.apache.uima.fit.util.JCasUtil; //导入依赖的package包/类
/**
 * Returns true, if the argument component annotation ends at this token
 *
 * @param t    token
 * @param jCas jcas
 * @return boolean
 */
public static boolean argAnnotationEnds(Token t, JCas jCas)
{
    List<ArgumentComponent> argumentAnnotations = new ArrayList<>();

    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Claim.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Backing.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Premise.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Rebuttal.class, t.getBegin(), t.getEnd()));
    argumentAnnotations
            .addAll(JCasUtil.selectCovering(jCas, Refutation.class, t.getBegin(), t.getEnd()));

    return !argumentAnnotations.isEmpty() && argumentAnnotations.get(0).getEnd() == t.getEnd();
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:25,代码来源:ArgumentPrinterUtils.java

示例8: 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;
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:23,代码来源:StandaloneArgument.java

示例9: 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();
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:21,代码来源:Step0bTextSegmenterA.java

示例10: 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;
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:19,代码来源:OOVFilter.java

示例11: 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;
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:19,代码来源:SentenceConstraintsFilter.java

示例12: 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);
	}
 
开发者ID:UKPLab,项目名称:ijcnlp2017-cmaps,代码行数:22,代码来源:PropositionExtractor.java

示例13: processSentence

import org.apache.uima.fit.util.JCasUtil; //导入依赖的package包/类
@Override
public void processSentence(JCas jcas, Sentence sent) {

	for (CC ca : JCasUtil.selectCovered(jcas, CC.class, sent)) {
		Concept c = this.parent.getComponent(ConceptExtractor.class).getConcept(ca);
		if (c != null) {
			for (Concept cn : this.lastConcepts) {
				this.pairs.add(new Pair<Concept, Concept>(cn, c));
			}
			this.lastConcepts.offer(c);
			if (this.lastConcepts.size() > windowSize)
				this.lastConcepts.poll();
		}
	}

}
 
开发者ID:UKPLab,项目名称:emnlp2017-cmapsum-corpus,代码行数:17,代码来源:TextRankScorer.java

示例14: findVerbs

import org.apache.uima.fit.util.JCasUtil; //导入依赖的package包/类
private void findVerbs(JCas jcas, Sentence sentence) {

		List<CC> concepts = JCasUtil.selectCovered(jcas, CC.class, sentence);
		if (concepts.size() >= 2) {
			for (CC c1 : concepts) {
				for (CC c2 : concepts) {
					if (c1 != c2 && c1.getEnd() < c2.getBegin()) {

						List<PToken> tokens = new ArrayList<PToken>();
						boolean hasVerb = false;
						for (Token t : JCasUtil.selectCovered(Token.class, sentence)) {
							if (t.getBegin() > c1.getEnd() && t.getEnd() < c2.getBegin()) {
								tokens.add(this.parent.getToken(t));
								if (t.getPos().getPosValue().startsWith("V"))
									hasVerb = true;
							}
						}

						if (tokens.size() > 0 && tokens.size() < 10 && hasVerb)
							this.addLink(c1, c2, tokens);
					}
				}
			}
		}
	}
 
开发者ID:UKPLab,项目名称:emnlp2017-cmapsum-corpus,代码行数:26,代码来源:RelationExtractorVerb.java

示例15: 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());
	}
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:25,代码来源:TestGenerics.java


注:本文中的org.apache.uima.fit.util.JCasUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。