| Lookup.java |
1 /*
2 * Lookup.java
3 *
4 * Copyright (c) 1998-2005, The University of Sheffield.
5 *
6 * This file is part of GATE (see http://gate.ac.uk/), and is free
7 * software, licenced under the GNU Library General Public License,
8 * Version 2, June 1991 (in the distribution as file licence.html,
9 * and also available at http://gate.ac.uk/gate/licence.html).
10 *
11 * Valentin Tablan, 11/07/2000
12 * borislav popov, 05/02/2002
13 *
14 * $Id: Lookup.java,v 1.11 2005/01/11 13:51:32 ian Exp $
15 */
16
17 package gate.creole.gazetteer;
18
19 /**
20 * Used to describe a type of lookup annotations. A lookup is described by a
21 * major type a minor type and a list of languages. Added members are :
22 * ontologyClass and list.
23 * All these values are strings (the list of languages is a string and it is
24 * intended to represesnt a comma separated list).
25 */
26 public class Lookup implements java.io.Serializable {
27
28 /** Debug flag
29 */
30 private static final boolean DEBUG = false;
31
32 /**
33 * Creates a new Lookup value with the given major and minor types and
34 * languages.
35 *
36 * @param major major type
37 * @param minor minor type
38 * @param theLanguages the languages
39 */
40 public Lookup(String theList, String major, String minor, String theLanguages){
41 majorType = major;
42 minorType = minor;
43 languages = theLanguages;
44 list = theList;
45 }
46
47 /** Tha major type for this lookup, e.g. "Organisation" */
48 public String majorType;
49
50 /** The minor type for this lookup, e.g. "Company" */
51 public String minorType;
52
53 /** The languages for this lookup, e.g. "English, French" */
54 public String languages;
55
56 /** the ontology class of this lookup according to the mapping between
57 * list and ontology */
58 public String oClass;
59
60 /** the ontology ID */
61 public String ontology;
62
63 /** the list represented by this lookup*/
64 public String list;
65
66 /**Returns a string representation of this lookup in the format
67 * This method is used in equals()
68 * that caused this method to implement dualistic behaviour :
69 * i.e. whenever class and ontology are filled then use the
70 * long version,incl. list, ontology and class;
71 * else return just majorType.minorType */
72 public String toString(){
73 StringBuffer b = new StringBuffer();
74 boolean longVersion = false;
75 if (null!=ontology && null!=oClass){
76 longVersion = true;
77 }
78
79 if ( longVersion ) {
80 b.append(list);
81 b.append(".");
82 }
83 b.append(majorType);
84 b.append(".");
85 if (null != minorType) {
86 b.append(minorType);
87 if (null!= languages) {
88 b.append(".");
89 b.append(languages);
90 }//if
91 }//if
92 if (longVersion) {
93 b.append("|");
94 b.append(ontology);
95 b.append(":");
96 b.append(oClass);
97 }
98 return b.toString();
99 }
100
101 /**
102 * Two lookups are equal if they have the same string representation
103 * (major type and minor type).
104 * @param obj
105 */
106 public boolean equals(Object obj){
107 if(obj instanceof Lookup) return obj.toString().equals(toString());
108 else return false;
109 } // equals
110
111 /** *
112 */
113 public int hashCode(){ return toString().hashCode();}
114
115 } // Lookup
116