/**
   * return a set of rules based on this CharGer file. All Rules are different from each other. If
   * the LHS of the file contains a lemma with multiple choices, like "lemma1/lemma2/lemma3...",
   * then one rule is created per lemma option otherwise, naturally, one rule is created
   */
  public List<RuleWithConfidenceAndDescription<Info, BasicNode>> makeRules(File file)
      throws EntailmentCompilationException {
    // first add all the rules into a set, to eliminate duplicates. Then put 'em in  a list
    Set<RuleWithConfidenceAndDescription<Info, BasicNode>> setOfRulesWithCD =
        new LinkedHashSet<RuleWithConfidenceAndDescription<Info, BasicNode>>();
    String description = RuleCompilerUtils.getDescription(file);

    String origText;
    try {
      origText = FileUtils.loadFileToString(file);
    } catch (IOException e) {
      throw new EntailmentCompilationException("error reading " + file, e);
    }
    try {
      List<String> expandedTexts =
          CgxMultipleChoiceExpander.expandMultipleChoiceParameters(origText, null);

      for (String text : expandedTexts) {
        setOfRulesWithCD.add(
            new RuleWithConfidenceAndDescription<Info, BasicNode>(
                cgxRuleCompiler.makeRule(text), Constants.RULE_CONFIDENCE, description));
      }

      EntailmentRuleBuildingUtils.addReversedRules(setOfRulesWithCD, expandedTexts.get(0));
    } catch (Exception e) {
      throw new EntailmentCompilationException("Error in file " + file, e);
    }

    List<RuleWithConfidenceAndDescription<Info, BasicNode>> rulesWithCD =
        new Vector<RuleWithConfidenceAndDescription<Info, BasicNode>>(setOfRulesWithCD);
    return rulesWithCD;
  }
  /**
   * @param args
   * @throws UnsupportedPosTagStringException
   * @throws EntailmentCompilationException
   * @throws IOException
   * @throws FileNotFoundException
   * @throws ConfigurationException
   */
  public static void main(String[] args)
      throws UnsupportedPosTagStringException, EntailmentCompilationException,
          FileNotFoundException, IOException, ConfigurationException {
    if (args.length < 1)
      throw new EntailmentCompilationException(
          "usage: EntailmentRuleCompiler configurationFile.xml");
    ConfigurationFile confFile = new ConfigurationFile(new File(args[0]));
    confFile.setExpandingEnvironmentVariables(true);
    ConfigurationParams compilationParams =
        confFile.getModuleConfiguration(RuleCompilerParameterNames.RULE_COMPILER_PARAMS_MODULE);
    // ConfigurationParams applictionParams =
    // confFile.getModuleConfiguration(KnowledgeResource.SYNTACTIC.getModuleName());
    ConfigurationParams applictionParams =
        confFile.getModuleConfiguration(RuleCompilerParameterNames.SYNTACTIC_PARAMS_MODULE);

    File dir =
        compilationParams.getDirectory(
            RuleCompilerParameterNames
                .ENTAILMENT_RULES_DIRECTORY); // new
                                              // File(props.getProperty("directoryName").trim());
    final String ruleFileSuffix =
        compilationParams.get(
            RuleCompilerParameterNames
                .RULE_FILE_SUFFIX); // props.getProperty("graphFileSuffix").trim();

    // create an english node rule compliler
    EntailmentRuleCompiler compiler = new EntailmentRuleCompiler();
    List<RuleWithConfidenceAndDescription<Info, BasicNode>> rulesWithCD;

    rulesWithCD = compiler.compileFolder(dir, ruleFileSuffix);

    // EnglishRulesViewer rv = new EnglishRulesViewer(rulesWithCD);
    // ExtendedRulesViewer rv = new ExtendedRulesViewer(rulesWithCD.subList(0,1));
    // rv.view();

    // serialize rules to file
    Set<RuleWithConfidenceAndDescription<Info, BasicNode>> rules =
        new LinkedHashSet<RuleWithConfidenceAndDescription<Info, BasicNode>>(rulesWithCD);

    String outFile =
        applictionParams.get(TransformationsConfigurationParametersNames.SYNTACTIC_RULES_FILE);
    try {
      RuleCompilerUtils.serializeToFile(rules, outFile);
    } catch (CompilationException e) {
      throw new EntailmentCompilationException("see nested", e);
    }

    System.out.println("\n\nMade " + rules.size() + " rules.");
    System.out.println("Serialized them into " + outFile);
  }