예제 #1
0
  /**
   * Saves the feature divide model settings .fsm file.
   *
   * @throws MaltChainedException
   */
  protected void save() throws MaltChainedException {
    try {
      final BufferedWriter out =
          new BufferedWriter(
              getGuide()
                  .getConfiguration()
                  .getConfigurationDir()
                  .getOutputStreamWriter(getModelName() + ".dsm"));
      out.write(masterModel.getIndex() + "\t" + masterModel.getFrequency() + "\n");

      if (divideModels != null) {
        for (AtomicModel divideModel : divideModels.values()) {
          out.write(divideModel.getIndex() + "\t" + divideModel.getFrequency() + "\n");
        }
      }
      out.close();
    } catch (IOException e) {
      throw new GuideException(
          "Could not write to the guide model settings file '"
              + getModelName()
              + ".dsm"
              + "', when "
              + "saving the guide model settings to file. ",
          e);
    }
  }
예제 #2
0
  private AtomicModel getAtomicModel() throws MaltChainedException {
    if (getGuide().getGuideMode() == ClassifierGuide.GuideMode.BATCH) {
      throw new GuideException("Can only predict during parsing. ");
    } else if (!(divideFeature.getFeatureValue() instanceof SingleFeatureValue)) {
      throw new GuideException("The divide feature does not have a single value. ");
    }

    if (divideModels != null
        && divideModels.containsKey(
            ((SingleFeatureValue) divideFeature.getFeatureValue()).getCode())) {
      return divideModels.get(((SingleFeatureValue) divideFeature.getFeatureValue()).getCode());
    } else if (masterModel != null && masterModel.getFrequency() > 0) {
      return masterModel;
    } else {
      getGuide()
          .getConfiguration()
          .getConfigLogger()
          .info(
              "Could not predict the next parser decision because there is "
                  + "no divide or master model that covers the divide value '"
                  + ((SingleFeatureValue) divideFeature.getFeatureValue()).getCode()
                  + "', as default"
                  + " class code '1' is used. ");
    }
    return null;
  }
예제 #3
0
  public boolean predict(SingleDecision decision) throws MaltChainedException {
    if (getGuide().getGuideMode() == ClassifierGuide.GuideMode.BATCH) {
      throw new GuideException("Can only predict during parsing. ");
    } else if (!(divideFeature.getFeatureValue() instanceof SingleFeatureValue)) {
      throw new GuideException("The divide feature does not have a single value. ");
    }

    // divideFeature.update();
    if (divideModels != null
        && divideModels.containsKey(
            ((SingleFeatureValue) divideFeature.getFeatureValue()).getCode())) {
      return divideModels
          .get(((SingleFeatureValue) divideFeature.getFeatureValue()).getCode())
          .predict(decision);
    } else if (masterModel != null && masterModel.getFrequency() > 0) {
      return masterModel.predict(decision);
    } else {
      getGuide()
          .getConfiguration()
          .getConfigLogger()
          .info(
              "Could not predict the next parser decision because there is "
                  + "no divide or master model that covers the divide value '"
                  + ((SingleFeatureValue) divideFeature.getFeatureValue()).getCode()
                  + "', as default"
                  + " class code '1' is used. ");

      decision.addDecision(1); // default prediction
      // classCodeTable.getEmptyKBestList().addKBestItem(1);
    }
    return true;
  }