SimpleNLG-EnFr-master/src/test/java/simplenlg/test/english/AdjectivePhraseTest.java
/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/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 Wewstwater, Roman Kutlak, Margaret Mitchell, Pierre-Luc Vaudry.
 */
package simplenlg.test.english;

import junit.framework.Assert;

import org.junit.Test;

import simplenlg.features.Feature;
import simplenlg.features.LexicalFeature;
import simplenlg.framework.CoordinatedPhraseElement;
import simplenlg.framework.PhraseElement;
import simplenlg.framework.StringElement;
import simplenlg.framework.LexicalCategory;
import simplenlg.framework.WordElement;

/**
 * This class incorporates a few tests for adjectival phrases. Also tests for
 * adverbial phrase specs, which are very similar
 * @author agatt
 */
public class AdjectivePhraseTest extends SimpleNLG4TestBase {

	/**
	 * Instantiates a new adj p test.
	 * 
	 * @param name
	 *            the name
	 */
	public AdjectivePhraseTest(String name) {
		super(name);
	}

	/**
	 * Test premodification & coordination of Adjective Phrases (Not much else
	 * to simplenlg.test)
	 */
	@Test
	public void testAdj() {

		// form the adjphrase "incredibly salacious"
		this.salacious.addPreModifier(this.phraseFactory.createAdverbPhrase("incredibly")); //$NON-NLS-1$
		Assert.assertEquals("incredibly salacious", this.realiser //$NON-NLS-1$
				.realise(this.salacious).getRealisation());

		// form the adjphrase "incredibly beautiful"
		this.beautiful.addPreModifier("amazingly"); //$NON-NLS-1$
		Assert.assertEquals("amazingly beautiful", this.realiser //$NON-NLS-1$
				.realise(this.beautiful).getRealisation());

		// coordinate the two aps
		CoordinatedPhraseElement coordap = phraseFactory.createCoordinatedPhrase(
				this.salacious, this.beautiful);
		Assert.assertEquals("incredibly salacious and amazingly beautiful", //$NON-NLS-1$
				this.realiser.realise(coordap).getRealisation());

		// changing the inner conjunction with String
		coordap.setFeature(Feature.CONJUNCTION, "but"); //$NON-NLS-1$
		Assert.assertEquals("incredibly salacious but amazingly beautiful", //$NON-NLS-1$
				this.realiser.realise(coordap).getRealisation());

		// changing the inner conjunction with WordElement
		WordElement or = (WordElement) phraseFactory.createWord("or", LexicalCategory.CONJUNCTION);
		coordap.setFeature(Feature.CONJUNCTION, or); //$NON-NLS-1$
		Assert.assertEquals("incredibly salacious or amazingly beautiful", //$NON-NLS-1$
				this.realiser.realise(coordap).getRealisation());

		// coordinate this with a new AdjPhraseSpec
		CoordinatedPhraseElement coord2 = phraseFactory.createCoordinatedPhrase(coordap,
				this.stunning);
		Assert.assertEquals(
				"incredibly salacious or amazingly beautiful and stunning", //$NON-NLS-1$
				this.realiser.realise(coord2).getRealisation());

		// add a premodifier the coordinate phrase, yielding
		// "seriously and undeniably incredibly salacious or amazingly beautiful
		// and stunning"
		CoordinatedPhraseElement preMod = phraseFactory.createCoordinatedPhrase(
				new StringElement("seriously"), new StringElement("undeniably")); //$NON-NLS-1$//$NON-NLS-2$

		coord2.addPreModifier(preMod);
		Assert
				.assertEquals(
						"seriously and undeniably incredibly salacious or amazingly beautiful and stunning", //$NON-NLS-1$
						this.realiser.realise(coord2).getRealisation());

		// adding a coordinate rather than coordinating should give a different
		// result
		coordap.addCoordinate(this.stunning);
		Assert.assertEquals(
				"incredibly salacious, amazingly beautiful or stunning", //$NON-NLS-1$
				this.realiser.realise(coordap).getRealisation());

	}

	/**
	 * Simple test of adverbials
	 */
	@Test
	public void testAdv() {

		PhraseElement sent = this.phraseFactory.createClause("John", "eat"); //$NON-NLS-1$ //$NON-NLS-2$

		PhraseElement adv = this.phraseFactory.createAdverbPhrase("quickly"); //$NON-NLS-1$

		sent.addPreModifier(adv);

		Assert.assertEquals("John quickly eats", this.realiser.realise(sent) //$NON-NLS-1$
				.getRealisation());

		adv.addPreModifier("very"); //$NON-NLS-1$

		Assert.assertEquals("John very quickly eats", this.realiser.realise( //$NON-NLS-1$
				sent).getRealisation());

	}

	/**
	 * Test for multiple adjective pre-modifiers with and without comma-separation.
	 */
	@Test
	public void testMultipleModifiers() {
		PhraseElement np = this.phraseFactory.createNounPhrase("the", "boat");
		WordElement big = this.lexicon.getWord("big", LexicalCategory.ADJECTIVE);
		np.addPreModifier(big);
		WordElement beautiful = this.lexicon.getWord("beautiful", LexicalCategory.ADJECTIVE);
		np.addPreModifier(beautiful);
		Assert.assertEquals("the big, beautiful boat", this.realiser.realise(np).getRealisation());

		//now we set the realiser not to separate using commas
		big.setFeature(LexicalFeature.NO_COMMA, true);
		Assert.assertEquals("the big beautiful boat", this.realiser.realise(np).getRealisation());
	}
}
