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.List; 019 020 import ch.uzh.ifi.attempto.acewiki.core.InvalidWordException; 021 import ch.uzh.ifi.attempto.acewiki.core.LanguageUtils; 022 import ch.uzh.ifi.attempto.acewiki.core.LexiconChanger; 023 import ch.uzh.ifi.attempto.acewiki.core.LexiconDetail; 024 import ch.uzh.ifi.attempto.acewiki.core.Ontology; 025 import ch.uzh.ifi.attempto.acewiki.core.OntologyElement; 026 import ch.uzh.ifi.attempto.ape.FunctionWords; 027 028 /** 029 * This class is used to modify or create transitive adjectives. 030 * 031 * @author Tobias Kuhn 032 */ 033 public class TrAdjChanger implements LexiconChanger { 034 035 public String getDescription() { 036 return "Every transitive adjective represents a certain relation between things. " + 037 "For example, the transitive adjective \"located in\" relates things to " + 038 "their location. Transitive adjectives consist of an adjective that " + 039 "is followed by a preposition."; 040 } 041 042 public List<LexiconDetail> getDetails(OntologyElement el) { 043 TrAdjRelation relation = (TrAdjRelation) el; 044 List<LexiconDetail> l = new ArrayList<LexiconDetail>(); 045 l.add(new LexiconDetail( 046 "tr. adjective", 047 "examples: located in, matched with, fond of", 048 relation.getWord(0) 049 )); 050 return l; 051 } 052 053 public void save(OntologyElement el, int wordNumber, List<Object> newValues, Ontology ontology) 054 throws InvalidWordException { 055 TrAdjRelation relation = (TrAdjRelation) el; 056 057 String name = ACEOWLLexicon.normalize((String) newValues.get(0)); 058 String nameP = LanguageUtils.getPrettyPrinted(name); 059 060 if (name.equals("")) { 061 throw new InvalidWordException("No word defined: Please specify the transitive " + 062 "adjective."); 063 } 064 if (!ACEOWLLexicon.isValidWordOrEmpty(name)) { 065 throw new InvalidWordException("Invalid character: Only a-z, A-Z, 0-9, -, and " + 066 "spaces are allowed, and the first character must be one of a-z A-Z."); 067 } 068 if (FunctionWords.isFunctionWord(name)) { 069 throw new InvalidWordException("'" + nameP + "' is a predefined word and cannot be " + 070 "used here."); 071 } 072 OntologyElement oe = ontology.getElement(name); 073 if (oe != null && oe != relation) { 074 throw new InvalidWordException("The word '" + nameP + "' is already used. Please " + 075 "use a different one."); 076 } 077 ontology.change(relation, name); 078 } 079 080 }