    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.text;
    016
    017    import ch.uzh.ifi.attempto.acewiki.core.ontology.Individual;
    018    import ch.uzh.ifi.attempto.acewiki.core.ontology.NounConcept;
    019    import ch.uzh.ifi.attempto.acewiki.core.ontology.OfRole;
    020    import ch.uzh.ifi.attempto.acewiki.core.ontology.OntologyElement;
    021    import ch.uzh.ifi.attempto.acewiki.core.ontology.TrAdjRole;
    022    import ch.uzh.ifi.attempto.acewiki.core.ontology.VerbRole;
    023    import ch.uzh.ifi.attempto.preditor.text.TextElement;
    024
    025    /**
    026     * This factory class creates text element objects on the basis of ontology elements.
    027     *
    028     * @author Tobias Kuhn
    029     */
    030    public class TextElemFactory {
    031
    032            private TextElemFactory() {}  // no instances allowed
    033
    034            /**
    035             * Creates a new text element for the given word form (by word form id) of the given
    036             * ontology element.
    037             *
    038             * @param el The ontology element.
    039             * @param wordNumber The word form id.
    040             * @return The newly created text element.
    041             */
    042            public static OntologyTextElement createTextElement(OntologyElement el, int wordNumber) {
    043                    if (el instanceof NounConcept) {
    044                            if (wordNumber == 0) {
    045                                    return new NounTextElem((NounConcept) el);
    046                            } else if (wordNumber == 1) {
    047                                    return new OntoTextElem(el, 1, "NOUNPL");
    048                            }
    049                    } else if (el instanceof Individual) {
    050                            if (wordNumber == 0) return new OntoTextElem(el, 0, "PROPERNAME");
    051                    } else if (el instanceof VerbRole) {
    052                            if (wordNumber == 0) {
    053                                    return new OntoTextElem(el, 0, "VERB");
    054                            } else if (wordNumber == 1) {
    055                                    return new OntoTextElem(el, 1, "VERBINF");
    056                            } else if (wordNumber == 2) {
    057                                    return new OntoTextElem(el, 2, "PVERB");
    058                            }
    059                    } else if (el instanceof OfRole) {
    060                            if (wordNumber == 0) return new OntoTextElem(el, 0, "NOUNOF");
    061                    } else if (el instanceof TrAdjRole) {
    062                            if (wordNumber == 0) return new OntoTextElem(el, 0, "TRADJ");
    063                    }
    064                    return null;
    065            }
    066
    067            /**
    068             * Creates a new text element for the default word form of the given ontology element.
    069             *
    070             * @param el The ontology element.
    071             * @return The newly created text element.
    072             */
    073            public static TextElement createTextElement(OntologyElement el) {
    074                    return createTextElement(el, 0);
    075            }
    076
    077    }