Package gate.util

Examples of gate.util.GateRuntimeException


      newText = getDocument().getContent().toString();
    }
     

      if (!(document instanceof DocumentImpl)) {
        throw new GateRuntimeException("Can only handle DocumentImpl not " + document.getClass());
      }
      String theclass = document.getClass().toString();
      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);
      FeatureMap thefeats = Factory.newFeatureMap();
      FeatureMap docfeats = document.getFeatures();
      for(Object k : docfeats.keySet()) {
        thefeats.put(k, docfeats.get(k));
      }

      String theName = document.getName();
      // create a copy of the current document
      Document newDoc;
      try {
        newDoc = (Document) Factory.createResource(
              //theclass,
              "gate.corpora.DocumentImpl",
              theparms,
              thefeats,
              theName+copiedDocNameSuffix
              );
      } catch (ResourceInstantiationException ex) {
        throw new GateRuntimeException(ex);
      }
      if(annotatedDocumentTransformer != null) {
        if(forwardcopy) {
          annotatedDocumentTransformer.
            addForwardMappedAnnotations(document, newDoc, annotationSetNames);
        }
      } else {
        // TODO: which annotation sets to copy to the copied doc here?
        // TODO: at least copy the ones specified!
      }

      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");
        PrintStream outStream;
        try {
          outStream = new PrintStream(outFile);
        } catch (FileNotFoundException ex) {
          throw new GateRuntimeException("Cannot write to file "+outFile.getAbsoluteFile(),ex);
        }
        outStream.print(out);
        outStream.close();
      }
View Full Code Here


    if(annotationSetNames != null && annotationSetNames.size() > 0) {
      forwardcopy = true;
    }
    if(getSavePreservingFormat()) {
      if(annotationSetNames.size() != 1) {
        throw new GateRuntimeException("Need exactly one set for annotation sets if save preserving format is true");
      }
      String annsetname = annotationSetNames.get(0);
      if(annsetname.contains(".")) {
        throw new GateRuntimeException("Annotation set must not contain a type (have a dot) if save preserving format is true");
      }
    }
    if(directoryUrl != null) {
      try {
        directoryFile = new File(directoryUrl.toURI());
      } catch (URISyntaxException ex) {
        throw new GateRuntimeException(ex);
      }
    } else {
      directoryFile = null;
    }
    if(directoryUrl == null && outputCorpus == null) {
      throw new GateRuntimeException("Output corpus and directory URL may not be both missing");
    }
    try {
      annotatedDocumentTransformer = null;
      if(getSourceSpecifications() != null && getSourceSpecifications().size() > 0) {
        annotatedDocumentTransformer =
View Full Code Here

      targetSet.add(newFrom,newTo,
              theAnn.getType(),
              // TODO: use a deep copy clone of the original Feature Map instead!?!?
              theAnn.getFeatures());
    } catch (InvalidOffsetException ex) {
      throw new GateRuntimeException(ex);
    }
  }
View Full Code Here


  public void addBackMappedAnnotations(Document originalDoc, Document virtualDoc,
          List<String> annotationSetsTypes) {
    if(!generateBackwardOffsetMap) {
      throw new GateRuntimeException(
        "Cannot create a backward mapping when backward map creation is disabled");
    }
    // TODO: before selecting an annotation to map back, check in
    // forwardMappedAnnotations (if non-null) if this annotation is new
    // or one of the forward mapped ones. In the latter case, ignore.
View Full Code Here

  }

  public void addForwardMappedAnnotations(Document originalDoc, Document virtualDoc,
          List<String> annotationSetsTypes) {
    if(!generateForwardOffsetMap) {
      throw new GateRuntimeException(
        "Cannot create a forward mapping when forward map creation is disabled");
    }
    // For now: if null, do not do anything!
    if(annotationSetsTypes == null) {
    } else {
View Full Code Here

          boolean isCopy) {
      // each output range maps back to exactly the offsets of the input range
      // no difficulties like with the forward mapping here as there cannot
      // be overlaps in the output ranges
      if(currentTargetOffset != mapFrom.size() || currentTargetOffset != mapTo.size()) {
        throw new GateRuntimeException("Problem adding backward mapping: currentTargetOffset="+currentTargetOffset+" mapFrom.size="+mapFrom.size()+" mapTo.size="+mapTo.size());
      }
      for(int i=0; i<targetLength; i++) {
        mapFrom.add(currentTargetOffset+i, sourceOffset);
        //!System.out.println("to mapFrom: "+(currentTargetOffset+i)+"--"+sourceOffset);
        mapTo.add(currentTargetOffset+i, sourceOffset+sourceLength);
View Full Code Here

      //   silently do it
      // - if the index pos is larger than one more than the current index,
      //   insert the missing elements and show a warning
      int size = map.size();
      if(pos < 0) {
        throw new GateRuntimeException("Trying to set map element at index "+pos);
      }
      if(pos == size) {
        map.add(pos,what);
      } else if(pos < size) {
        System.err.println("Trying to set map element that exists: "+pos+" size is "+size);
View Full Code Here

    JapeDocParser parser = new JapeDocParser();
    try {
      listOfJapeDocs = parser.parse(filepath);
    } catch(Exception ex) {
      throw new GateRuntimeException("Problem parsing JAPE File "+filepath,ex);
    }

    // convert the docstrings according to the required format conversion!
    Converter converter = ConverterFactory.getConverter(fromFormat, toFormat);
    for(Map<String,String> entry : listOfJapeDocs) {
View Full Code Here

      //to = parser.parse(scanner).toString();
      to = jcreole.parseCreole(sb);
    } catch (Exception ex) {
      //System.out.println("This is the creole we got: >>>>\n"+sb+"\n<<<<");
      //System.out.println("This is the original string we got: >>>>\n"+from+"\n<<<<");
      throw new GateRuntimeException("Could not convert creole wiki format to html: "+from,ex);
    }
    return to;
  }
View Full Code Here

    japeFile = new File(pathname);
    FileInputStream fis;
    try {
      fis = new FileInputStream(japeFile);
    } catch (FileNotFoundException ex) {
      throw new GateRuntimeException("JapeDoc: JAPE file does not exist: "+pathname);
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String strLine;
    boolean readMore = true;
    Collection<Map<String,String>> result =
      new ArrayList<Map<String,String>>();
    boolean insideJapeDoc = false// indicates that we are inside a JapeDoc comment
    StringBuffer currentJapeDoc = null; // the current JapeDoc
    Map<String,String> currentEntry = null;
    boolean needType = false// indicates that after a jape doc, we still need the type
    int matchtype = 0// 0=no, 1=/** 2=//[
    int line = 0;
    while(readMore) {
      try {
        strLine = br.readLine();
      } catch (IOException ex) {
        System.err.println("Error reading JAPE file: "+pathname+" Reason: "+ex);
        strLine = null;
      }
      if(strLine == null) {
        readMore = false;
      } else {
        line++;
        if(japeDocEmptyLinePattern.matcher(strLine).matches()) {
          continue;
        }
        if(insideJapeDoc) {
          // process the jape doc and wait for closing comment line
          Matcher end;
          Matcher inside;
          if(matchtype == 1) {
            end = japeDocEndPattern1.matcher(strLine);
            inside = japeDocInsidePattern1.matcher(strLine);
          } else if(matchtype == 2) {
            end = japeDocEndPattern2.matcher(strLine);
            inside = japeDocInsidePattern2.matcher(strLine);
          } else {
            throw new GateRuntimeException("JapeDoc parsing error in file "+pathname+" line "+line);
          }
          if(end.matches()) {
            matchtype = 0;
            currentEntry.put("docstring", currentJapeDoc.toString());
            insideJapeDoc = false;
          } else if(inside.matches()) {
            String docLine = inside.group(1);
            currentJapeDoc.append(docLine);
          } else {
            throw new GateRuntimeException("JapeDoc format error in JAPE file "+pathname+": unclosed JavaDoc at line "+line);
          }
        } else {
          // wait for opening comment line
          Matcher start1 = japeDocStartPattern1.matcher(strLine);
          Matcher start2 = japeDocStartPattern2.matcher(strLine);
          String declaredType = null;
          if(start1.matches()) {
            matchtype = 1;
            needType = true;
            if(start1.group(1) != null) {
              declaredType = start1.group(1);
              needType = false;
            }
          } else if(start2.matches()) {
            matchtype = 2;
            needType = true;
            if(start2.group(1) != null) {
              declaredType = start2.group(1);
              needType = false;
            }
          }
          // if we got a match, create a new doc entry
          if(matchtype > 0) { // we got an opening comment line
            currentJapeDoc = new StringBuffer();
            currentEntry = new HashMap<String,String>();
            currentEntry.put("name", "");
            if(declaredType != null) {
              currentEntry.put("name", japeFile.getName());
              currentEntry.put("type", declaredType);
            } else {
              currentEntry.put("type", "");
            }
            currentEntry.put("format", "");
            currentEntry.put("docstring", "");
            result.add(currentEntry);
            insideJapeDoc = true;
            // if we have a FILE, set the type and set needType to false
          } else { // no start, but if we still need a type, try to find it
            if(needType) {
              Matcher type = japeDocTypePattern.matcher(strLine);
              if(type.matches()) {
                needType = false;
                currentEntry.put("type",type.group(1));
                currentEntry.put("name",type.group(2));
              } else {
                System.err.println("Could not find a type/name at line "+line);
                needType = false;
              }
            }
          }
        }
      }
    }
    try {
      br.close();
    } catch (IOException ex) {
      throw new GateRuntimeException("Error closing JAPE file: "+pathname,ex);
    }

    return result;
  }
View Full Code Here

TOP

Related Classes of gate.util.GateRuntimeException

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.