001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    // 
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    // 
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    // 
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.acewiki.aceowl;
016    
017    import java.util.ArrayList;
018    import java.util.Collection;
019    import java.util.List;
020    
021    import ch.uzh.ifi.attempto.acewiki.core.OntologyTextElement;
022    import ch.uzh.ifi.attempto.acewiki.owl.OWLConcept;
023    import ch.uzh.ifi.attempto.ape.ACEUtils;
024    import ch.uzh.ifi.attempto.ape.Gender;
025    import ch.uzh.ifi.attempto.ape.LexiconEntry;
026    import ch.uzh.ifi.attempto.base.TextContainer;
027    import ch.uzh.ifi.attempto.base.TextElement;
028    import ch.uzh.ifi.attempto.chartparser.LexicalRule;
029    import ch.uzh.ifi.attempto.chartparser.Preterminal;
030    
031    /**
032     * This class stands for concepts that are represented by ACE nouns and OWL concepts.
033     * Noun concepts have two word forms.
034     *<p>
035     * 0: singular form.
036     * 1: plural form.
037     *<p>
038     * Examples: ["country", "countries"]; ["woman", "women"].
039     * 
040     * @author Tobias Kuhn
041     */
042    public class NounConcept extends OWLConcept implements ACEOWLOntoElement {
043            
044            private String singular, plural;
045            
046            /**
047             * Creates a new noun concept.
048             */
049            public NounConcept() {
050                    singular = "";
051                    plural = "";
052            }
053            
054            public String[] getWords() {
055                    return new String[] {singular, plural};
056            }
057    
058            public void setWords(String serializedWords) {
059                    String[] words = serializedWords.split(";");
060                    singular = words[0];
061                    plural = words[1];
062            }
063            
064            public String serializeWords() {
065                    return singular + ";" + plural + ";";
066            }
067            
068            public String getIRISuffix() {
069                    return getWord(0);
070            }
071            
072            public List<LexiconEntry> getLexiconEntries() {
073                    List<LexiconEntry> entries = new ArrayList<LexiconEntry>();
074                    entries.add(LexiconEntry.createNounSgEntry(getWord(0), getWord(0), Gender.UNDEF));
075                    entries.add(LexiconEntry.createNounPlEntry(getWord(1), getWord(0), Gender.UNDEF));
076                    return entries;
077            }
078            
079            public String getType() {
080                    return "Noun";
081            }
082            
083            public String getInternalType() {
084                    return "noun";
085            }
086            
087            public void collectLexicalRules(String catName, Collection<LexicalRule> lexRules) {
088                    if (catName == null || catName.equals("noun")) {
089                            lexRules.add(new LexicalRule("noun", getWord(0)));
090                    }
091                    if (catName == null || catName.equals("nounpl")) {
092                            lexRules.add(new LexicalRule("nounpl", getWord(1)));
093                    }
094                    if (catName == null || catName.equals("defnoun")) {
095                            Preterminal cat = new Preterminal("defnoun");
096                            cat.setFeature("noun", getWord(0));
097                            lexRules.add(new LexicalRule(cat, "the " + getWord(0)));
098                    }
099            }
100            
101            public TextContainer getAnswerText() {
102                    boolean an = ACEUtils.useIndefiniteArticleAn(getWord());
103                    TextElement det = new TextElement(an ? "an" : "a");
104                    TextElement n = new OntologyTextElement(this, 0);
105                    return new TextContainer(det, n);
106            }
107            
108    }