Package gate

Examples of gate.Annotation


  @Override
  public boolean doMatch(Object annotValue, AnnotationSet context)
    throws JapeException {

    Annotation annot = (Annotation) annotValue;
    AnnotationSet containedSet = doMatch(annot, context);

    Collection<Annotation> filteredSet = filterMatches(containedSet);

    return filteredSet.isEmpty();
View Full Code Here


        //logger.debug("Size of tmpSet: "+tmpSet.size());
        //System.out.println("After checking for anns, tmpSet has "+tmpSet.size());
        if(!tmpSet.isEmpty()) {
          // get the longest annotation in the set, but only if it fits
          // and ends before toOffset
          Annotation ann = null;
          int maxlength = -1;
          Iterator<Annotation> it = tmpSet.iterator();
          while(it.hasNext()) {
            Annotation tmpAnn = it.next();
            if(Utils.length(tmpAnn) > maxlength &&
               tmpAnn.getEndNode().getOffset().intValue() <= toOffset) {
              maxlength = Utils.length(tmpAnn);
              ann = tmpAnn;
            }
          }
          // ann should now contain the longest annotation, or is still null
View Full Code Here

      newDoc.getAnnotations(virtualSpecificationSet).get(virtualSpecificationType));
    // System.err.println("Processing virtual annotations: "+virtanns.size());
    for(Annotation virtann : virtanns) {
      String value = (String)virtann.getFeatures().get(virtualSpecificationFeature);
      Integer id = (Integer)virtann.getFeatures().get("orig_id");
      Annotation origann = anns.get(id);
      if(origann != null) {
        origann.getFeatures().put(outputFeature, value);
      } else {
        // This should never happen!
        System.err.println("Could not find original annotation with id:"+id);
      }
    }
View Full Code Here

            annotatedDocumentTransformer.getIterator(getDocument(),inputAnnotationSetName);

    AnnotationSet os = getDocument().getAnnotations(outputAnnotationSetName);
    while(it.hasNext()) {
      it.next();
      Annotation ann = it.getAnnotation();
      // if the annotation is null, skip to next match. This can happen for
      // a @STRING specification which does not make sense here
      if(ann == null) {
        continue;
      }
      logger.debug("Got annotation: "+ann);
      int specNo = it.getSpecNo();
      String spec = sourceSpecificationsVector.get(it.getSpecNo());
      FeatureMap fm = Factory.newFeatureMap();
      fm.putAll(ann.getFeatures());
      fm.put("annID",ann.getId());
      fm.put("annSet", inputAnnotationSetName);
      String content = it.getContent();
      fm.put("content", content);
      fm.put("specNo",specNo+"");
      fm.put("spec", spec);
      os.add(ann.getStartNode(),ann.getEndNode(),outputAnnotationTypeName,fm);
    }
    fireStatusChanged("AnnotatedBySpecPR completed");

  }
View Full Code Here

    int outOffset = 0;
    int inOffset = 0;
    int sourceLen = 0;
    while(it.hasNext()) {
      String toAppend = it.next();
      Annotation ann = it.getAnnotation();
      if(ann == null) { // if @STRING is matched
        sourceLen = 1;
      } else {
        inOffset = ann.getStartNode().getOffset().intValue();
        sourceLen = (int)(ann.getEndNode().getOffset() - ann.getStartNode().getOffset());
        //sourceLen = Utils.length(ann);
      }
      //System.out.println("Got content >"+toAppend+"< annotation: "+ann);
      // check if we process the very first part, if yes, no separator
      // string (if any is defined) needs to be inserted, otherwise
      // insert the one that applies if we are at a new or the same
      // offset as before.
      if(first) {
        first = false;
      } else {
        if(it.getOffset().equals(lastOffset)) {
          resultString.append(separatorSame);
          addMappings(ann.getEndNode().getOffset().intValue(), outOffset, 0, separatorSame.length(), false);
          outOffset += separatorSame.length();
        } else {
          resultString.append(separator);
          // TODO: if we get the result of @STRING, ann is null!
          // In that case, the
          if(ann == null) {
            addMappings((int)(it.getOffset()+it.getContent().length()), outOffset, 0, separator.length(), false);
          } else {
            addMappings(ann.getEndNode().getOffset().intValue(), outOffset, 0, separator.length(), false);
          }
          outOffset += separator.length();
          lastOffset = it.getOffset();
        }
      }
View Full Code Here

    java.util.Collections.sort(sentList, new gate.util.OffsetComparator());

    // for each sentence get token annotations
    for (Iterator iterator = sentList.iterator(); iterator.hasNext();) {
      Annotation annotation = (Annotation) iterator.next();

      AnnotationSet sentenceTokens = annotations.get("Token", annotation
          .getStartNode().getOffset(), annotation.getEndNode()
          .getOffset());

      // create a list

      List<Annotation> tokenList = new LinkedList<Annotation>();

      for (Iterator iterator2 = sentenceTokens.iterator(); iterator2
          .hasNext();) {
        tokenList.add((Annotation) iterator2.next());

      }

      // order on offset

      Collections.sort(tokenList, new gate.util.OffsetComparator());

      // make the array be string[] sentence
      String[] sentence = new String[tokenList.size()];
      int i = 0;
      for (Iterator iterator2 = tokenList.iterator(); iterator2.hasNext();) {

        Annotation token = (Annotation) iterator2.next();

        sentence[i] = token.getFeatures().get("string").toString()
            .replaceAll("\\s+", "").trim();

        i++;
      }

      StringBuffer buf = new StringBuffer();
      for (int j = 0; j < sentence.length; j++) {
        buf.append(sentence[j] + "@@@");
      }

      // run pos tagger
      String[] postags = null;
      /**
       * we will make shure to not allow smth to breack the tagger
       */
      try {
        postags = pos.tag(sentence);
      } catch (Exception e) {
        e.printStackTrace();
        System.out
            .println("There is a problem....\n with this sentence");
        System.out.println(buf);
        continue;
      }

      // add tohose spans to token annotations

      int j = 0;
      for (Iterator iterator2 = tokenList.iterator(); iterator2.hasNext();) {
        Annotation token = (Annotation) iterator2.next();

        FeatureMap fm = token.getFeatures();
        fm.put("category", postags[j]);

        token.setFeatures(fm);

        j++;

      }
    }
View Full Code Here

          {
            String[] row = s.split("\t");
            String label = row[1];
            int tokenId = Integer.parseInt(row[0].substring(row[0].indexOf(":")+1, row[0].length()));
     
            Annotation aToken = gateDoc.getAnnotations().get("Token").get(tokenId);
            gate.FeatureMap gateMap = aToken.getFeatures();
            gateMap.put("crf_prediction", label + "_" + model);
            aToken.setFeatures(gateMap);
          }
            //post-process:
            //-crf_prediction tags per token to final crf_prediction annotation span across 1 or more tokens [Done]
            //-remove FP & adjust boundaries [rule set not added yet 20.4.13]
          gateDoc = Pipeline.postProcPipeline(gateDoc);
View Full Code Here

        {
          String[] row = s.split("\t");
          String label = row[1];
          int tokenId = Integer.parseInt(row[0].substring(row[0].indexOf(":")+1, row[0].length()));
   
          Annotation aToken = gateDoc.getAnnotations().get("Token").get(tokenId);
          gate.FeatureMap gateMap = aToken.getFeatures();
          gateMap.put("crf_prediction", label + "_" + model);
          aToken.setFeatures(gateMap);
        }
       
         // post-process:
         // -crf_prediction tags per token to final crf_prediction annotation span across 1 or more tokens [Done]
         // -remove FP & adjust boundaries [rule set not added yet 20.4.13]
View Full Code Here

      java.util.Collections.sort(sentList,
          new gate.util.OffsetComparator());

      // for each sentence get token annotations
      for (Iterator iterator = sentList.iterator(); iterator.hasNext();) {
        Annotation annotation = (Annotation) iterator.next();

        AnnotationSet sentenceTokens = annotations.get("Token",
            annotation.getStartNode().getOffset(), annotation
                .getEndNode().getOffset());

        // create a list

        List<Annotation> annList = new LinkedList<Annotation>();

        for (Iterator<Annotation> iterator2 = sentenceTokens.iterator(); iterator2
            .hasNext();) {
          annList.add(iterator2.next());

        }

        // order on offset
        Collections.sort(annList, new gate.util.OffsetComparator());

        // make the array be string[] sentence
        String[] tokens = new String[sentenceTokens.size()];
        String[] postags = new String[sentenceTokens.size()];
        int i = 0;
        for (Iterator iterator3 = annList.iterator(); iterator3
            .hasNext();) {

          Annotation token = (Annotation) iterator3.next();

          tokens[i] = token.getFeatures().get("string").toString();
          Object posObj = token.getFeatures().get("category");
          if (posObj == null) {
            throw new ExecutionException(
                "Token found with no POS tag category!\n"
                    + "Did you run a POS tagger before the OpenNLPChunker?");
          }
          postags[i] = posObj.toString();

          i++;
        }

        // run pos chunker
        String[] chunks = chunker.chunk(tokens, postags);

        // add tohose chunk tags to token annotations

        int j = 0;

        for (Iterator iterator4 = annList.iterator(); iterator4
            .hasNext();) {
          Annotation token = (Annotation) iterator4.next();

          FeatureMap fm = token.getFeatures();
          fm.put("chunk", chunks[j]);

          token.setFeatures(fm);

          j++;

        }
      }
View Full Code Here

  gate.AnnotationSet inputAS;
  gate.AnnotationSet outputAS;
  gate.creole.ontology.Ontology ontology;

  public void doJape() {
    Annotation clue = null;
    try {

      // first get the clue

      clue = ((AnnotationSet) bindings.get("clue")).iterator().next();

      // then get the clueType

      Annotation clueType = null;
      if (inputAS.get(clue.getStartNode().getOffset(),
          clue.getEndNode().getOffset()).get("clueType").iterator()
          .hasNext())
        clueType = inputAS.get(clue.getStartNode().getOffset(),
            clue.getEndNode().getOffset()).get("clueType")
            .iterator().next();
      else
        return;

      // System.out.println(doc.getContent().getContent(
      // type.getStartNode().getOffset(),
      // type.getEndNode().getOffset()));

      // now just the type
      String type = null;
      if (inputAS.get(clue.getStartNode().getOffset(),
          clue.getEndNode().getOffset()).get("type").iterator()
          .hasNext())
        type = inputAS.get(clue.getStartNode().getOffset(),
            clue.getEndNode().getOffset()).get("type").iterator()
            .next().getFeatures().get("class").toString();
      else
        return;

      BufferedWriter bw = null;

      try {
        bw = new BufferedWriter(
            new FileWriter(
                "/Users/georgigeorgiev/tmp/corpora/relex/verbs_type.txt",
                true));
        bw.write(doc.getContent().getContent(
            clueType.getStartNode().getOffset(),
            clueType.getEndNode().getOffset()).toString()
            + "\t" + type);
        bw.newLine();
        bw.flush();
      } catch (IOException ioe) {
        ioe.printStackTrace();
View Full Code Here

TOP

Related Classes of gate.Annotation

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.