1 | /**
|
---|
2 | * ResultDocument.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
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 3 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, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.greenstone;
|
---|
20 |
|
---|
21 | import java.util.HashSet;
|
---|
22 | import java.util.Set;
|
---|
23 | import java.util.Vector;
|
---|
24 |
|
---|
25 | public class ResultDocument {
|
---|
26 | private Vector<String> authors;
|
---|
27 |
|
---|
28 | private Vector<String> keywords;
|
---|
29 |
|
---|
30 | private String title;
|
---|
31 |
|
---|
32 | private String date;
|
---|
33 |
|
---|
34 | private String booktitle;
|
---|
35 |
|
---|
36 | private String pages;
|
---|
37 |
|
---|
38 | private String journal;
|
---|
39 |
|
---|
40 | private String volume;
|
---|
41 |
|
---|
42 | private String number;
|
---|
43 |
|
---|
44 | private String docabstract;
|
---|
45 |
|
---|
46 | private String editor;
|
---|
47 |
|
---|
48 | private String publisher;
|
---|
49 |
|
---|
50 | private int frequencyReturned;
|
---|
51 |
|
---|
52 | private Vector<QueryContext> queryContexts;
|
---|
53 |
|
---|
54 | private Set<String> retrievedMetadata;
|
---|
55 |
|
---|
56 | private double sessionScore;
|
---|
57 |
|
---|
58 | public ResultDocument() {
|
---|
59 | authors = new Vector<String>();
|
---|
60 | keywords = new Vector<String>();
|
---|
61 | title = null;
|
---|
62 | date = null;
|
---|
63 | booktitle = null;
|
---|
64 | pages = null;
|
---|
65 | journal = null;
|
---|
66 | volume = null;
|
---|
67 | number = null;
|
---|
68 | docabstract = null;
|
---|
69 | editor = null;
|
---|
70 | publisher = null;
|
---|
71 | frequencyReturned = 1;
|
---|
72 | sessionScore = 0;
|
---|
73 | queryContexts = new Vector<QueryContext>();
|
---|
74 | retrievedMetadata = new HashSet<String>();
|
---|
75 | }
|
---|
76 |
|
---|
77 | public String toString() {
|
---|
78 | String dump = "Authors\t\t" + authors.toString() + "\n";
|
---|
79 | dump = dump + "Keywords\t" + keywords.toString() + "\n";
|
---|
80 | dump = dump + "Title\t\t" + title + "\n";
|
---|
81 | dump = dump + "Date\t\t" + date + "\n";
|
---|
82 | dump = dump + "Booktitle\t" + booktitle + "\n";
|
---|
83 | dump = dump + "Pages\t\t" + pages + "\n";
|
---|
84 | dump = dump + "Journal\t\t" + journal + "\n";
|
---|
85 | dump = dump + "Volume\t\t" + volume + "\n";
|
---|
86 | dump = dump + "Number\t\t" + number + "\n";
|
---|
87 | dump = dump + "Editor\t\t" + editor + "\n";
|
---|
88 | dump = dump + "Publisher\t" + publisher + "\n";
|
---|
89 | dump = dump + "Frequency\t" + frequencyReturned + "\n";
|
---|
90 | dump = dump + "Abstract\t" + docabstract;
|
---|
91 |
|
---|
92 | for (QueryContext queryContext : queryContexts) {
|
---|
93 | dump = dump + queryContext.toString();
|
---|
94 | }
|
---|
95 | return dump;
|
---|
96 | }
|
---|
97 |
|
---|
98 | public String toDelimitedString(String delimiter) {
|
---|
99 | String dump = "";
|
---|
100 | dump = dump + date + delimiter;
|
---|
101 | if (authors.size() > 0) {
|
---|
102 | dump = dump + authors.elementAt(0) + delimiter;
|
---|
103 | } else {
|
---|
104 | dump = dump + null + delimiter;
|
---|
105 | }
|
---|
106 | if (keywords.size() > 0) {
|
---|
107 | dump = dump + keywords.elementAt(0) + delimiter;
|
---|
108 | } else {
|
---|
109 | dump = dump + null + delimiter;
|
---|
110 | }
|
---|
111 | dump = dump + title + delimiter;
|
---|
112 | dump = dump + booktitle + delimiter;
|
---|
113 | dump = dump + journal + delimiter;
|
---|
114 | dump = dump + volume + delimiter;
|
---|
115 | dump = dump + number + delimiter;
|
---|
116 | dump = dump + editor + delimiter;
|
---|
117 | dump = dump + publisher + delimiter;
|
---|
118 | dump = dump + frequencyReturned;
|
---|
119 | return dump;
|
---|
120 | }
|
---|
121 |
|
---|
122 | public void addAuthor(String author) {
|
---|
123 | this.authors.addElement(author);
|
---|
124 | this.retrievedMetadata.add("Creator");
|
---|
125 | }
|
---|
126 |
|
---|
127 | public void addKeyword(String keyword) {
|
---|
128 | this.keywords.addElement(keyword);
|
---|
129 | this.retrievedMetadata.add("Keywords");
|
---|
130 | }
|
---|
131 |
|
---|
132 | public void setTitle(String title) {
|
---|
133 | this.title = removeHTML(title);
|
---|
134 | this.retrievedMetadata.add("Title");
|
---|
135 | }
|
---|
136 |
|
---|
137 | public void setDate(String date) {
|
---|
138 | this.date = new String(date);
|
---|
139 | this.retrievedMetadata.add("Date");
|
---|
140 | }
|
---|
141 |
|
---|
142 | public void setBooktitle(String booktitle) {
|
---|
143 | this.booktitle = new String(booktitle);
|
---|
144 | this.retrievedMetadata.add("Booktitle");
|
---|
145 | }
|
---|
146 |
|
---|
147 | public void setPages(String pages) {
|
---|
148 | this.pages = new String(pages);
|
---|
149 | this.retrievedMetadata.add("Pages");
|
---|
150 | }
|
---|
151 |
|
---|
152 | public void setJournal(String journal) {
|
---|
153 | this.journal = new String(journal);
|
---|
154 | this.retrievedMetadata.add("Journal");
|
---|
155 | }
|
---|
156 |
|
---|
157 | public void setVolume(String volume) {
|
---|
158 | this.volume = new String(volume);
|
---|
159 | this.retrievedMetadata.add("Volume");
|
---|
160 | }
|
---|
161 |
|
---|
162 | public void setNumber(String number) {
|
---|
163 | this.number = new String(number);
|
---|
164 | this.retrievedMetadata.add("Number");
|
---|
165 | }
|
---|
166 |
|
---|
167 | public void setAbstract(String docabstract) {
|
---|
168 | this.docabstract = new String(docabstract);
|
---|
169 | this.retrievedMetadata.add("Abstract");
|
---|
170 | }
|
---|
171 |
|
---|
172 | public void setEditor(String editor) {
|
---|
173 | this.editor = new String(editor);
|
---|
174 | this.retrievedMetadata.add("Editor");
|
---|
175 | }
|
---|
176 |
|
---|
177 | public void setPublisher(String publisher) {
|
---|
178 | this.publisher = new String(publisher);
|
---|
179 | this.retrievedMetadata.add("Publisher");
|
---|
180 | }
|
---|
181 |
|
---|
182 | public double getSessionScore() {
|
---|
183 | return this.sessionScore;
|
---|
184 | }
|
---|
185 | public void setSessionScore(double s) {
|
---|
186 | this.sessionScore = s;
|
---|
187 | }
|
---|
188 |
|
---|
189 | public void incrementFrequencyReturned() {
|
---|
190 | this.frequencyReturned++;
|
---|
191 | }
|
---|
192 |
|
---|
193 | public void addQueryContext(QueryContext queryContext) {
|
---|
194 | this.queryContexts.addElement(queryContext);
|
---|
195 | if (this.frequencyReturned == 1)
|
---|
196 | this.sessionScore = Double.parseDouble(queryContext.getScore());
|
---|
197 | }
|
---|
198 |
|
---|
199 | public Vector<String> getAuthors() {
|
---|
200 | return authors;
|
---|
201 | }
|
---|
202 |
|
---|
203 | public Vector<String> getAuthor() {
|
---|
204 | return getAuthors();
|
---|
205 | }
|
---|
206 |
|
---|
207 | public Vector<String> getKeywords() {
|
---|
208 | return keywords;
|
---|
209 | }
|
---|
210 |
|
---|
211 | public Vector<String> getKeyword() {
|
---|
212 | return getKeywords();
|
---|
213 | }
|
---|
214 |
|
---|
215 | public String getTitle() {
|
---|
216 | return title;
|
---|
217 | }
|
---|
218 |
|
---|
219 | public String getDate() {
|
---|
220 | return date;
|
---|
221 | }
|
---|
222 |
|
---|
223 | public String getBooktitle() {
|
---|
224 | return booktitle;
|
---|
225 | }
|
---|
226 |
|
---|
227 | public String getPages() {
|
---|
228 | return pages;
|
---|
229 | }
|
---|
230 |
|
---|
231 | public String getJournal() {
|
---|
232 | return journal;
|
---|
233 | }
|
---|
234 |
|
---|
235 | public String getVolume() {
|
---|
236 | return volume;
|
---|
237 | }
|
---|
238 |
|
---|
239 | public String getNumber() {
|
---|
240 | return number;
|
---|
241 | }
|
---|
242 |
|
---|
243 | public String getAbstract() {
|
---|
244 | return docabstract;
|
---|
245 | }
|
---|
246 |
|
---|
247 | public String getEditor() {
|
---|
248 | return editor;
|
---|
249 | }
|
---|
250 |
|
---|
251 | public String getPublisher() {
|
---|
252 | return publisher;
|
---|
253 | }
|
---|
254 |
|
---|
255 | public int getFrequencyReturned() {
|
---|
256 | return frequencyReturned;
|
---|
257 | }
|
---|
258 |
|
---|
259 | public Vector<QueryContext> getQueryContexts() {
|
---|
260 | return this.queryContexts;
|
---|
261 | }
|
---|
262 |
|
---|
263 | public boolean metadataExists(String metadataTag) {
|
---|
264 | return this.retrievedMetadata.contains(metadataTag);
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | protected String removeHTML(String s){
|
---|
269 | return s.replaceAll(""", "\"");
|
---|
270 | }
|
---|
271 |
|
---|
272 | }
|
---|