001 /*
002 * LinearNode.java
003 *
004 * Copyright (c) 2002, The University of Sheffield.
005 *
006 * This file is part of GATE (see http://gate.ac.uk/), and is free
007 * software, licenced under the GNU Library General Public License,
008 * Version 2, June1991.
009 *
010 * A copy of this licence is included in the distribution in the file
011 * licence.html, and is also available at http://gate.ac.uk/gate/licence.html.
012 *
013 * borislav popov 02/2002
014 *
015 */
016 package gate.creole.gazetteer;
017
018
019
020 /**Linear node specifies an entry of the type :
021 * list:major:minor:language */
022 public class LinearNode {
023
024 /** the gazetteer list from the node */
025 private String list;
026 /** the minor type from the node */
027 private String minor;
028 /** the major type from the node */
029 private String major;
030 /** the languages member from the node */
031 private String language;
032
033 /**
034 * Constructs a linear node given its elements
035 * @param aList the gazetteer list file name
036 * @param aMajor the major type
037 * @param aMinor the minor type
038 * @param aLanguage the language(s)
039 */
040 public LinearNode(String aList,String aMajor,String aMinor, String aLanguage) {
041 list = aList;
042 minor = aMinor;
043 major = aMajor;
044 language = aLanguage;
045 } // LinearNode construct
046
047 /**
048 * Parses and create a linear node from a string
049 * @param node the linear node to be parsed
050 * @throws InvalidFormatException
051 */
052 public LinearNode (String node) throws InvalidFormatException {
053 int firstColon = node.indexOf(':');
054 int secondColon = node.indexOf(':', firstColon + 1);
055 int thirdColon = node.indexOf(':', secondColon + 1);
056 if(firstColon == -1){
057 throw new InvalidFormatException("", "Line: " + node);
058 }
059 list = node.substring(0, firstColon);
060
061 if(secondColon == -1){
062 major = node.substring(firstColon + 1);
063 minor = null;
064 language = null;
065 } else {
066 major = node.substring(firstColon + 1, secondColon);
067 if(thirdColon == -1) {
068 minor = node.substring(secondColon + 1);
069 language = null;
070 } else {
071 minor = node.substring(secondColon + 1, thirdColon);
072 language = node.substring(thirdColon + 1);
073 }
074 } // else
075 } // LinearNode concstruct
076
077 /**Get the gazetteer list filename from the node
078 * @return the gazetteer list filename */
079 public String getList() {
080 return list;
081 }
082
083 /**Sets the gazetteer list filename for the node
084 * @param aList the gazetteer list filename*/
085 public void setList(String aList) {
086 list = aList;
087 }
088
089 /** Gets the language of the node (the language is optional)
090 * @return the language of the node */
091 public String getLanguage() {
092 return language;
093 }
094
095 /** Sets the language of the node
096 * @param aLanguage the language of the node */
097 public void setLanguage(String aLanguage) {
098 language = aLanguage;
099 }
100
101 /** Gets the minor type
102 * @return the minor type */
103 public String getMinorType() {
104 return minor;
105 }
106
107 /** Sets the minor type
108 * @return the minor type */
109 public void setMinorType(String minorType) {
110 minor = minorType;
111 }
112
113 /** Gets the major type
114 * @return the major type*/
115 public String getMajorType() {
116 return major;
117 }
118
119 /** Sets the major type
120 * @param majorType the major type */
121 public void setMajorType(String majorType) {
122 major = majorType;
123 }
124
125 /**
126 * Gets the string representation of this node
127 * @return the string representation of this node
128 */
129 public String toString() {
130 String result = list+':'+major;
131
132 if ( (null!=minor) && (0 != minor.length()))
133 result += ':'+minor;
134
135 if ( (null!=language) && (0 != language.length())) {
136 if ((null==minor) || (0 == minor.length()) )
137 result +=':';
138 result += ':'+language;
139 }
140 return result;
141 }
142
143 /**Checks this node vs another one for equality.
144 * @param o another node
145 * @return true if languages,list,major type and minor type match.*/
146 public boolean equals(Object o) {
147 boolean result = false;
148 if ( o instanceof LinearNode ) {
149 LinearNode node = (LinearNode) o;
150 result = true;
151
152 if (null != this.getLanguage())
153 result &= this.getLanguage().equals(node.getLanguage());
154
155 if ( null != this.getList())
156 result &= this.getList().equals(node.getList());
157
158 if ( null!=this.getMajorType())
159 result &= this.getMajorType().equals(node.getMajorType());
160
161 if ( null!= this.getMinorType())
162 result &= this.getMinorType().equals(node.getMinorType());
163 }
164 return result;
165 }
166
167 } // class LinearNode
|