/** * Get rules of type leftSide -> rightSide, using the given lexical resource * * @param resource The lexical resource to use * @param leftSide The phrase that will be looked for as lhs of a rule * @param rightSide The phrase that will be looked for as rhs of a rule * @param partOfSpeech2 * @param partOfSpeech * @return The list of rules leftSide -> rightSide * @throws LexicalResourceException */ private List<LexicalRule<? extends RuleInfo>> getRules( LexicalResource<? extends RuleInfo> resource, String leftSide, String rightSide, PartOfSpeech leftSidePOS, PartOfSpeech rightSidePOS) throws LexicalResourceException { List<LexicalRule<? extends RuleInfo>> rules = new ArrayList<LexicalRule<? extends RuleInfo>>(); try { // WordNet workaround: // Make sure the synsets of the right and left sides of the rule // are equal to the right and left phrases. // (WN returns rules associated with any of the words in the phrase) if (resource.getClass().getName().toLowerCase().contains(WORDNET)) { for (LexicalRule<? extends RuleInfo> rule : resource.getRules(leftSide, leftSidePOS, rightSide, rightSidePOS)) { WordnetRuleInfo ruleInfo = (WordnetRuleInfo) rule.getInfo(); if ((ruleInfo.getLeftSense().getWords().contains(leftSide)) && (ruleInfo.getRightSense().getWords().contains(rightSide))) { addRuleToList(rules, rule); } } } else { // Get rules from t to h for (LexicalRule<? extends RuleInfo> rule : resource.getRules(leftSide, leftSidePOS, rightSide, rightSidePOS)) { addRuleToList(rules, rule); } } } catch (Exception e) { logger.warn( "Could not add rules from " + resource.getClass().getSimpleName() + " for " + leftSide + "->" + rightSide, e); } return rules; }