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.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 lexiconEntryString 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 that defines the positive form of an adverb, for example "manually" or "fast".
038             * 
039             * @param wordForm The word form how it should appear in the ACE texts.
040             * @param symbol The symbol how it should appear in the logical representations.
041             * @return The new lexicon entry.
042             */
043            public static LexiconEntry createAdvEntry(String wordForm, String symbol) {
044                    return new LexiconEntry("adv(" + escape(wordForm) + ", " + escape(symbol) + ")");
045            }
046    
047            /**
048             * Creates a new lexicon entry that defines the comparative form of an adverb, for example "faster".
049             * 
050             * @param wordForm The word form how it should appear in the ACE texts.
051             * @param symbol The symbol how it should appear in the logical representations.
052             * @return The new lexicon entry.
053             */
054            public static LexiconEntry createAdvCompEntry(String wordForm, String symbol) {
055                    return new LexiconEntry("adv_comp(" + escape(wordForm) + ", " + escape(symbol) + ")");
056            }
057    
058            /**
059             * Creates a new lexicon entry that defines the superlative form of an adverb, for example "fastest".
060             * 
061             * @param wordForm The word form how it should appear in the ACE texts.
062             * @param symbol The symbol how it should appear in the logical representations.
063             * @return The new lexicon entry.
064             */
065            public static LexiconEntry createAdvSupEntry(String wordForm, String symbol) {
066                    return new LexiconEntry("adv_sup(" + escape(wordForm) + ", " + escape(symbol) + ")");
067            }
068    
069            /**
070             * Creates a new lexicon entry that defines the positive form of an adjective, for example "rich".
071             * 
072             * @param wordForm The word form how it should appear in the ACE texts.
073             * @param symbol The symbol how it should appear in the logical representations.
074             * @return The new lexicon entry.
075             */
076            public static LexiconEntry createAdjEntry(String wordForm, String symbol) {
077                    return new LexiconEntry("adj_itr(" + escape(wordForm) + ", " + escape(symbol) + ")");
078            }
079    
080            /**
081             * Creates a new lexicon entry that defines the comparative form of an adjective, for example "richer".
082             * 
083             * @param wordForm The word form how it should appear in the ACE texts.
084             * @param symbol The symbol how it should appear in the logical representations.
085             * @return The new lexicon entry.
086             */
087            public static LexiconEntry createAdjCompEntry(String wordForm, String symbol) {
088                    return new LexiconEntry("adj_itr_comp(" + escape(wordForm) + ", " + escape(symbol) + ")");
089            }
090    
091            /**
092             * Creates a new lexicon entry that defines the superlative form of an adjective, for example "richest".
093             * 
094             * @param wordForm The word form how it should appear in the ACE texts.
095             * @param symbol The symbol how it should appear in the logical representations.
096             * @return The new lexicon entry.
097             */
098            public static LexiconEntry createAdjSupEntry(String wordForm, String symbol) {
099                    return new LexiconEntry("adj_itr_sup(" + escape(wordForm) + ", " + escape(symbol) + ")");
100            }
101    
102            /**
103             * Creates a new lexicon entry that defines the positive form of a transitive adjective, for example "fond-of".
104             * 
105             * @param wordForm The word form how it should appear in the ACE texts.
106             * @param symbol The symbol how it should appear in the logical representations.
107             * @param preposition The preposition of the transitive adjective, for example "of" in the case of "fond-of".
108             * @return The new lexicon entry.
109             */
110            public static LexiconEntry createTrAdjEntry(String wordForm, String symbol, String preposition) {
111                    return new LexiconEntry("adj_tr(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")");
112            }
113    
114            /**
115             * Creates a new lexicon entry that defines the comparative form of a transitive adjective, for example "fonder-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 "fonder-of".
120             * @return The new lexicon entry.
121             */
122            public static LexiconEntry createTrAdjCompEntry(String wordForm, String symbol, String preposition) {
123                    return new LexiconEntry("adj_tr_comp(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")");
124            }
125    
126            /**
127             * Creates a new lexicon entry that defines the superlative form of a transitive adjective, for example "fondest-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 "fondest-of".
132             * @return The new lexicon entry.
133             */
134            public static LexiconEntry createTrAdjSupEntry(String wordForm, String symbol, String preposition) {
135                    return new LexiconEntry("adj_tr_sup(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")");
136            }
137    
138            /**
139             * Creates a new lexicon entry that defines the singular form of a countable noun, for example "country".
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 gender The gender of the noun.
144             * @return The new lexicon entry.
145             */
146            public static LexiconEntry createNounSgEntry(String wordForm, String symbol, Gender gender) {
147                    return new LexiconEntry("noun_sg(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
148            }
149    
150            /**
151             * Creates a new lexicon entry that defines the plural form of a countable noun, for example "countries".
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 createNounPlEntry(String wordForm, String symbol, Gender gender) {
159                    return new LexiconEntry("noun_pl(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
160            }
161    
162            /**
163             * Creates a new lexicon entry that defines a mass noun, for example "money".
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 createNounMassEntry(String wordForm, String symbol, Gender gender) {
171                    return new LexiconEntry("noun_mass(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
172            }
173    
174            /**
175             * Creates a new lexicon entry that defines the singular form of a measurement noun, for example "mile", "km".
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             * @return The new lexicon entry.
180             */
181            public static LexiconEntry createMeasureNounSgEntry(String wordForm, String symbol) {
182                    return new LexiconEntry("mn_sg(" + escape(wordForm) + ", " + escape(symbol) + ")");
183            }
184    
185            /**
186             * Creates a new lexicon entry that defines the plural form of a measurement noun, for example "miles", "km".
187             * 
188             * @param wordForm The word form how it should appear in the ACE texts.
189             * @param symbol The symbol how it should appear in the logical representations.
190             * @return The new lexicon entry.
191             */
192            public static LexiconEntry createMeasureNounPlEntry(String wordForm, String symbol) {
193                    return new LexiconEntry("mn_pl(" + escape(wordForm) + ", " + escape(symbol) + ")");
194            }
195    
196            /**
197             * Creates a new lexicon entry that defines a singular proper name, for example "Switzerland".
198             * 
199             * @param wordForm The word form how it should appear in the ACE texts.
200             * @param symbol The symbol how it should appear in the logical representations.
201             * @param gender The gender of the proper name.
202             * @return The new lexicon entry.
203             */
204            public static LexiconEntry createPropernameSgEntry(String wordForm, String symbol, Gender gender) {
205                    return new LexiconEntry("pn_sg(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
206            }
207    
208            /**
209             * Creates a new lexicon entry that defines a plural proper name, for example "United-States".
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 createPropernamePlEntry(String wordForm, String symbol, Gender gender) {
217                    return new LexiconEntry("pn_pl(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
218            }
219    
220            /**
221             * Creates a new lexicon entry that defines a singular proper name to be used with the definite article
222             * "the", for example "the Nile".
223             * 
224             * @param wordForm The word form how it should appear in the ACE texts.
225             * @param symbol The symbol how it should appear in the logical representations.
226             * @param gender The gender of the proper name.
227             * @return The new lexicon entry.
228             */
229            public static LexiconEntry createPropernameDefSgEntry(String wordForm, String symbol, Gender gender) {
230                    return new LexiconEntry("pndef_sg(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
231            }
232    
233            /**
234             * Creates a new lexicon entry that defines a plural proper name to be used with the definite article
235             * "the", for example "the United-Nations".
236             * 
237             * @param wordForm The word form how it should appear in the ACE texts.
238             * @param symbol The symbol how it should appear in the logical representations.
239             * @param gender The gender of the proper name.
240             * @return The new lexicon entry.
241             */
242            public static LexiconEntry createPropernameDefPlEntry(String wordForm, String symbol, Gender gender) {
243                    return new LexiconEntry("pndef_pl(" + escape(wordForm) + ", " + escape(symbol) + ", " + gender + ")");
244            }
245    
246            /**
247             * Creates a new lexicon entry that defines the third singular form of an intransitive verb, for example "waits".
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             * @return The new lexicon entry.
252             */
253            public static LexiconEntry createItrVerbThirdEntry(String wordForm, String symbol) {
254                    return new LexiconEntry("iv_finsg(" + escape(wordForm) + ", " + escape(symbol) + ")");
255            }
256    
257            /**
258             * Creates a new lexicon entry that defines the bare infinitive form of an intransitive verb, for example "wait".
259             * 
260             * @param wordForm The word form how it should appear in the ACE texts.
261             * @param symbol The symbol how it should appear in the logical representations.
262             * @return The new lexicon entry.
263             */
264            public static LexiconEntry createItrVerbInfEntry(String wordForm, String symbol) {
265                    return new LexiconEntry("iv_infpl(" + escape(wordForm) + ", " + escape(symbol) + ")");
266            }
267    
268            /**
269             * Creates a new lexicon entry that defines the third singular form of a transitive verb, for example "contains".
270             * 
271             * @param wordForm The word form how it should appear in the ACE texts.
272             * @param symbol The symbol how it should appear in the logical representations.
273             * @return The new lexicon entry.
274             */
275            public static LexiconEntry createTrVerbThirdEntry(String wordForm, String symbol) {
276                    return new LexiconEntry("tv_finsg(" + escape(wordForm) + ", " + escape(symbol) + ")");
277            }
278    
279            /**
280             * Creates a new lexicon entry that defines the bare infinitive form of a transitive verb, for example "contain".
281             * 
282             * @param wordForm The word form how it should appear in the ACE texts.
283             * @param symbol The symbol how it should appear in the logical representations.
284             * @return The new lexicon entry.
285             */
286            public static LexiconEntry createTrVerbInfEntry(String wordForm, String symbol) {
287                    return new LexiconEntry("tv_infpl(" + escape(wordForm) + ", " + escape(symbol) + ")");
288            }
289    
290            /**
291             * Creates a new lexicon entry that defines the past participle form of a transitive verb, for example "contained".
292             * 
293             * @param wordForm The word form how it should appear in the ACE texts.
294             * @param symbol The symbol how it should appear in the logical representations.
295             * @return The new lexicon entry.
296             */
297            public static LexiconEntry createTrVerbPPEntry(String wordForm, String symbol) {
298                    return new LexiconEntry("tv_pp(" + escape(wordForm) + ", " + escape(symbol) + ")");
299            }
300    
301            /**
302             * Creates a new lexicon entry that defines the third singular form of a ditransitive verb, for example "gives".
303             * 
304             * @param wordForm The word form how it should appear in the ACE texts.
305             * @param symbol The symbol how it should appear in the logical representations.
306             * @param preposition The preposition for the indirect object.
307             * @return The new lexicon entry.
308             */
309            public static LexiconEntry createDitrVerbThirdEntry(String wordForm, String symbol, String preposition) {
310                    return new LexiconEntry("dv_finsg(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")");
311            }
312    
313            /**
314             * Creates a new lexicon entry that defines the bare infinitive form of a ditransitive verb, for example "give".
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 createDitrVerbInfEntry(String wordForm, String symbol, String preposition) {
322                    return new LexiconEntry("dv_infpl(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")");
323            }
324    
325            /**
326             * Creates a new lexicon entry that defines the past participle form of a ditransitive verb, for example "given".
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 createDitrVerbPPEntry(String wordForm, String symbol, String preposition) {
334                    return new LexiconEntry("dv_pp(" + escape(wordForm) + ", " + escape(symbol) + ", " + escape(preposition) + ")");
335            }
336    
337            /**
338             * Creates a new lexicon entry that defines a preposition, for example "for".
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             * @return The new lexicon entry.
343             */
344            public static LexiconEntry createPrepEntry(String wordForm, String symbol) {
345                    return new LexiconEntry("prep(" + escape(wordForm) + ", " + escape(symbol) + ")");
346            }
347    
348            /**
349             * Returns the plain text serialization for this lexicon entry.
350             * 
351             * @return The plain text serialization for this lexicon entry.
352             */
353            @Override
354            public String toString() {
355                    return lexiconTerm;
356            }
357            
358            private static String escape(String str) {
359                    return PrologUtils.escape(str);
360            }
361            
362            public boolean equals(Object obj) {
363                    if (obj instanceof LexiconEntry) {
364                            LexiconEntry other = (LexiconEntry) obj;
365                            return this.toString().equals(other.toString());
366                    } else {
367                            return false;
368                    }
369            }
370            
371    }