Package gate

Examples of gate.AnnotationSet


  @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


  @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

    }

    // if a contained annotation name is specified, get those anns,
    // sort by offset and then loop through them, otherwise just get
    // all annotations
    AnnotationSet inputAS = document.getAnnotations(inputAnnotationSetName);


    if(containingAnnotationTypeName != null && !containingAnnotationTypeName.equals(""))  {
      AnnotationSet containingAnnotations = inputAS.get(containingAnnotationTypeName);
      //Iterator<Annotation> it = inputAnnotations.iterator();
      //String content = document.getContent().toString();

      List<Annotation> containingList = new ArrayList<Annotation>(containingAnnotations);
      Collections.sort(containingList,new OffsetComparator());
View Full Code Here

  }

  protected boolean exportContainedAnnotations(PrintStream outStream, Long from, Long to,
          AnnotationSet inputAS) {
    AnnotationSet filteredAS = inputAS.get(containedAnnotationTypeName,from,to);
    List<Annotation> filteredList = new ArrayList<Annotation>(filteredAS);
    Collections.sort(filteredList,new OffsetComparator());
    boolean haveSomething = false;
    for(Annotation ann : filteredList) {
      String toExport;
View Full Code Here

        AnnotationParm parm = annSpecs.get(curAnnSpec);
        String typeName = parm.getTypeName();
        Set<String>  featureSet = parm.getFeatureSet();
        String featureName = parm.getFeatureName();
        String constantValue = parm.getConstantValue();
        AnnotationSet tmpSet = null;
        //logger.debug("Checking specification type/feature: "+typeName+"/"+featureName);
        //logger.debug("Annotations in CurAnnSet: "+curOff_Set.size());
        if(typeName.equals("@STRING")) {
          // if we arrive at this spec, set the content to the character
          // at the current position, leave the ann null and advance the
          // offset by one and reset the spec number to 0
          nextAnnotation = null;
          nextSpecNo = curAnnSpec;
          nextContent = theDocument.getContent().toString().substring(curOffset,curOffset+1);
          nextOffset = new Long(curOffset);
          nextSpec = annSpecs.get(nextSpecNo).toString();
          curAnnSpec = 0;
          curOffset++;
          curOff_Set = Utils.getAnnotationsAtOffset(theAnnSet,new Long(curOffset));
          //System.out.println("B: Going to next offset="+curOffset+" found "+curOff_Set.size());
          break;
        }
        // TODO: when is this needed? if curOff_Set is empty, only if one
        // of the next annSpecs is @String, otherwise we will never get
        // something
        if(curOff_Set.size() == 0) {
          //System.out.println("curOff_Set is empty, get for next annspec");
          curAnnSpec++;
          if(curAnnSpec >= annSpecs.size()) {
            curAnnSpec = 0;
            curOffset++;
            curOff_Set = Utils.getAnnotationsAtOffset(theAnnSet,new Long(curOffset));
            //System.out.println("C: Going to next offset="+curOffset+" found "+curOff_Set.size());
          }
          continue;
        }
        if(featureSet == null) {
          tmpSet = curOff_Set.get(typeName);
        } else {
          tmpSet = curOff_Set.get(typeName,featureSet);
        }
        //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);
View Full Code Here

      throw new GateRuntimeException("Can only handle DocumentImpl not " +
          document.getClass());
    }
   
    // Get the annotations in document order
    AnnotationSet anns =
      document.getAnnotations(inputSpecificationSet).get(inputSpecificationType);
    List<Annotation> annlist = gate.Utils.inDocumentOrder(anns);
    List<AnnotationSpec> annspecs = new LinkedList<AnnotationSpec>();
    StringBuilder newText = new StringBuilder();
    long curoffset = 0;
    // System.err.println("Processing original annotations: "+anns.size());
    for(Annotation ann : annlist) {
      String txt;
      if(inputSpecificationFeature == null) {
        txt = gate.Utils.stringFor(document, ann);
        newText.append(txt);
        annspecs.add(new AnnotationSpec(ann,curoffset,curoffset+txt.length(),ann.getId()));
        curoffset += txt.length();
        newText.append(actualSeparatorString);
        curoffset += actualSeparatorString.length();
      } else {
        txt = (String)ann.getFeatures().get(inputSpecificationFeature);
        if(txt != null) {
          newText.append(txt);
          annspecs.add(new AnnotationSpec(ann,curoffset,curoffset+txt.length(),ann.getId()));
          curoffset += txt.length();
          newText.append(actualSeparatorString);
          curoffset += actualSeparatorString.length();
        }
      }
    }
   
    FeatureMap theparms = Factory.newFeatureMap();
    theparms.put("collectRepositioningInfo", document.getCollectRepositioningInfo());
    theparms.put("encoding", ((DocumentImpl) document).getEncoding());
    theparms.put("markupAware", document.getMarkupAware());
    theparms.put("mimeType", ((DocumentImpl) document).getMimeType());
    theparms.put("preserveOriginalContent", document.getPreserveOriginalContent());
    theparms.put("stringContent", newText.toString());
    FeatureMap thefeats = Factory.newFeatureMap();
    FeatureMap docfeats = document.getFeatures();
    thefeats.putAll(docfeats);

    String theName = document.getName();
    // create a copy of the current document
    Document newDoc;
    try {
      newDoc = (Document) Factory.createResource(
              "gate.corpora.DocumentImpl",
              theparms,
              thefeats,
              theName+"_virtual");
    } catch (ResourceInstantiationException ex) {
      throw new GateRuntimeException(ex);
    }

    // set the initial annotations in the virtual document
    AnnotationSet newSet = newDoc.getAnnotations(virtualSpecificationSet);
    for(AnnotationSpec annspec : annspecs) {
      FeatureMap fm = Factory.newFeatureMap();
      fm.putAll(annspec.annotation.getFeatures());
      fm.put("orig_id",annspec.origId);     
      try {
        newSet.add(annspec.fromOffset, annspec.toOffset, virtualSpecificationType, fm);
      } catch(InvalidOffsetException ex) {
        throw new GateRuntimeException(
          "Invalid offset when creating annotation for virtual document: from/to/doclength: "+
          annspec.fromOffset+"/"+annspec.toOffset+"/"+newDoc.getContent().size(),ex);
      }
View Full Code Here

            + getDocument().getName());

    TextForSpecIterator it =
            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

      }

      if(directoryFile != null) {
        String out = "";
        if(getSavePreservingFormat()) {
          AnnotationSet as = newDoc.getAnnotations(annotationSetNames.get(0));
          out = newDoc.toXml(as,addFeaturesToPreservingFormat);
        } else {
          out = newDoc.toXml();
        }
        File outFile = new File(directoryFile, theName+copiedDocNameSuffix+".xml");
View Full Code Here

        String annotationSetName = tmp1[0];
        String annotationTypeName = (tmp1.length == 2) ? tmp1[1] : null;
        if(annotationSetName.equals("")) {
          annotationSetName = null;
        }
        AnnotationSet theAnns = virtualDoc.getAnnotations(annotationSetName);
        AnnotationSet targetSet = originalDoc.getAnnotations(annotationSetName);
        if(annotationTypeName != null) {
          theAnns = theAnns.get(annotationTypeName);
        }
        for (Annotation theAnn : theAnns) {
          addMappedAnnotation(targetSet,theAnn,getBackwardOffsetMap());
View Full Code Here

        String annotationSetName = tmp1[0];
        String annotationTypeName = (tmp1.length == 2) ? tmp1[1] : null;
        if(annotationSetName.equals("")) {
          annotationSetName = null;
        }
        AnnotationSet theAnns = originalDoc.getAnnotations(annotationSetName);
        AnnotationSet targetSet = virtualDoc.getAnnotations(annotationSetName);
        if(annotationTypeName != null) {
          theAnns = theAnns.get(annotationTypeName);
        }
        for (Annotation theAnn : theAnns) {
          addMappedAnnotation(targetSet,theAnn,getForwardOffsetMap());
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.