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.LexiconEntry; 021 022 /** 023 * This class stands for roles that are represented by a transitive verb. Transitive 024 * verbs have three word forms: a third singular form, a bare infinitive form , 025 * and a passive form. The bare infinitive form is used in the case of negation and plural. 026 * The passive form always ends with the word "by". 027 *<p> 028 * 0: third singular form. 029 * 1: bare infinitive form. 030 * 2: passive form. 031 *<p> 032 * Examples: ["gives", "give", "given by"]; ["knows", "know", "known by"]. 033 * 034 * @author Tobias Kuhn 035 */ 036 public class VerbRole extends Role { 037 038 private String thirdSg, inf, passive; 039 040 /** 041 * Creates a new verb role. 042 */ 043 public VerbRole() { 044 } 045 046 public String[] getWords() { 047 return new String[] {thirdSg, inf, passive}; 048 } 049 050 protected void changeWords(String... words) { 051 thirdSg = words[0]; 052 inf = words[1]; 053 if (words.length < 3 || words[2] == null) { 054 passive = null; 055 } else if (words[2].endsWith(" by")) { 056 passive = words[2]; 057 } else { 058 passive = words[2] + " by"; 059 } 060 } 061 062 /** 063 * Returns the past participle which is the passive form without the "by". 064 * E.g. for the passive form "given by", the past participle is "given". 065 * 066 * @return The past participle form. 067 */ 068 public String getPastPart() { 069 String s = getWord(2); 070 if (s == null) { 071 return null; 072 } else if (s.endsWith(" by")) { 073 return s.substring(0, s.length()-3); 074 } else { 075 throw new RuntimeException("Illegal passive word form: " + s); 076 } 077 } 078 079 /** 080 * Returns the pretty-printed past participle. The pretty printing replaces 081 * underscores by blanks. 082 * 083 * @return The pretty-printed past participle form. 084 * @see #getPastPart() 085 */ 086 public String getPrettyPastPart() { 087 String s = getWord(2); 088 if (s == null) { 089 return null; 090 } else if (s.endsWith(" by")) { 091 return s.substring(0, s.length()-3); 092 } else { 093 throw new RuntimeException("Illegal passive word form: " + s); 094 } 095 } 096 097 List<LexiconEntry> getLexiconEntries() { 098 List<LexiconEntry> entries = new ArrayList<LexiconEntry>(); 099 entries.add(LexiconEntry.createTrVerbThirdEntry(thirdSg, inf)); 100 entries.add(LexiconEntry.createTrVerbInfEntry(inf, inf)); 101 if (passive != null) { 102 entries.add(LexiconEntry.createTrVerbPPEntry(getPastPart(), inf)); 103 } 104 return entries; 105 } 106 107 public String getType() { 108 return "Verb"; 109 } 110 111 public String getInternalType() { 112 return "trverb"; 113 } 114 115 }