001    // This file is part of the Attempto Java Packages.
002    // Copyright 2008-2009, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch).
003    //
004    // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the
005    // terms of the GNU Lesser General Public License as published by the Free Software Foundation,
006    // either version 3 of the License, or (at your option) any later version.
007    //
008    // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY
009    // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
010    // PURPOSE. See the GNU Lesser General Public License for more details.
011    //
012    // You should have received a copy of the GNU Lesser General Public License along with the Attempto
013    // Java Packages. If not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.preditor.text;
016    
017    import ch.uzh.ifi.attempto.chartparser.Terminal;
018    
019    /**
020     * This class represents referenceable text elements that contain a noun. One can refer to such
021     * text elements with "the" plus the respective noun, e.g. "the customer" in the case of the noun
022     * "customer". If the text element is followed by a {@link VarTextElement} then the variable is
023     * also included in the reference text, e.g. "the customer X" if the variable has the name "X".
024     * 
025     * @author Tobias Kuhn
026     */
027    public class NounTextElement extends BasicTextElement implements RefableTextElement {
028            
029            private VarTextElement varTextElement;
030            
031            /**
032             * Creates a new noun text element.
033             * 
034             * @param noun The noun.
035             * @param category The category.
036             */
037            public NounTextElement(String noun, Terminal category) {
038                    super(noun, category);
039            }
040            
041            /**
042             * Creates a new noun text element.
043             * 
044             * @param noun The noun.
045             * @param categoryName The name of the category.
046             */
047            public NounTextElement(String noun, String categoryName) {
048                    super(noun, categoryName);
049            }
050    
051            public void checkNeighborTextElements(TextElement precedingTextElement, TextElement nextTextElement) {
052                    if (nextTextElement instanceof VarTextElement) {
053                            this.varTextElement = (VarTextElement) nextTextElement;
054                    } else {
055                            this.varTextElement = null;
056                    }
057            }
058    
059            public String getReferenceText() {
060                    if (varTextElement == null) {
061                            return "the " + getText();
062                    }
063                    return "the " + getText() + " " + varTextElement.getText();
064            }
065    
066    }