Package gate

Examples of gate.AnnotationSet


      throw new ExecutionException(
        "No document to process!"
      );
    }

    AnnotationSet inputAS = null;
    if(inputAnnotationSet == null ||
       inputAnnotationSet.equals("")) inputAS = theDocument.getAnnotations();
    else inputAS = theDocument.getAnnotations(inputAnnotationSet);

    outputAS = null;
    if(outputAnnotationSet == null ||
       outputAnnotationSet.equals("")) outputAS = theDocument.getAnnotations();
    else outputAS = theDocument.getAnnotations(outputAnnotationSet);


    AnnotationSet processAnns = null;
    if(wordAnnotationType == null || wordAnnotationType.isEmpty()) {
      throw new GateRuntimeException("Word annotation type must not be empty!");
    }
   
    if(spaceAnnotationType == null || spaceAnnotationType.isEmpty()) {
      throw new GateRuntimeException("Space annotation type must not be empty!");
    }
    Set<String> typeSet = new HashSet<String>();
    typeSet.add(wordAnnotationType);
    typeSet.add(spaceAnnotationType);
    processAnns = inputAS.get(typeSet);
   
    AnnotationSet containingAnns = null;
    if(containingAnnotationType == null || containingAnnotationType.isEmpty()) {
      // leave the containingAnns null to indicate we do not use containing annotations
    } else {
      containingAnns = inputAS.get(containingAnnotationType);
      //System.out.println("DEBUG: got containing annots: "+containingAnns.size()+" type is "+containingAnnotationType);
    }
   
    AnnotationSet splitAnns = null;
    if(splitAnnotationType == null || splitAnnotationType.isEmpty()) {
      // leave the splitAnns null to indicate we do not use containing annotations
    } else {
      splitAnns = inputAS.get(splitAnnotationType);
      //System.out.println("DEBUG: got split annots: "+splitAnns.size()+" type is "+splitAnnotationType);
      if(splitAnns.size() == 0) {
        splitAnns = null;
      }
    }
   
   
    fireStatusChanged("Performing look-up in " + theDocument.getName() + "...");

    long endOffset = theDocument.getContent().size();

    // now split the document into chunks if necessary:
    // = for each containing annotation we create a chunk,
    // = each split annotation forces the end of a chunk
    // Each chunk is represented by an instance of Chunk
    if(containingAnns == null) {
      if(splitAnns != null) { // we need to do some additional chunking
        List<Annotation> splitAnnsList = Utils.inDocumentOrder(splitAnns);
        long lastOffset = 0;
        for(Annotation splitAnn : splitAnnsList) {
          long splitOffset = splitAnn.getStartNode().getOffset();
          if(splitOffset > lastOffset) {
            doAnnotateChunk(Chunk.makeChunk(
                document,lastOffset,splitOffset,!caseSensitive,
                processAnns,wordAnnotationType,textFeature,spaceAnnotationType,
                matchAtWordStartOnly,matchAtWordEndOnly,matchStartFeature,matchEndFeature,matchTypeFeature));
          }
          lastOffset = splitOffset;
        } // for
        // anything left?
        if(lastOffset < endOffset) {
          doAnnotateChunk(Chunk.makeChunk(document,lastOffset,endOffset,!caseSensitive,
              processAnns,wordAnnotationType,textFeature,spaceAnnotationType,
              matchAtWordStartOnly,matchAtWordEndOnly,matchStartFeature,matchEndFeature,matchTypeFeature));
        }
      } else {
        // create a chunk from the whole document
        doAnnotateChunk(Chunk.makeChunk(document,0,endOffset,!caseSensitive,
            processAnns,wordAnnotationType,textFeature,spaceAnnotationType,
            matchAtWordStartOnly,matchAtWordEndOnly,matchStartFeature,matchEndFeature,matchTypeFeature));
      }
    } else {
      for(Annotation containingAnn : containingAnns) {
        //System.out.println("processing containing annot "+containingAnn);
        // if we do have split annotations and we have split annotations within the range
        // of this containing annotation, we need to do further chunking
        if(splitAnns != null) {
          AnnotationSet containedSplits = Utils.getContainedAnnotations(splitAnns, containingAnn);
          if(containedSplits.size() > 0) {
            // we need to split
           
           
            List<Annotation> splitAnnsList = Utils.inDocumentOrder(containedSplits);
            long lastOffset = containingAnn.getStartNode().getOffset();
View Full Code Here


      throw new ExecutionException(
        "No document to process!"
      );
    }

    AnnotationSet inputAS = null;
    if(inputAnnotationSet == null ||
       inputAnnotationSet.equals("")) inputAS = theDocument.getAnnotations();
    else inputAS = theDocument.getAnnotations(inputAnnotationSet);

    AnnotationSet processAnns = null;
    if(wordAnnotationType == null || wordAnnotationType.isEmpty()) {
      throw new GateRuntimeException("Word annotation type must not be empty!");
    }
    processAnns = inputAS.get(wordAnnotationType);
   
    AnnotationSet containingAnns = null;
    if(containingAnnotationType == null || containingAnnotationType.isEmpty()) {
      // leave the containingAnns null to indicate we do not use containing annotations
    } else {
      containingAnns = inputAS.get(containingAnnotationType);
      //System.out.println("DEBUG: got containing annots: "+containingAnns.size()+" type is "+containingAnnotationType);
    }
   
    AnnotationSet outputAS = document.getAnnotations(outputAnnotationSet);
   
    fireStatusChanged("Performing look-up in " + theDocument.getName() + "...");

    if(containingAnns == null) {
      // go through all word annotations
      for(Annotation ann : processAnns) {
        Iterator<Lookup> ret = doMatch(featureAsString(ann,textFeature),matchAtStartOnly,matchAtEndOnly);
        if(ret != null) {
          processMatch(ann,ret, inputAS, outputAS);
        } else {
          processNonMatch(ann,ret,inputAS,outputAS);
        }
      }
    } else {
      for(Annotation containingAnn : containingAnns) {
        AnnotationSet containedAnns = Utils.getContainedAnnotations(processAnns, containingAnn);
        for(Annotation ann : containedAnns) {
          Iterator<Lookup> ret = doMatch(featureAsString(ann,textFeature),matchAtStartOnly,matchAtEndOnly);
          if(ret != null) {
            processMatch(ann,ret, inputAS, outputAS);
          } else {
View Full Code Here

    chunk.from = (int)fromOffset;
    chunk.to = (int)toOffset;
    chunk.text = new char[chunk.initialLength];
    chunk.endOffsets = new int[chunk.initialLength];
    chunk.startOffsets = new int[chunk.initialLength];
    AnnotationSet actualAnns = processAnns.get(fromOffset,toOffset);
    AnnotationSet wordAnns = actualAnns.get(wordAnnotationType);
    if(wordAnns.isEmpty()) {
      chunk.length = 0;
      return chunk;
    }
    List<Annotation> actualAnnsList = Utils.inDocumentOrder(actualAnns);
    int i = 0; // index into the text, startOffsets and endOffsets arrays
View Full Code Here

    parms = Factory.newFeatureMap();
    File docFile = new File(testingDir,"extgaz2docprep.xml");
    parms.put("sourceUrl",docFile.toURI().toURL());
    Document doc = (Document)
         Factory.createResource("gate.corpora.DocumentImpl", parms);
    AnnotationSet lookups = doc.getAnnotations().get("OutType");
    assertEquals(0,lookups.size());
    // run the gazetteer on the document
    eg.setDocument(doc);
    eg.execute();
    // check if we got the correct annotations
    AnnotationSet tokens = doc.getAnnotations().get("Token");
    assertEquals(46,tokens.size());
    AnnotationSet sentences = doc.getAnnotations().get("Sentence");
    assertEquals(4,sentences.size());
    lookups = doc.getAnnotations().get("OutType");
    if(backendNr == 3) {
      assertEquals(12,lookups.size());
    } else {
      assertEquals(14,lookups.size());
View Full Code Here

    parms = Factory.newFeatureMap();
    File docFile = new File(testingDir,"news1pre.xml");
    parms.put("sourceUrl",docFile.toURI().toURL());
    Document doc = (Document)
         Factory.createResource("gate.corpora.DocumentImpl", parms);
    AnnotationSet lookups = doc.getAnnotations("EXT").get("Lookup");
    assertEquals(0,lookups.size());
    // run the gazetteer on the document
    eg.setDocument(doc);
    eg.execute();
    AnnotationDiffer differ = new AnnotationDiffer();
    differ.setSignificantFeaturesSet(new HashSet<String>());
    AnnotationSet keys = doc.getAnnotations().get("Lookup");
    System.out.println("Lookups old: "+keys.size());
    AnnotationSet responses = doc.getAnnotations("EXT").get("Lookup");
    System.out.println("Lookups new: "+responses.size());
    differ.calculateDiff(keys, responses);
    int correct = differ.getCorrectMatches();
    int falsePositives = differ.getFalsePositivesStrict();
    int missing = differ.getMissing();
    System.out.println("Diff: correct="+correct+" false positives="+falsePositives+" missing="+missing);
View Full Code Here

    inputAnnotSet = document.getAnnotations(getInputAS());
    document.getAnnotations(getOutputAS());
    if (inputAnnotSet == null || inputAnnotSet.isEmpty()) {
      System.err.println("Null or empty input annotations.");
    } else {
      AnnotationSet codableSpanAnnotations = inputAnnotSet.get(getInputAnnotationType());
      if (codableSpanAnnotations == null || codableSpanAnnotations.size() == 0) {
        codableSpanAnnotations = deriveCodableSpansFromDocumentLines();
      }
      if (codableSpanAnnotations == null || codableSpanAnnotations.isEmpty()) {
        throw new GateRuntimeException("NobleCoder Warning:"
            + "No codable spans found for processing!");
      }
      for (gate.Annotation codableSpanAnnotation : codableSpanAnnotations) {
        currentCodableSpanAnnotation = codableSpanAnnotation;
View Full Code Here

      features.put("definition", concept.getDefinition());
      features.put("preferredTerm", concept.getPreferredTerm().getText());
      features.put("synonyms", StringUtils.join(concept.getSynonyms(), ";"));
      features.put("tuis", joinTuis(concept.getSemanticTypes()));
      features.put("stys", joinStys(concept.getSemanticTypes()));
      AnnotationSet nobleCoderSet = getDocument().getAnnotations(
          getOutputAS());
      nobleCoderSet.add(sPos, ePos, getOutputAnnotationType(), features);
    } catch (Exception x) {
      if (debugging) {
        StringBuffer sb = new StringBuffer();
        sb.append("\n\nFailed to add Concept:");
        sb.append("\n\tDocument name ==> " + getDocument().getName());
View Full Code Here

    inputAnnotSet = document.getAnnotations(getInputAS());
    document.getAnnotations(getOutputAS());
    if (inputAnnotSet == null || inputAnnotSet.isEmpty()) {
      System.err.println("Null or empty input annotations.");
    } else {
      AnnotationSet codableSpanAnnotations = inputAnnotSet.get(getInputAnnotationType());
      if (codableSpanAnnotations == null || codableSpanAnnotations.size() == 0) {
        codableSpanAnnotations = deriveCodableSpansFromDocumentLines();
      }
      if (codableSpanAnnotations == null || codableSpanAnnotations.isEmpty()) {
        throw new GateRuntimeException("NobleCoder Warning:"
            + "No codable spans found for processing!");
      }
      for (gate.Annotation codableSpanAnnotation : codableSpanAnnotations) {
        currentCodableSpanAnnotation = codableSpanAnnotation;
View Full Code Here

      features.put("definition", concept.getDefinition());
      features.put("preferredTerm", concept.getPreferredTerm().getText());
      features.put("synonyms", StringUtils.join(concept.getSynonyms(),";"));
      features.put("tuis", joinTuis(concept.getSemanticTypes()));
      features.put("stys", joinStys(concept.getSemanticTypes()));
      AnnotationSet nobleCoderSet = getDocument().getAnnotations(
          getOutputAS());
      nobleCoderSet.add(sPos, ePos, getOutputAnnotationType(), features);
    } catch (Exception x) {
      if (debugging) {
        StringBuffer sb = new StringBuffer();
        sb.append("\n\nFailed to add Concept:");
        sb.append("\n\tDocument name ==> " + getDocument().getName());
View Full Code Here

     * @param quest
     */
    public void parseQuestion(String quest, String col_data) throws Exception {

        this.question = cleanQuestion(quest);
        AnnotationSet ann = gateChunker.ParseQuestion(question);
        System.out.println("\n-----Start(LinguisticComponent.java): "
                + "cac ham GetAnnotationsType(...) -----\n");

        Lookup_ann = gateChunker.GetAnnotationsType(question, "Lookup", ann);
        //Person_ann = gateChunker.GetAnnotationsType(question, "Person", ann);
View Full Code Here

TOP

Related Classes of gate.AnnotationSet

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.