Examples of JCas


Examples of org.apache.uima.jcas.JCas

    }
  }

  @Override
  public void process(JCas jcaz) throws AnalysisEngineProcessException {
    JCas jcas;
    try {
      if (inputViewName != null) {
        jcas = jcaz.getView(inputViewName);
      } else {
        jcas = jcaz;
      }
    } catch (CASException e1) {
      throw new AnalysisEngineProcessException(e1.getCause());
    }
    // init:
    String documentText = jcas.getDocumentText();
    String splitSeq = documentText.contains("\r\n") ? "\r\n" : "\n";
    map = new int[documentText.length() + 1];
    JCas modview = null;
    try {
      // check if view already exists:
      Iterator<JCas> viewIterator = jcas.getViewIterator();
      while (viewIterator.hasNext()) {
        JCas jCas2 = (JCas) viewIterator.next();
        if (jCas2.getViewName().equals(modifiedViewName)) {
          modview = jCas2;
          getContext().getLogger().log(Level.WARNING,
                  "view with name \"" + modifiedViewName + "\" already exists.");
        }
      }
View Full Code Here

Examples of org.apache.uima.jcas.JCas

      e.printStackTrace();
    }
  }

  private void mapAnnotations(JCas fromJcas, int[] map, String toView) throws CASException {
    JCas modview = fromJcas.getView(toView);

    Set<Annotation> indexedFs = new HashSet<Annotation>();
    AnnotationIndex<Annotation> annotationIndex = fromJcas.getAnnotationIndex();
    TypeSystem typeSystem = fromJcas.getTypeSystem();
    Type docType = typeSystem.getType(UIMAConstants.TYPE_DOCUMENT);
    CasCopier casCopier = new CasCopier(fromJcas.getCas(), modview.getCas());
    for (Annotation annotation : annotationIndex) {
      // TODO be careful here, because some people inherit from DocumentAnnotation
      if (typeSystem.subsumes(docType, annotation.getType())) {
        continue;
      }
      Annotation clone = (Annotation) casCopier.copyFs(annotation);
      // change the view/sofa of the new annotation...
      // see: http://osdir.com/ml/apache.uima.general/2007-09/msg00107.html
      clone.setFeatureValue(modview.getTypeSystem()
              .getFeatureByFullName(CAS.FEATURE_FULL_NAME_SOFA), modview.getSofa());
      final int mappedBegin = map[clone.getBegin()];
      final int mappedEnd = map[clone.getEnd()];
      if (mappedBegin < mappedEnd) {
        if (mappedEnd > fromJcas.getCas().getDocumentAnnotation().getEnd()) {
          getContext().getLogger().log(Level.WARNING, "illegal annotation offset mapping");
        } else {
          int max = modview.getCas().getDocumentAnnotation().getEnd();
          if (mappedBegin < max && mappedEnd <= max && mappedBegin >= 0 && mappedEnd > 0) {
            clone.setBegin(mappedBegin);
            clone.setEnd(mappedEnd);
            // TODO handle nested annotation features
            modview.addFsToIndexes(clone);
            indexedFs.add(clone);
          } else {
            getContext().getLogger().log(Level.WARNING, "illegal annotation offset mapping");
          }
        }
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  public void annotatorIntegrationTest() {
    try {
      Map<String, Object> parameterSettings = new HashMap<String, Object>();
      parameterSettings.put("apikey", "04490000a72fe7ec5cb3497f14e77f338c86f2fe");
      String documentText = FileUtils.file2String(new File(DOCPATH));
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAE(XML_PATH, parameterSettings),
              documentText);
      List<ConceptFS> concepts = (List<ConceptFS>) TestUtils.getAllFSofType(ConceptFS.type,
              resultingCAS);
      assertTrue(concepts != null);
      assertTrue(concepts.size() == 8);
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  @SuppressWarnings("unchecked")
  @Test
  public void mockedAnnotatorTest() {
    try {
      String mockedAnnotatorName = MockedTextConceptTaggingAnnotator.class.getName();
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAEWithMockedImplementation(XML_PATH,
              mockedAnnotatorName), DOC);
      List<ConceptFS> concepts = (List<ConceptFS>) TestUtils.getAllFSofType(ConceptFS.type,
              resultingCAS);
      assertTrue(concepts != null);
      assertTrue(concepts.size() == 1);
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  @Test
  public void annotatorIntegrationTest() {
    try {
      Map<String,Object> parameterSettings = new HashMap<String, Object>();
      parameterSettings.put("apikey","04490000a72fe7ec5cb3497f14e77f338c86f2fe");
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAE(XML_PATH,parameterSettings), DOC);
      List<KeywordFS> keywords = (List<KeywordFS>) TestUtils.getAllFSofType(KeywordFS.type, resultingCAS);
      assertTrue(keywords.size()>0);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.toString());
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  @SuppressWarnings("unchecked")
  @Test
  public void mockedAnnotatorTest() {
    try {
      String mockedAnnotatorName = MockedTextKeywordExtractionAnnotator.class.getName();
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAEWithMockedImplementation(XML_PATH,mockedAnnotatorName), DOC);
      List<KeywordFS> keywords = (List<KeywordFS>) TestUtils.getAllFSofType(KeywordFS.type, resultingCAS);
      assertTrue(keywords!=null);
      assertTrue(keywords.size()==4);
    }
    catch (Exception e) {
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  @Test
  public void annotatorIntegrationTest() {
    try {
      Map<String,Object> parameterSettings = new HashMap<String, Object>();
      parameterSettings.put("apikey","04490000a72fe7ec5cb3497f14e77f338c86f2fe");
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAE(XML_PATH,parameterSettings), DOC);
      List<MicroformatFS> microformatsList = (List<MicroformatFS>) TestUtils.getAllFSofType(MicroformatFS.type, resultingCAS);
      assertTrue(microformatsList.size()>0);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.toString());
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  @SuppressWarnings("unchecked")
  @Test
  public void mockedAnnotatorTest() {
    try {
      String mockedAnnotatorName = MockedMicroformatsAnnotator.class.getName();
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAEWithMockedImplementation(XML_PATH,mockedAnnotatorName), DOC);
      List<MicroformatFS> microformatsList = (List<MicroformatFS>) TestUtils.getAllFSofType(MicroformatFS.type, resultingCAS);
      assertTrue(microformatsList.size()>0);
    }
    catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of org.apache.uima.jcas.JCas

    String doc = "Eight US soldiers die in attacks in south Afghanistan [this quad parentesis], making October the deadliest month for the US in the war there";
    String xmlPath = "desc/TextAnnotatedEntityExtractionAEDescriptor.xml";
    try {
      Map<String,Object> parameterSettings = new HashMap<String, Object>();
      parameterSettings.put("apikey","04490000a72fe7ec5cb3497f14e77f338c86f2fe");
      JCas resultingCAS = TestUtils.executeAE(TestUtils.getAE(xmlPath,parameterSettings), doc);
      AnnotationIndex<Annotation> annotations = resultingCAS.getAnnotationIndex(AlchemyAnnotation.type);
      assertTrue(annotations.size()>0);
    } catch (Exception e) {
      e.printStackTrace();
      fail(e.toString());
    }
View Full Code Here

Examples of org.apache.uima.jcas.JCas

  public void annotatorIntegrationTest() {
    try {
      if (isURLreachable()) {
        Map<String,Object> parameterSettings = new HashMap<String, Object>();
        parameterSettings.put("apikey","04490000a72fe7ec5cb3497f14e77f338c86f2fe");
        JCas resultingCAS = TestUtils.executeAE(TestUtils.getAE(XML_PATH,parameterSettings), URL);
        List<MicroformatFS> microformats = (List<MicroformatFS>) TestUtils.getAllFSofType(MicroformatFS.type, resultingCAS);
        assertTrue(microformats!=null);
        assertTrue(microformats.size()==7);
      }
    } catch (Exception e) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.