Package org.apache.uima.cas

Examples of org.apache.uima.cas.CAS


    }
  }

  @Override
  public void process(JCas jcas) throws AnalysisEngineProcessException {
    CAS cas = jcas.getCas();
    if (reloadScript || (!initialized && !cas.getViewName().equals(CAS.NAME_DEFAULT_SOFA))) {
      initializeScript(cas.getViewName());
    } else {
      resetEnvironments(cas);
    }
    boolean typeSystemChanged = lastTypeSystem != cas.getTypeSystem();
    if (!initialized || reloadScript || typeSystemChanged) {
      initializeTypes(script, cas);
      initialized = true;
      lastTypeSystem = cas.getTypeSystem();
    }
    InferenceCrowd crowd = initializeCrowd();
    RutaStream stream = initializeStream(cas, crowd);
    stream.setDynamicAnchoring(dynamicAnchoring);
    stream.setGreedyRuleElement(greedyRuleElement);
    stream.setGreedyRule(greedyRule);
    try {
      script.apply(stream, crowd);
    } catch (Throwable e) {
      throw new AnalysisEngineProcessException(AnalysisEngineProcessException.ANNOTATOR_EXCEPTION,
              new Object[] {}, e);
    }
    crowd.finished(stream);

    if (removeBasics) {
      List<AnnotationFS> toRemove = new ArrayList<AnnotationFS>();
      Type basicType = cas.getTypeSystem().getType(BASIC_TYPE);
      AnnotationIndex<AnnotationFS> basicIndex = cas.getAnnotationIndex(basicType);
      for (AnnotationFS fs : basicIndex) {
        toRemove.add(fs);
      }
      for (Type seedType : seedTypes) {
        AnnotationIndex<AnnotationFS> seedIndex = cas.getAnnotationIndex(seedType);
        for (AnnotationFS fs : seedIndex) {
          toRemove.add(fs);
        }
      }
      for (AnnotationFS annotationFS : toRemove) {
        cas.removeFsFromIndexes(annotationFS);
      }
    }
  }
View Full Code Here


public class NLSQueryAnalyzerTest {
  @Test
  public void testBoostExpansion() {
    try {
      String qstr = "people working at Google Amsterdam office";
      CAS cas = UIMAAnalyzersUtils.getInstance().analyzeInput(new StringReader(qstr), "/OpenNlpTextAnalyzer.xml");
      NLSQueryAnalyzer nlsQueryAnalyzer = new NLSQueryAnalyzer(cas);
      String expandedQuery = nlsQueryAnalyzer.expandBoosts();
      assertNotNull(expandedQuery);
      assertEquals("people working at Google^5.0 Amsterdam^5.0 office", expandedQuery);
    } catch (Exception e) {
View Full Code Here

  @Test
  public void testEntitiesExtraction() {
    try {
      String qstr = "was Albert Einstein living in Paris ?";
      CAS cas = UIMAAnalyzersUtils.getInstance().analyzeInput(new StringReader(qstr), "/OpenNlpTextAnalyzer.xml");
      NLSQueryAnalyzer nlsQueryAnalyzer = new NLSQueryAnalyzer(cas);
      Map<String, Collection<String>> entitiesMap = nlsQueryAnalyzer.extractEntities();
      assertNotNull(entitiesMap);
      assertTrue(!entitiesMap.isEmpty());
      for (String k : entitiesMap.keySet()) {
View Full Code Here

  }

  @Test
  public void testAsyncCall() {
    try {
      CAS cas = UIMAAnalyzersUtils.getInstance().analyzeAsynchronously(new StringReader("Google has some offices in " +
              "the world, but not in Rome"), "OpenNLPQueue");
      assertNotNull(cas);
      AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
      System.err.println(annotationIndex.size());
      for (AnnotationFS a : annotationIndex) {
        System.err.println(a.getCoveredText() + " ");
      }
View Full Code Here

    getCAS();
  }

  public TypeSystem getTypeSystem() {

    CAS cas = getCAS();

    if (cas != null) {
      return cas.getTypeSystem();
    }

    return null;
  }
View Full Code Here

    FsIndexDescription indexDesciptor = new FsIndexDescription_impl();
    indexDesciptor.setLabel("TOPIndex");
    indexDesciptor.setTypeName("uima.cas.TOP");
    indexDesciptor.setKind(FsIndexDescription.KIND_SORTED);

    CAS cas;
    try {
      cas = CasCreationUtils.createCas(typeSystemDesciptor, typePriorities,
              new FsIndexDescription[] { indexDesciptor });
    } catch (ResourceInitializationException e) {
      String message = (e.getMessage() != null ? e.getMessage() : "");
View Full Code Here

   */
  @Override
  public void run() {
    AnnotationSelection annotations = new AnnotationSelection(getStructuredSelection());

    CAS documentCAS = mDocument.getCAS();

    AnnotationFS mergedAnnotation = documentCAS.createAnnotation(annotations.getFirst().getType(),
            annotations.getFirst().getBegin(), annotations.getLast().getEnd());

    mDocument.removeAnnotations(annotations.toList());
    mDocument.addFeatureStructure(mergedAnnotation);
  }
View Full Code Here

   * @throws CollectionException -
   */
  public void getNext(CAS cas) throws CollectionException {
    DocumentElement document = (DocumentElement) mDocumentIterator.next();

    CAS documentCas = null;

    try {
      documentCas = document.getDocument(false).getCAS();
    } catch (CoreException e) {
      // TODO Auto-generated catch block
View Full Code Here

      }
  }

  private InputStream getDocument(String text, DocumentFormat format) {

    CAS cas = createEmtpyCAS();
    cas.setDocumentText(text);

    ByteArrayOutputStream out = new ByteArrayOutputStream(40000);
   
    if (DocumentFormat.XCAS.equals(format)) {
      try {
View Full Code Here

    }
    if (collectionReaderDescriptor != null) {
      uimaEEEngine.process();
    } else {
      // send an empty CAS
      CAS cas = uimaEEEngine.getCAS();
      uimaEEEngine.sendCAS(cas);
      uimaEEEngine.collectionProcessingComplete();
    }

    // if (logCas) {
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.CAS

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.