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


Java JCas类代码示例

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


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

示例1: extractAspectExpressions

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
/**
 * Extracts aspect expressions from a CAS.
 * @param cas the CAS containing {@link AspectTarget} annotations
 * @param res the {@link Result}, where the expressions are added
 */
private void extractAspectExpressions(JCas cas, Result res) {
    String text = cas.getDocumentText();
    int begin = 0;
    int end = text.length()-1;

    boolean aspectActive = false;
    for (AspectTarget t: select(cas, AspectTarget.class)) {
        end = t.getEnd();
        if (aspectActive && t.getAspectTargetType().compareTo("O") == 0) {
            aspectActive = false;
            res.addAspectExpression(new AspectExpression(text.substring(begin, end), begin, end));
        } else if (!aspectActive && t.getAspectTargetType().compareTo("B") == 0) {
            aspectActive = true;
            begin = t.getBegin();
        } else if (aspectActive && t.getAspectTargetType().compareTo("B") == 0) {
            aspectActive = true;
            res.addAspectExpression(new AspectExpression(text.substring(begin, end), begin, end));
            begin = t.getBegin();
        }
    }
    if (aspectActive) {
        res.addAspectExpression(new AspectExpression(text.substring(begin, end), begin, end));
    }
}
 
开发者ID:uhh-lt,项目名称:LT-ABSA,代码行数:30,代码来源:AbSentiment.java

示例2: createSemanticAnnotation

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
static private IdentifiedAnnotation createSemanticAnnotation( final JCas jcas, final int cTakesSemantic ) {
   switch ( cTakesSemantic ) {
      case NE_TYPE_ID_DRUG: {
         return new MedicationMention( jcas );
      }
      case NE_TYPE_ID_ANATOMICAL_SITE: {
         return new AnatomicalSiteMention( jcas );
      }
      case NE_TYPE_ID_DISORDER: {
         return new DiseaseDisorderMention( jcas );
      }
      case NE_TYPE_ID_FINDING: {
         return new SignSymptomMention( jcas );
      }
      case NE_TYPE_ID_LAB: {
         return new LabMention( jcas );
      }
      case NE_TYPE_ID_PROCEDURE: {
         return new ProcedureMention( jcas );
      }
   }
   return new EntityMention( jcas );
}
 
开发者ID:tmills,项目名称:ctakes-docker,代码行数:24,代码来源:DeidAwareTermConsumer.java

示例3: process

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
  try{
    JCas deidView = CasUtil.getView(jCas.getCas(), DEID_VIEW_NAME, true).getJCas();

    String text = jCas.getDocumentText();

    String decoderOut = decoder.decodeString(text);

    while(true) {
      Matcher m = xmlPatt.matcher(decoderOut);
      if (!m.find()) {
        break;
      }
      String matchType = m.group(1);
      int matchStart = m.start();
      int matchEnd = m.end();
      decoderOut = decoderOut.substring(0, matchStart) + "[" + matchType + "]" + decoderOut.substring(matchEnd);
    }

    deidView.setDocumentText(decoderOut);
  }catch(Exception e){
    System.err.println("Error trying to run mist!");
    throw new AnalysisEngineProcessException(e);
  }
}
 
开发者ID:tmills,项目名称:ctakes-docker,代码行数:27,代码来源:MistAnalysisEngine.java

示例4: main

import org.apache.uima.jcas.JCas; //导入依赖的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

示例5: process

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

      final String patient = Long.toString( SourceMetadataUtil.getPatientNum( jcas ) );
      final SourceData sourceData = SourceMetadataUtil.getSourceData( jcas );
      final String encounter = sourceData==null?"null":sourceData.getSourceEncounterId();
      final String providerId = sourceData==null?"null":SourceMetadataUtil.getProviderId( sourceData );
      // source date not used ???
//      final String sourceDate = sourceData.getSourceOriginalDate();
      JCas deidView = null;
      try{
        deidView = jcas.getView(DEID_VIEW);
      }catch(CASException e){
        throw new AnalysisEngineProcessException(e);
      }
      final Collection<String> conceptLines = createConceptLines( deidView, patient, encounter, providerId );

      final File outputFile = new File( _outputRootDir, encounter );
      saveAnnotations( outputFile, conceptLines );

   }
 
开发者ID:tmills,项目名称:ctakes-docker,代码行数:22,代码来源:I2b2ReadyFileWriter.java

示例6: createConceptLines

import org.apache.uima.jcas.JCas; //导入依赖的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

示例7: process

import org.apache.uima.jcas.JCas; //导入依赖的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

示例8: createAnnotation

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
private static ArgumentComponent createAnnotation(String fullTag, JCas jCas)
{
    String tag = fullTag.split("-")[0];

    switch (tag.toLowerCase()) {
    case "premise":
        return new Premise(jCas);
    case "backing":
        return new Backing(jCas);
    case "claim":
        return new Claim(jCas);
    case "rebuttal":
        return new Rebuttal(jCas);
    case "refutation":
        return new Refutation(jCas);
    default:
        throw new IllegalArgumentException("Unknown annotation type " + tag);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:20,代码来源:Step08GoldClaimAnnotator.java

示例9: writeTypeSystem

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
/**
 * Writes "typesystem.xml" to the output tar.gz
 *
 * @param aJCas any jcas from the collection to get the currently active typesystem
 * @throws IOException IO Exception
 */
private void writeTypeSystem(JCas aJCas)
        throws IOException
{
    try {
        String name = "typesystem.xml";
        java.io.ByteArrayOutputStream stream = new java.io.ByteArrayOutputStream();

        TypeSystemUtil.typeSystem2TypeSystemDescription(aJCas.getTypeSystem()).toXML(stream);

        // add to tar
        addSingleEntryToTar(stream.toByteArray(), name);
    }
    catch (SAXException e) {
        throw new IOException(e);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:23,代码来源:CompressedXmiWriter.java

示例10: extractSentenceIDsAndContent

import org.apache.uima.jcas.JCas; //导入依赖的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

示例11: getJCas

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
public JCas getJCas()
        throws RuntimeException
{
    if (base64JCas == null) {
        return null;
    }

    try {
        byte[] bytes = new BASE64Decoder()
                .decodeBuffer(new ByteArrayInputStream(base64JCas.getBytes("utf-8")));
        JCas jCas = JCasFactory.createJCas();
        XmiCasDeserializer.deserialize(new ByteArrayInputStream(bytes), jCas.getCas());

        return jCas;
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:20,代码来源:StandaloneArgument.java

示例12: copyParagraphAndTokenAnnotations

import org.apache.uima.jcas.JCas; //导入依赖的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

示例13: keepArgument

import org.apache.uima.jcas.JCas; //导入依赖的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

示例14: keepArgument

import org.apache.uima.jcas.JCas; //导入依赖的package包/类
@Override
public boolean keepArgument(Argument argument, Debate parentDebate)
        throws IOException
{
    if (!(argument instanceof StandaloneArgument)) {
        throw new IllegalStateException(
                StandaloneArgument.class.getName() + " expected but was " + argument.getClass()
                        .getName());
    }

    JCas jCas = ((StandaloneArgument) argument).getJCas();

    if (jCas == null) {
        throw new IllegalStateException("Empty jCas for " + argument.getId());
    }

    return keepArgument(jCas);
}
 
开发者ID:UKPLab,项目名称:argument-reasoning-comprehension-task,代码行数:19,代码来源:AbstractLinguisticFeaturesFilter.java

示例15: keepArgument

import org.apache.uima.jcas.JCas; //导入依赖的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


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