Package gate.util

Examples of gate.util.GateRuntimeException


  public void replaceOld(int mapIndex, char key, int newState, int oldState) {
    char[] itemsKeys = storeKeys.get(mapIndex);
    int[] itemsObjs = storeStates.get(mapIndex);
    int index = Arrays.binarySearch(itemsKeys, key);
    if(index<0) {
      throw new GateRuntimeException("CharMapState: should have key but not found: "+key);
    }
    if(itemsObjs[index] != oldState) {
      throw new GateRuntimeException("CharMapState: old states differ!");
    }
    itemsObjs[index] = newState;
  }
View Full Code Here


    return text[textoff];
  }
 
  private void guardOffset(int off) {
    if(!(off < length) || off<0) {
      throw new GateRuntimeException("Attempt to use invalid chunk text offset: off="+off+" length="+length);
    }   
  }
View Full Code Here

  } // put

  public State replace(char key, State newState, State oldState) {
    int index = Arrays.binarySearch(itemsKeys, key);
    if(index<0) {
      throw new GateRuntimeException("CharMapState: should have key but not found: "+key);
    }
    if(itemsObjs[index] != oldState) {
      throw new GateRuntimeException("CharMapState: old states differ!");
    }
    itemsObjs[index] = newState;
    return newState;
  }
View Full Code Here

  @Override
  public State put(char key, State value) {
    // Now that we use replace for overwriting the state, this should never happen
    // unless our key is still 0
    if(this.key != 0) {
      throw new GateRuntimeException("SingleCharState: put of "+key+" when old key is "+this.key);
    }
    this.key = key;
    this.next = value;
    nrChars++;
    return value;
View Full Code Here

    // check the extension and determine if we have an old format .def file or
    // a new format .defyaml file
    String name = configFile.getName();
    int i = name.lastIndexOf('.')+1;
    if(i < 0) {
      throw new GateRuntimeException("Config file must have a .def or .defyaml extension");
    }
    String ext = name.substring(i);
    if(ext.isEmpty() || !(ext.equals("def") || ext.equals("defyaml"))) {
      throw new GateRuntimeException("Config file must have a .def or .defyaml extension");     
    }
    if(ext.equals("def")) {
      loadDataFromDef(configFile);
    } else {
      loadDataFromYaml(configFile);
View Full Code Here

    return value;
  }

  public State replace(char key, State newState, State oldState) {
    if(key != this.key) {
      throw new GateRuntimeException("SingleCharState: Trying to replace key "+this.key+" with key "+key);
    }
    if(next != oldState) {
      throw new GateRuntimeException("SingleCharState: old states differ for replace!");
    }
    this.key = key;
    this.next = newState;
    return newState;
  }
View Full Code Here

 
  protected void loadDataFromDef(File configFile) throws IOException
    String configFileName = configFile.getAbsolutePath();
    String gazbinFileName = configFileName.replaceAll("\\.def$", ".gazbin");
    if(configFileName.equals(gazbinFileName)) {
      throw new GateRuntimeException("Config file must have def or defyaml extension");
    }
    File gazbinFile = new File(gazbinFileName);
  
   if(backendNr == 3 && useCache && gazbinFile.exists()) {
     gazStore = new GazStoreTrie3();
     gazStore = gazStore.load(gazbinFile);
  
   } else {
    if(backendNr == 1) {
      gazStore = new GazStoreTrie1();
    } else if (backendNr == 2) {
      gazStore = new GazStoreTrie2();     
    } else if (backendNr == 3) {
      gazStore = new GazStoreTrie3();     
    } else {
      throw new GateRuntimeException("Invalid backend number: "+backendNr);
    }
    BufferedReader defReader =
      new BomStrippingInputStreamReader((configFileURL).openStream(), encoding);
    String line;
    //logger.info("Loading data");
    while (null != (line = defReader.readLine())) {
       String[] fields = line.split(":");
       if(fields.length == 0) {
         System.err.println("Empty line in file "+configFileURL);
       } else {
         String listFileName = "";
         String majorType = "";
         String minorType = "";
         String languages = "";
         String annotationType = ANNIEConstants.LOOKUP_ANNOTATION_TYPE;
         listFileName = fields[0];
         if(fields.length > 1) {
           majorType = fields[1];
         }
         if(fields.length > 2) {
           minorType = fields[2];
         }
         if(fields.length > 3) {
           languages = fields[3];
         }
         if(fields.length > 4) {
           annotationType = fields[4];
         }
         if(fields.length > 5) {
           defReader.close();
           throw new GateRuntimeException("Line has more that 5 fields in def file "+configFileURL);
         }
         logger.debug("Reading from "+listFileName+", "+majorType+"/"+minorType+"/"+languages+"/"+annotationType);
         //logger.info("DEBUG: loading data from "+listFileName);
         loadListFile(listFileName,majorType,minorType,languages,annotationType);
      }
View Full Code Here

  protected void loadDataFromYaml(File configFile) throws IOException
    String configFileName = configFile.getAbsolutePath();
    String gazbinFileName = configFileName.replaceAll("\\.defyaml$", ".gazbin");
    if(configFileName.equals(gazbinFileName)) {
      throw new GateRuntimeException("Config file must have def or defyaml extension");
    }
    File gazbinFile = new File(gazbinFileName);
  
    String gazbinDir = gazbinFile.getParent();
    String gazbinName = gazbinFile.getName();
   
    // Always read the yaml file so we can get any special location of the cache
    // file or figure out that we should not try to load the cache file
    Yaml yaml = new Yaml();
    BufferedReader yamlReader =
        new BomStrippingInputStreamReader((configFileURL).openStream(), encoding);
    Object configObject = yaml.load(yamlReader);

    List<Map> configListFiles = null;
    if(configObject instanceof Map) {
      Map<String,Object> configMap = (Map<String,Object>)configObject;
      String configCacheDirName = (String)configMap.get("cacheDir");
      if(configCacheDirName != null) {
        gazbinDir = configCacheDirName;
      }
      String configCacheFileName = (String)configMap.get("chacheFile");
      if(configCacheFileName != null) {
        gazbinName = configCacheFileName;
      }
      gazbinFile = new File(new File(gazbinDir),gazbinName);
      Integer configBackendNr = (Integer)configMap.get("backendNr");
      if(configBackendNr != null) {
        backendNr = configBackendNr;
      }
      configListFiles = (List<Map>)configMap.get("listFiles");
    } else if(configObject instanceof List) {
      configListFiles = (List<Map>)configObject;
    } else {
      throw new GateRuntimeException("Strange YAML format for the defyaml file "+configFileURL);
    }
   
    // if we want to load the cache and it exists, load it
    if(backendNr == 3 && useCache && gazbinFile.exists()) {
      gazStore = new GazStoreTrie3();
      gazStore = gazStore.load(gazbinFile);  
   } else {
     // otherwise process the files listed in the yaml file
    if(backendNr == 1) {
      gazStore = new GazStoreTrie1();
    } else if (backendNr == 2) {
      gazStore = new GazStoreTrie2();     
    } else if (backendNr == 3) {
      gazStore = new GazStoreTrie3();     
    } else {
      throw new GateRuntimeException("Invalid backend number: "+backendNr);
    }
    // go through all the list and tsv files to load and load them
    for(Map configListFile : configListFiles) {
      // TODO!!!
   
View Full Code Here

        int nextSepIndex = 0;
        do {
          //logger.info("Feature nr: "+(nrFeatures+1));
          // check if we already have maximum number of features allows
          if(nrFeatures == MAX_FEATURES_PER_ENTRY) {
            throw new GateRuntimeException(
                "More than "+MAX_FEATURES_PER_ENTRY+" features in gazetteer entry in list "+listFileName+
                " line "+lines);
          }
          // get the index of the next separator
          nextSepIndex = line.indexOf(unescapedSeparator,lastSepIndex+1);
          if(nextSepIndex < 0) { // if none found, use beyond end of String
            nextSepIndex = line.length();
          }
          // find the first equals character in the string section for this feature
          int equalsIndex = line.indexOf('=',lastSepIndex+1);
          //logger.info("lastSepIndex="+lastSepIndex+", nextSepIndex="+nextSepIndex+", equalsIndex="+equalsIndex);
          // if we do not find one or only after the end of this feature string,
          // make a fuss about it
          if(equalsIndex < 0 || equalsIndex >= nextSepIndex) {
            throw new GateRuntimeException(
                "Not a proper feature=value in gazetteer list "+listFileName+
                " line "+lines+"\nlooking at "+line.substring(lastSepIndex,nextSepIndex)+
                " lastSepIndex is "+lastSepIndex+
                " nextSepIndex is "+nextSepIndex+
                " equals at "+equalsIndex);
View Full Code Here

  } // put

  public State replace(char key, State newState, State oldState) {
    int index = Arrays.binarySearch(itemsKeys, key);
    if(index<0) {
      throw new GateRuntimeException("CharMapState: should have key but not found: "+key);
    }
    if(itemsObjs[index] != oldState) {
      throw new GateRuntimeException("CharMapState: old states differ!");
    }
    itemsObjs[index] = newState;
    return newState;
  }
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.