    001    // This file is part of the Attempto Java Packages.
    002    // Copyright 2008, 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.acewiki.core.ontology;
    016
    017    import java.util.ArrayList;
    018    import java.util.List;
    019
    020    import ch.uzh.ifi.attempto.ape.Gender;
    021    import ch.uzh.ifi.attempto.ape.LexiconEntry;
    022
    023    /**
    024     * This class stands for roles that are represented by of-constructs. Of-constructs
    025     * consist of a noun plus the word "of". They have only one word form.
    026     *<p>
    027     * 0: word form consisting of a noun plus the word "of".
    028     *<p>
    029     * Examples: "father of"; "part of".
    030     *
    031     * @author Tobias Kuhn
    032     */
    033    public class OfRole extends Role {
    034
    035            private String word;
    036
    037            /**
    038             * Creates a new role that is represented by an of-construct.
    039             */
    040            public OfRole() {
    041            }
    042
    043            public String[] getWords() {
    044                    return new String[] {word};
    045            }
    046
    047            protected void changeWords(String... words) {
    048                    if (words[0] == null || words[0].equals("")) {
    049                            word = null;
    050                    } else if (words[0].endsWith(" of")) {
    051                            word = words[0];
    052                    } else {
    053                            word = words[0] + " of";
    054                    }
    055            }
    056
    057            /**
    058             * Returns the noun of the of-construct.
    059             *
    060             * @return The noun.
    061             */
    062            public String getNoun() {
    063                    if (word == null) {
    064                            return null;
    065                    } else if (word.endsWith(" of")) {
    066                            return word.substring(0, word.length()-3);
    067                    } else {
    068                            throw new RuntimeException("Illegal of-construct: " + word);
    069                    }
    070            }
    071
    072            /**
    073             * Returns the pretty-printed noun of the of-construct. Pretty-printing replaces
    074             * underscores by blanks.
    075             *
    076             * @return The pretty-printed noun.
    077             */
    078            public String getPrettyNoun() {
    079                    String n = getPrettyWord(0);
    080                    if (n == null) {
    081                            return null;
    082                    } else if (n.endsWith(" of")) {
    083                            return n.substring(0, n.length()-3);
    084                    } else {
    085                            throw new RuntimeException("Illegal of-construct: " + n);
    086                    }
    087            }
    088
    089            List<LexiconEntry> getLexiconEntries() {
    090                    List<LexiconEntry> entries = new ArrayList<LexiconEntry>();
    091                    if (word != null) {
    092                            entries.add(LexiconEntry.createNounSgEntry(getNoun(), getNoun(), Gender.NEUTRAL));
    093                    }
    094                    return entries;
    095            }
    096
    097            public String getType() {
    098                    return "Of-Construct";
    099            }
    100
    101            public String getInternalType() {
    102                    return "nounof";
    103            }
    104
    105    }