simplenlg.aggregation.BackwardConjunctionReductionRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SimpleNLG Show documentation
Show all versions of SimpleNLG Show documentation
Java API for Natural Language Generation
The newest version!
/*
* The contents of this file are subject to the Mozilla Public License
* Version 2.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* https://www.mozilla.org/en-US/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is "Simplenlg".
*
* The Initial Developer of the Original Code is Ehud Reiter, Albert Gatt and Dave Westwater.
* Portions created by Ehud Reiter, Albert Gatt and Dave Westwater are Copyright (C) 2010-11 The University of Aberdeen. All Rights Reserved.
*
* Contributor(s): Ehud Reiter, Albert Gatt, Dave Westwater, Roman Kutlak, Margaret Mitchell, and Saad Mahamood.
*/
package simplenlg.aggregation;
import java.util.List;
import simplenlg.framework.NLGElement;
import simplenlg.framework.PhraseCategory;
/**
* Implementation of the backward conjunction reduction rule. Given two
* sentences s1
and s2
, this rule elides any
* constituent in the right periphery of s1
which is
* form-identical to a constituent with the same function in
* s2
, that is, the two constituents are essentially identical in
* their final, realised, form.
*
*
* The current implementation is loosely based on the algorithm in Harbusch and
* Kempen (2009), which is described here:
*
*
* http://aclweb.org/anthology-new/W/W09/W09-0624.pdf
*
*
*
* Implementation note: The current implementation only applies
* ellipsis to phrasal constituents (i.e. not to their component lexical items).
*
*
* *
*
* Note:: this rule can be used in conjunction with the
* {@link ForwardConjunctionReductionRule} in {@link Aggregator}.
*
*
* @author Albert Gatt, University of Malta and University of Aberdeen
*/
public class BackwardConjunctionReductionRule extends AggregationRule {
//private SyntaxProcessor _syntaxProcessor;
/**
* Creates a new BackwardConjunctionReduction
.
*/
public BackwardConjunctionReductionRule() {
super();
//this._syntaxProcessor = new SyntaxProcessor();
}
/**
* Applies backward conjunction reduction to two NLGElements e1 and e2,
* succeeding only if they are clauses (that is, e1.getCategory() ==
* e2.getCategory == {@link simplenlg.framework.PhraseCategory#CLAUSE}).
*
* @param previous the first phrase
* @param next the second phrase
* @return a coordinate phrase if aggregation is successful,
* null
otherwise
*/
@Override
public NLGElement apply(NLGElement previous, NLGElement next) {
boolean success = false;
if(previous.getCategory() == PhraseCategory.CLAUSE && next.getCategory() == PhraseCategory.CLAUSE
&& PhraseChecker.nonePassive(previous, next)) {
List rightPeriphery = PhraseChecker.rightPeriphery(previous, next);
for(PhraseSet pair : rightPeriphery) {
if(pair.lemmaIdentical()) {
pair.elideLeftmost();
success = true;
}
}
}
return success ? this.factory.createCoordinatedPhrase(previous, next) : null;
}
}