1 | /**********************************************************************
|
---|
2 | *
|
---|
3 | * ResultBox.java -- a list of phrases in the Phind java interface
|
---|
4 | *
|
---|
5 | * Copyright 1997-2000 Gordon W. Paynter
|
---|
6 | * Copyright 2000 The New Zealand Digital Library Project
|
---|
7 | *
|
---|
8 | * A component of the Greenstone digital library software
|
---|
9 | * from the New Zealand Digital Library Project at the
|
---|
10 | * University of Waikato, New Zealand.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or modify
|
---|
13 | * it under the terms of the GNU General Public License as published by
|
---|
14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
15 | * (at your option) any later version.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful,
|
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | * GNU General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, write to the Free Software
|
---|
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | *
|
---|
26 | *********************************************************************/
|
---|
27 |
|
---|
28 | /*********************************************************************
|
---|
29 |
|
---|
30 | This class is used in the Phind java applet (Phind.java).
|
---|
31 |
|
---|
32 | A result item object holds the data describing a single line returned from
|
---|
33 | a query to the server. It therefore contains either information describing
|
---|
34 | a phrase or a URL.
|
---|
35 |
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 |
|
---|
39 | public class ResultItem {
|
---|
40 |
|
---|
41 | // There are four kinds of item
|
---|
42 | // 1. a phrase
|
---|
43 | // 2. a document (or URL)
|
---|
44 | // 3. a "get more phrases" marker
|
---|
45 | // 4. a "get more documents" marker
|
---|
46 | // These should possibly be written as subclasses of a ResultItem
|
---|
47 | // superclass, but I cannot be bothered rewriting it for now.
|
---|
48 |
|
---|
49 | final static int phraseItem = 1;
|
---|
50 | final static int morePhrases = 2;
|
---|
51 | final static int documentItem = 3;
|
---|
52 | final static int moreDocuments = 4;
|
---|
53 |
|
---|
54 | // What kind is this item:
|
---|
55 | int kind;
|
---|
56 |
|
---|
57 | // The "rule" is the unique identifier of this item. For a phrase,
|
---|
58 | // this is its "phrase number", and is also stored as a number in
|
---|
59 | // symbol. For a document it is the document's OID (hash) value.
|
---|
60 | String rule;
|
---|
61 | int symbol;
|
---|
62 |
|
---|
63 | // The term frequency of the item
|
---|
64 | int freq;
|
---|
65 |
|
---|
66 | // The document frequency of the item
|
---|
67 | int documents;
|
---|
68 |
|
---|
69 | // Can this item be expanded? ---- obsolete?
|
---|
70 | int expansion;
|
---|
71 |
|
---|
72 | // When the item is a phrase, the text of the item is split into a
|
---|
73 | // prefix, body, and suffix. The body is the search term and the
|
---|
74 | // prefix and suffix the surrounding text in the new phrase.
|
---|
75 | // When the item is a document, its title is stored in the body.
|
---|
76 | String prefix;
|
---|
77 | String body;
|
---|
78 | String suffix;
|
---|
79 |
|
---|
80 |
|
---|
81 | // Create a ResultItem for a phrase
|
---|
82 | ResultItem(String r, String f, String d,
|
---|
83 | String p, String b, String s) {
|
---|
84 |
|
---|
85 | kind = phraseItem;
|
---|
86 | rule = r;
|
---|
87 | symbol = Integer.valueOf(rule).intValue();
|
---|
88 |
|
---|
89 | freq = Integer.valueOf(f).intValue();
|
---|
90 | documents = Integer.valueOf(d).intValue();
|
---|
91 | expansion = 0;
|
---|
92 |
|
---|
93 | prefix = p;
|
---|
94 | body = b;
|
---|
95 | suffix = s;
|
---|
96 |
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | // Create a ResultItem for a document
|
---|
101 | ResultItem(String hash, String title, String df) {
|
---|
102 |
|
---|
103 | kind = documentItem;
|
---|
104 | rule = hash;
|
---|
105 | body = title;
|
---|
106 | documents = Integer.valueOf(df).intValue();
|
---|
107 |
|
---|
108 | // not needed for a document
|
---|
109 | symbol = 0;
|
---|
110 | freq = 0;
|
---|
111 | expansion = 0;
|
---|
112 | prefix = "";
|
---|
113 | suffix = "";
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | // Create an empty ResultItem of a given kind
|
---|
118 | ResultItem(int k, String r) {
|
---|
119 |
|
---|
120 | kind = k;
|
---|
121 |
|
---|
122 | rule = r;
|
---|
123 | symbol = -1;
|
---|
124 |
|
---|
125 | freq = 0;
|
---|
126 | expansion = 0;
|
---|
127 | documents = 0;
|
---|
128 |
|
---|
129 | prefix = "";
|
---|
130 | body = "";
|
---|
131 | suffix = "";
|
---|
132 | }
|
---|
133 |
|
---|
134 | // Return the full phrase described by the item.
|
---|
135 | public String toString() {
|
---|
136 | String result = "";
|
---|
137 | if (!prefix.equals("")) result = prefix.replace(' ', '+') + "+";
|
---|
138 | result += body.replace(' ', '+');
|
---|
139 | if (!suffix.equals("")) result += "+" + suffix.replace(' ', '+');
|
---|
140 | return(result.trim());
|
---|
141 | }
|
---|
142 |
|
---|
143 | // Is the item a phrase?
|
---|
144 | public boolean isPhrase() {
|
---|
145 | return (kind == phraseItem);
|
---|
146 | }
|
---|
147 |
|
---|
148 | // Is the item a document?
|
---|
149 | public boolean isDocument() {
|
---|
150 | return (kind == documentItem);
|
---|
151 | }
|
---|
152 |
|
---|
153 | public boolean isMorePhrases() {
|
---|
154 | return (kind == morePhrases);
|
---|
155 | }
|
---|
156 |
|
---|
157 | public boolean isMoreDocuments() {
|
---|
158 | return (kind == moreDocuments);
|
---|
159 | }
|
---|
160 |
|
---|
161 |
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|