source: trunk/java-client/org/nzdl/gsdl/classification/LibraryOfCongressClassification.java@ 2194

Last change on this file since 2194 was 2194, checked in by say1, 23 years ago

added Library of Congress files

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/*
2 * TODO.java
3 * Copyright (C) 2000 Stuart Yeates
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20// the package we're in
21package org.nzdl.gsdl.classification;
22
23// java standard library classes used
24import java.io.File;
25import java.io.FileInputStream;
26import java.io.FileOutputStream;
27import java.io.IOException;
28import java.io.Serializable;
29import java.lang.Cloneable;
30import java.util.Vector;
31import java.util.Hashtable;
32import java.util.Enumeration;
33import java.util.Properties;
34
35/**
36 * The Library of Congress Classification System
37 *
38 * @author stuart yeates ([email protected])
39 * @version $Revision: 2194 $
40 * @see org.nzdl.gsdl.classification.Classification
41 * @see org.nzdl.gsdl.classification.ClassificationSystem
42 * @see org.nzdl.gsdl.classification.LibraryOfCongressClassification
43 * @see java.io.Serializable
44 * @see java.lang.Cloneable
45 */
46
47/**
48 * A Dewey Decimal Subject Classification Category
49 *
50 * @author stuart yeates ([email protected])
51 * @version $Revision: 2194 $
52 * @see org.nzdl.gsdl.classification.ClassificationSystem
53 * @see java.io.Serializable
54 * @see java.lang.Cloneable
55 * @see
56 */
57public class LibraryOfCongressClassification implements Classification {
58 LibraryOfCongressClassificationSystem system = null;
59 LibraryOfCongressClassification parent = null;
60 String key = null;
61 String value = null;
62 String parentValue = null; // parentValue + " --- " + myValue == value
63 String myValue = null; //
64 Vector subClassifications = null;
65 int level;
66
67 LibraryOfCongressClassification(LibraryOfCongressClassificationSystem system,
68 LibraryOfCongressClassification parent,
69 int level,
70 String key,
71 String value)
72 {
73 this.system = system;
74 this.parent = parent;
75 this.key = key;
76 this.value = value;
77 this.level = level;
78 subClassifications = new Vector();
79 for(int i = 0; i < 10;i++)
80 subClassifications.add(null);
81 }
82
83 boolean add (String key, String value) {
84 if (key.length() < level+1)
85 throw new Error("blarg " + key.length() + " " + level);
86 int next = Integer.parseInt(key.substring(level,level+1));
87 if (subClassifications.elementAt(next) == null) {
88 LibraryOfCongressClassification classification =
89 new LibraryOfCongressClassification(system,
90 this,
91 level+1,
92 key,
93 value);
94 subClassifications.setElementAt(classification,next);
95 return true;
96 } else {
97 LibraryOfCongressClassification classification =
98 (LibraryOfCongressClassification) subClassifications.elementAt(next);
99 return classification.add(key,value);
100 }
101 }
102
103 void clean() {
104 String common = null;
105
106 if (value == null) {
107 for (int i = 0; i < 10; i++){
108 LibraryOfCongressClassification classification =
109 (LibraryOfCongressClassification) subClassifications.elementAt(i);
110 if (classification != null){
111 classification.clean();
112 if (common == null)
113 common = clean (classification.getFullTextualDescription());
114 else {
115 String diff = clean (classification.getFullTextualDescription());
116 int min = Math.min(common.length(),diff.length());
117 StringBuffer com = new StringBuffer(min);
118 int j = 0;
119 for (j = 0; j < min && (diff.charAt(j) == common.charAt(j)); j++){
120 com.append(diff.charAt(j));
121 }
122 common = com.toString();
123 }
124 }
125 }
126 value = common;
127 }
128 if (parent == null)
129 parentValue = "";
130 else
131 parentValue = parent.value;
132 myValue = clean (value.substring(parentValue.length(),value.length()));
133 }
134
135 String clean(String in) {
136 int first = 0;
137 int last = in.length();
138 for (; first < last-1 &&
139 (in.charAt(first) == ' ' ||
140 in.charAt(first) == '-'); first++)
141 ;
142 for (; last > 1 &&
143 (in.charAt(last-1) == ' ' ||
144 in.charAt(last-1) == '-'); last--)
145 ;
146
147 return in.substring(first,last);
148 }
149
150
151 /** What is the textual description of this Classification? */
152 public Classification getClassificationFor(String string) {
153 if (key.length() < level)
154 return this;
155
156 int next = Integer.parseInt(key.substring(level,level+1));
157 if (subClassifications.elementAt(next) == null) {
158 return this;
159 } else {
160 LibraryOfCongressClassification classification =
161 (LibraryOfCongressClassification) subClassifications.elementAt(next);
162 return classification.getClassificationFor(string);
163 }
164 }
165
166 /** What is the textual description of this Classification? */
167 public String getTextualDescription() {
168 return value;
169 }
170 /** Verbose textual description */
171 public String getFullTextualDescription() {
172 if (parent == null)
173 return value;
174 else
175 return parent.getFullTextualDescription() + value;
176 }
177 /** What is the code representing this Classification */
178 public String getLabel() {
179 return key;
180 }
181 /** What System is this Classification part of? */
182 public ClassificationSystem getSystem(){
183 return system;
184 }
185
186 /** Does this Classification contain this sub-Classification? */
187 public boolean contains(Classification instance){
188 return false;
189 }
190 /** What direct sub-Classifications does this Classification have? */
191 public Enumeration getSubClassifications() {
192 return subClassifications.elements();
193 }
194 /** The parent Classification */
195 public Classification getParent() {
196 return parent;
197 }
198
199}
Note: See TracBrowser for help on using the repository browser.