/** * 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; }
/** * @return the map, re-loaded from the file. * @throws IOException */ @Override public synchronized ValueSetMap<String, String> getMap() { long currentTimeInSeconds = System.currentTimeMillis() / 1000; if (currentTimeInSeconds - lastLoadTimeInSeconds > minimumSecondsBetweenLoads) { try { this.map = ValueSetMapFromStringCreator.mapFromTwoColumnsText( FileUtils.loadFileOrUrlToList(this.file), this.separator); lastLoadTimeInSeconds = currentTimeInSeconds; } catch (IOException e) { // If there was an IO exception while reading the file, then we cannot re-read the file, // so we just use the existing file. } } return this.map; }