001 // This file is part of the Attempto Java Packages. 002 // Copyright 2008-2009, 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.ape; 016 017 /** 018 * This class represents a single lexicon entry. 019 * 020 * @author Tobias Kuhn 021 * @author Kaarel Kaljurand 022 */ 023 public class LexiconEntry { 024 025 private String lexiconTerm; 026 027 /** 028 * Creates a new lexicon entry on the basis of a string that is a serialization of a Prolog term. 029 * 030 * @param lexiconTerm A string that is a serialized Prolog term representing a lexicon entry. 031 */ 032 private LexiconEntry(String lexiconTerm) { 033 this.lexiconTerm = lexiconTerm; 034 } 035 036 /** 037 * Creates a new lexicon entry on the basis of a string that is a serialization of a Prolog term. 038 * The string is not checked for wellformedness. Whenever possible, one of the other static constructor 039 * methods should be used instead of this method. 040 * 041 * @param lexiconTerm A string that is a serialized Prolog term representing a lexicon entry. 042 * @return The new lexicon entry. 043 */ 044 public static LexiconEntry createEntry(String lexiconTerm) { 045 return new LexiconEntry(lexiconTerm); 046 } 047 048 /** 049 * Creates a new lexicon entry that defines the positive form of an adverb, for example "manually" or "fast". 050 * 051 * @param wordForm The word form how it should appear in the ACE texts. 052 * @param symbol The symbol how it should appear in the logical representations. 053 * @return The new lexicon entry. 054 */ 055 public static LexiconEntry createAdvEntry(String wordForm, String symbol) { 056 return new LexiconEntry("adv(" + escape(wordForm) + ", " + escape(symbol) + ")"); 057 } 058 059 /** 060 * Creates a new lexicon entry that defines the comparative form of an adverb, for example "faster". 061 * 062 * @param wordForm The word form how it should appear in the ACE texts. 063 * @param symbol The symbol how it should appear in the logical representations. 064 * @return The new lexicon entry. 065 */ 066 public static LexiconEntry createAdvCompEntry(String wordForm, String symbol) { 067 return new LexiconEntry("adv_comp(" + escape(wordForm) + ", " + escape(symbol) + ")"); 068 } 069 070 /** 071 * Creates a new lexicon entry that defines the superlative form of an adverb, for example "fastest". 072 * 073 * @param wordForm The word form how it should appear in the ACE texts. 074 * @param symbol The symbol how it should appear in the logical representations. 075 * @return The new lexicon entry. 076 */ 077 public static LexiconEntry createAdvSupEntry(String wordForm, String symbol) { 078 return new LexiconEntry("adv_sup(" + escape(wordForm) + ", " + escape(symbol) + ")"); 079 } 080 081 /** 082 * Creates a new lexicon entry that defines the positive form of an adjective, for example "rich". 083 * 084 * @param wordForm The word form how it should appear in the ACE texts. 085 * @param symbol The symbol how it should appear in the logical representations. 086 * @return The new lexicon entry. 087 */ 088 public static LexiconEntry createAdjEntry(String wordForm, String symbol) { 089 return new LexiconEntry("adj_itr(" + escape(wordForm) + ", " + escape(symbol) + ")"); 090 } 091 092 /** 093 * Creates a new lexicon entry that defines the comparative form of an adjective, for example "richer". 094 * 095 * @param wordForm The word form how it should appear in the ACE texts. 096 * @param symbol The symbol how it should appear in the logical representations. 097 * @return The new lexicon entry. 098 */ 099 public static LexiconEntry createAdjCompEntry(String wordForm, String symbol) { 100 return new LexiconEntry("adj_itr_comp(" + escape(wordForm) + ", " + escape(symbol) + ")"); 101 } 102 103 /** 104 * Creates a new lexicon entry that defines the superlative form of an adjective, for example "richest". 105 * 106 * @param wordForm The word form how it should appear in the ACE texts. 107 * @param symbol The symbol how it should appear in the logical representations. 108 * @return The new lexicon entry. 109 */ 110 public static LexiconEntry createAdjSupEntry(String wordForm, String symbol) { 111 return new LexiconEntry("adj_itr_sup(" + escape(wordForm) + ", " + escape(symbol) + ")"); 112 } 113 114 /** 115 * Creates a new lexicon entry that defines the positive form of a transitive adjective, for example "fond-of". 116 * 117 * @param wordForm The word form how it should appear in the ACE texts. 118 * @param symbol The symbol how it should appear in the logical representations. 119 * @param preposition The preposition of the transitive adjective, for example "of" in the case of "fond-of". 120 * @return The new lexicon entry. 121 */ 122 public static LexiconEntry createTrAdjEntry(String wordForm, String symbol, String preposition) { 123 return new LexiconEntry("adj_tr(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")"); 124 } 125 126 /** 127 * Creates a new lexicon entry that defines the comparative form of a transitive adjective, for example "fonder-of". 128 * 129 * @param wordForm The word form how it should appear in the ACE texts. 130 * @param symbol The symbol how it should appear in the logical representations. 131 * @param preposition The preposition of the transitive adjective, for example "of" in the case of "fonder-of". 132 * @return The new lexicon entry. 133 */ 134 public static LexiconEntry createTrAdjCompEntry(String wordForm, String symbol, String preposition) { 135 return new LexiconEntry("adj_tr_comp(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")"); 136 } 137 138 /** 139 * Creates a new lexicon entry that defines the superlative form of a transitive adjective, for example "fondest-of". 140 * 141 * @param wordForm The word form how it should appear in the ACE texts. 142 * @param symbol The symbol how it should appear in the logical representations. 143 * @param preposition The preposition of the transitive adjective, for example "of" in the case of "fondest-of". 144 * @return The new lexicon entry. 145 */ 146 public static LexiconEntry createTrAdjSupEntry(String wordForm, String symbol, String preposition) { 147 return new LexiconEntry("adj_tr_sup(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")"); 148 } 149 150 /** 151 * Creates a new lexicon entry that defines the singular form of a countable noun, for example "country". 152 * 153 * @param wordForm The word form how it should appear in the ACE texts. 154 * @param symbol The symbol how it should appear in the logical representations. 155 * @param gender The gender of the noun. 156 * @return The new lexicon entry. 157 */ 158 public static LexiconEntry createNounSgEntry(String wordForm, String symbol, Gender gender) { 159 return new LexiconEntry("noun_sg(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 160 } 161 162 /** 163 * Creates a new lexicon entry that defines the plural form of a countable noun, for example "countries". 164 * 165 * @param wordForm The word form how it should appear in the ACE texts. 166 * @param symbol The symbol how it should appear in the logical representations. 167 * @param gender The gender of the noun. 168 * @return The new lexicon entry. 169 */ 170 public static LexiconEntry createNounPlEntry(String wordForm, String symbol, Gender gender) { 171 return new LexiconEntry("noun_pl(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 172 } 173 174 /** 175 * Creates a new lexicon entry that defines a mass noun, for example "money". 176 * 177 * @param wordForm The word form how it should appear in the ACE texts. 178 * @param symbol The symbol how it should appear in the logical representations. 179 * @param gender The gender of the noun. 180 * @return The new lexicon entry. 181 */ 182 public static LexiconEntry createNounMassEntry(String wordForm, String symbol, Gender gender) { 183 return new LexiconEntry("noun_mass(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 184 } 185 186 /** 187 * Creates a new lexicon entry that defines the singular form of a measurement noun, for example "mile", "km". 188 * 189 * @param wordForm The word form how it should appear in the ACE texts. 190 * @param symbol The symbol how it should appear in the logical representations. 191 * @return The new lexicon entry. 192 */ 193 public static LexiconEntry createMeasureNounSgEntry(String wordForm, String symbol) { 194 return new LexiconEntry("mn_sg(" + escape(wordForm) + ", " + escape(symbol) + ")"); 195 } 196 197 /** 198 * Creates a new lexicon entry that defines the plural form of a measurement noun, for example "miles", "km". 199 * 200 * @param wordForm The word form how it should appear in the ACE texts. 201 * @param symbol The symbol how it should appear in the logical representations. 202 * @return The new lexicon entry. 203 */ 204 public static LexiconEntry createMeasureNounPlEntry(String wordForm, String symbol) { 205 return new LexiconEntry("mn_pl(" + escape(wordForm) + ", " + escape(symbol) + ")"); 206 } 207 208 /** 209 * Creates a new lexicon entry that defines a singular proper name, for example "Switzerland". 210 * 211 * @param wordForm The word form how it should appear in the ACE texts. 212 * @param symbol The symbol how it should appear in the logical representations. 213 * @param gender The gender of the proper name. 214 * @return The new lexicon entry. 215 */ 216 public static LexiconEntry createPropernameSgEntry(String wordForm, String symbol, Gender gender) { 217 return new LexiconEntry("pn_sg(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 218 } 219 220 /** 221 * Creates a new lexicon entry that defines a plural proper name, for example "United-States". 222 * 223 * @param wordForm The word form how it should appear in the ACE texts. 224 * @param symbol The symbol how it should appear in the logical representations. 225 * @param gender The gender of the proper name. 226 * @return The new lexicon entry. 227 */ 228 public static LexiconEntry createPropernamePlEntry(String wordForm, String symbol, Gender gender) { 229 return new LexiconEntry("pn_pl(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 230 } 231 232 /** 233 * Creates a new lexicon entry that defines a singular proper name to be used with the definite article 234 * "the", for example "the Nile". 235 * 236 * @param wordForm The word form how it should appear in the ACE texts. 237 * @param symbol The symbol how it should appear in the logical representations. 238 * @param gender The gender of the proper name. 239 * @return The new lexicon entry. 240 */ 241 public static LexiconEntry createPropernameDefSgEntry(String wordForm, String symbol, Gender gender) { 242 return new LexiconEntry("pndef_sg(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 243 } 244 245 /** 246 * Creates a new lexicon entry that defines a plural proper name to be used with the definite article 247 * "the", for example "the United-Nations". 248 * 249 * @param wordForm The word form how it should appear in the ACE texts. 250 * @param symbol The symbol how it should appear in the logical representations. 251 * @param gender The gender of the proper name. 252 * @return The new lexicon entry. 253 */ 254 public static LexiconEntry createPropernameDefPlEntry(String wordForm, String symbol, Gender gender) { 255 return new LexiconEntry("pndef_pl(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")"); 256 } 257 258 /** 259 * Creates a new lexicon entry that defines the third singular form of an intransitive verb, for example "waits". 260 * 261 * @param wordForm The word form how it should appear in the ACE texts. 262 * @param symbol The symbol how it should appear in the logical representations. 263 * @return The new lexicon entry. 264 */ 265 public static LexiconEntry createItrVerbThirdEntry(String wordForm, String symbol) { 266 return new LexiconEntry("iv_finsg(" + escape(wordForm) + ", " + escape(symbol) + ")"); 267 } 268 269 /** 270 * Creates a new lexicon entry that defines the bare infinitive form of an intransitive verb, for example "wait". 271 * 272 * @param wordForm The word form how it should appear in the ACE texts. 273 * @param symbol The symbol how it should appear in the logical representations. 274 * @return The new lexicon entry. 275 */ 276 public static LexiconEntry createItrVerbInfEntry(String wordForm, String symbol) { 277 return new LexiconEntry("iv_infpl(" + escape(wordForm) + ", " + escape(symbol) + ")"); 278 } 279 280 /** 281 * Creates a new lexicon entry that defines the third singular form of a transitive verb, for example "contains". 282 * 283 * @param wordForm The word form how it should appear in the ACE texts. 284 * @param symbol The symbol how it should appear in the logical representations. 285 * @return The new lexicon entry. 286 */ 287 public static LexiconEntry createTrVerbThirdEntry(String wordForm, String symbol) { 288 return new LexiconEntry("tv_finsg(" + escape(wordForm) + ", " + escape(symbol) + ")"); 289 } 290 291 /** 292 * Creates a new lexicon entry that defines the bare infinitive form of a transitive verb, for example "contain". 293 * 294 * @param wordForm The word form how it should appear in the ACE texts. 295 * @param symbol The symbol how it should appear in the logical representations. 296 * @return The new lexicon entry. 297 */ 298 public static LexiconEntry createTrVerbInfEntry(String wordForm, String symbol) { 299 return new LexiconEntry("tv_infpl(" + escape(wordForm) + ", " + escape(symbol) + ")"); 300 } 301 302 /** 303 * Creates a new lexicon entry that defines the past participle form of a transitive verb, for example "contained". 304 * 305 * @param wordForm The word form how it should appear in the ACE texts. 306 * @param symbol The symbol how it should appear in the logical representations. 307 * @return The new lexicon entry. 308 */ 309 public static LexiconEntry createTrVerbPPEntry(String wordForm, String symbol) { 310 return new LexiconEntry("tv_pp(" + escape(wordForm) + ", " + escape(symbol) + ")"); 311 } 312 313 /** 314 * Creates a new lexicon entry that defines the third singular form of a ditransitive verb, for example "gives". 315 * 316 * @param wordForm The word form how it should appear in the ACE texts. 317 * @param symbol The symbol how it should appear in the logical representations. 318 * @param preposition The preposition for the indirect object. 319 * @return The new lexicon entry. 320 */ 321 public static LexiconEntry createDitrVerbThirdEntry(String wordForm, String symbol, String preposition) { 322 return new LexiconEntry("dv_finsg(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")"); 323 } 324 325 /** 326 * Creates a new lexicon entry that defines the bare infinitive form of a ditransitive verb, for example "give". 327 * 328 * @param wordForm The word form how it should appear in the ACE texts. 329 * @param symbol The symbol how it should appear in the logical representations. 330 * @param preposition The preposition for the indirect object. 331 * @return The new lexicon entry. 332 */ 333 public static LexiconEntry createDitrVerbInfEntry(String wordForm, String symbol, String preposition) { 334 return new LexiconEntry("dv_infpl(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")"); 335 } 336 337 /** 338 * Creates a new lexicon entry that defines the past participle form of a ditransitive verb, for example "given". 339 * 340 * @param wordForm The word form how it should appear in the ACE texts. 341 * @param symbol The symbol how it should appear in the logical representations. 342 * @param preposition The preposition for the indirect object. 343 * @return The new lexicon entry. 344 */ 345 public static LexiconEntry createDitrVerbPPEntry(String wordForm, String symbol, String preposition) { 346 return new LexiconEntry("dv_pp(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")"); 347 } 348 349 /** 350 * Creates a new lexicon entry that defines a preposition, for example "for". 351 * 352 * @param wordForm The word form how it should appear in the ACE texts. 353 * @param symbol The symbol how it should appear in the logical representations. 354 * @return The new lexicon entry. 355 */ 356 public static LexiconEntry createPrepEntry(String wordForm, String symbol) { 357 return new LexiconEntry("prep(" + escape(wordForm) + ", " + escape(symbol) + ")"); 358 } 359 360 /** 361 * Returns the plain text serialization for this lexicon entry. 362 * 363 * @return The plain text serialization for this lexicon entry. 364 */ 365 @Override 366 public String toString() { 367 return lexiconTerm; 368 } 369 370 private static String escape(String str) { 371 return PrologUtils.escape(str); 372 } 373 374 public boolean equals(Object obj) { 375 if (obj instanceof LexiconEntry) { 376 LexiconEntry other = (LexiconEntry) obj; 377 return this.toString().equals(other.toString()); 378 } else { 379 return false; 380 } 381 } 382 383 }