예제 #1
0
 /**
  * Constructs an atomic model.
  *
  * @param index the index of the atomic model (-1..n), where -1 is special value (used by a single
  *     model or the master divide model) and n is number of divide models.
  * @param features the feature vector used by the atomic model.
  * @param parent the parent guide model.
  * @throws MaltChainedException
  */
 public AtomicModel(int index, FeatureVector features, Model parent) throws MaltChainedException {
   setParent(parent);
   setIndex(index);
   if (index == -1) {
     setModelName(parent.getModelName() + ".");
   } else {
     setModelName(parent.getModelName() + "." + new Formatter().format("%03d", index) + ".");
   }
   setFeatures(features);
   setFrequency(0);
   initMethod();
   if (getGuide().getGuideMode() == ClassifierGuide.GuideMode.BATCH
       && index == -1
       && getGuide().getConfiguration().getConfigurationDir().getInfoFileWriter() != null) {
     try {
       getGuide()
           .getConfiguration()
           .getConfigurationDir()
           .getInfoFileWriter()
           .write(method.toString());
       getGuide().getConfiguration().getConfigurationDir().getInfoFileWriter().flush();
     } catch (IOException e) {
       throw new GuideException("Could not write learner settings to the information file. ", e);
     }
   }
 }
예제 #2
0
 /**
  * Loads the feature divide model settings .fsm file.
  *
  * @throws MaltChainedException
  */
 protected void load() throws MaltChainedException {
   try {
     final BufferedReader in =
         new BufferedReader(
             getGuide()
                 .getConfiguration()
                 .getConfigurationDir()
                 .getInputStreamReader(getModelName() + ".dsm"));
     final Pattern tabPattern = Pattern.compile("\t");
     while (true) {
       String line = in.readLine();
       if (line == null) break;
       String[] cols = tabPattern.split(line);
       if (cols.length != 2) {
         throw new GuideException("");
       }
       int code = -1;
       int freq = 0;
       try {
         code = Integer.parseInt(cols[0]);
         freq = Integer.parseInt(cols[1]);
       } catch (NumberFormatException e) {
         throw new GuideException(
             "Could not convert a string value into an integer value when loading the feature divide model settings (.fsm). ",
             e);
       }
       if (code == -1) {
         masterModel = new AtomicModel(-1, masterFeatureVector, this);
         masterModel.setFrequency(freq);
       } else if (divideModels != null) {
         divideModels.put(code, new AtomicModel(code, divideFeatureVector, this));
         divideModels.get(code).setFrequency(freq);
       }
       setFrequency(getFrequency() + freq);
     }
     in.close();
   } catch (IOException e) {
     throw new GuideException(
         "Could not read from the guide model settings file '"
             + getModelName()
             + ".dsm"
             + "', when "
             + "loading the guide model settings. ",
         e);
   }
 }