source: trunk/java-client/org/nzdl/gsdl/service/NzdlResultSet.java@ 2108

Last change on this file since 2108 was 2108, checked in by bas6, 23 years ago

Documenting NzdlQuery, NzdlResponse, NzdlResultSet & NzdlServiceServer (removed some extraneous @see comments)

  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
Line 
1/*
2 * NzdlResultSet.java
3 * Copyright (C) 2001 New Zealand Digital Library Project
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.service;
22
23import java.util.*;
24
25/**
26 * An object that holds results extracted from a response by
27 * {@link NzdlResponse#getResultSet() NzdlResponse.getResultSet()}.
28 * Easily interrogated by a user.
29 */
30public class NzdlResultSet extends java.lang.Object {
31
32 private List m_resultSet = null;
33 private int m_numDocs = -1;
34 private int m_resultType = -1;
35 private List m_queryTerms = null;
36 private List m_docIDs = null;
37
38 /* The key is the query term, the value its frequency */
39 private Map m_frequencies = null;
40
41 /*
42 * The key is the docID, the value is the doc corresponding
43 * meta data which is also a Map where the key is the meta tag
44 * and the value is a set of values for that tag
45 */
46 private Map m_docToMetaDataMap = null;
47
48 /**
49 * Creates an empty instance of NzdlResultSet.
50 */
51 public NzdlResultSet() {
52 m_resultSet = new ArrayList();
53 m_docToMetaDataMap = new HashMap();
54 m_docIDs = new ArrayList();
55 }
56
57 /**
58 * Adds a {@link NzdlQueryHit NzdlQueryHit} to a result set.
59 * @param hit - is an instance of NzdlQueryHit.
60 */
61 public void add( NzdlQueryHit _hit ) {
62 m_resultSet.add( _hit ) ;
63 String id = _hit.getDocumentID();
64 m_docIDs.add( id );
65 m_docToMetaDataMap.put( id, _hit.getMetaData() );
66 }
67
68 /**
69 * Sets the number of documents in a NzdlResultSet.
70 * @param num the number of documents in the result set
71 */
72 public void setNumOfDocs( int _num ) {
73 m_numDocs = _num;
74 }
75
76
77 /**
78 * Sets the result type.
79 * @param type an integer representing the result type.
80 */
81 public void setResultType( int _type ) {
82 m_resultType = _type;
83 }
84
85 /**
86 * Sets the Query terms of a NzdlResultSet.
87 * @param terms a list of words within the query string.
88 */
89 public void setQueryTerms( List _terms ) {
90 m_queryTerms = _terms;
91 }
92
93// public void setTermFrequency( String _term, int _freq ) {
94// m_frequencies.put( _term, new Integer(_freq) );
95// }
96
97 /**
98 * Sets the term frequencies within a NzdlResultSet.
99 * @param freqs a map of the term frequencies. The map key is the query term.
100 */
101 public void setTermFrequencies( Map _freqs ) {
102 m_frequencies = _freqs;
103 }
104
105 /**
106 * Returns the number of documents that matched a query. <br>
107 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
108 * {@link NzdlService NzdlService} object has filled the NzdlResponse
109 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
110 * @return The number of documents that matched a query. This is limited
111 * by the maxDocs set in {@link NzdlQuery NzdlQuery}
112 */
113 public int getNumOfDocs() {
114 return m_numDocs;
115 }
116
117 /**
118 * Returns the result type for the NzdlResultSet. <br>
119 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
120 * {@link NzdlService NzdlService} object has filled the NzdlResponse
121 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
122 * @return result type as an integer.
123 */
124 public int getResultType() {
125 return m_resultType;
126 }
127
128 /**
129 * Returns a list of the words within the query string. <br>
130 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
131 * {@link NzdlService NzdlService} object has filled the NzdlResponse
132 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
133 * @return A list of words within the query string.
134 */
135 public List getQueryTerms() {
136 return m_queryTerms;
137 }
138
139 /**
140 * Returns the number of hits for each word within the query string. <br>
141 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
142 * {@link NzdlService NzdlService} object has filled the NzdlResponse
143 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
144 * @return A map of the frequency of each query word. The map key is the query term..
145 */
146 public Map getTermFrequencies() {
147 return m_frequencies;
148 }
149
150// public int getTermFrequency( String _term ) {
151// return ((Integer)m_frequencies.get(_term)).intValue();
152// }
153
154// public List getDocumentIDs() {
155// NzdlQueryHit hit = null;
156// //Set docIDs = new HashSet();
157// List docIDs = new ArrayList();
158// for (ListIterator itr = m_resultSet.listIterator(); itr.hasNext(); ) {
159// hit = (NzdlQueryHit) itr.next();
160// docIDs.add( hit.getDocumentID() );
161// }
162// return docIDs;
163// }
164
165 /**
166 * Returns a list of Document ID's in the NzdlResultSet. <br>
167 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
168 * {@link NzdlService NzdlService} object has filled the NzdlResponse
169 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
170 * @return A list of Document ID's in the NzdlResultSet.
171 */
172 public List getDocumentIDs() {
173 return m_docIDs;
174 }
175
176// public Set getMetaData( String _docID, String _metaTag ) {
177// NzdlQueryHit hit = null;
178// for (ListIterator itr = m_resultSet.listIterator(); itr.hasNext(); ) {
179// hit = (NzdlQueryHit) itr.next();
180// if ( _docID.equals( hit.getDocumentID() ) ) {
181// return hit.getMetaDataValues( _metaTag );
182// }
183// }
184// return null;
185// }
186
187 /**
188 * Returns metatag values for a document. <br>
189 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
190 * {@link NzdlService NzdlService} object has filled the NzdlResponse
191 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
192 * @return A map of metatag values in the specified document. The key
193 * of the map is the metatag field such as Author or Title.
194 */
195 public Set getMetaData( String _docID, String _metaTag ) {
196 Map metaData = (Map) m_docToMetaDataMap.get( _docID );
197 return (Set) metaData.get( _metaTag );
198 }
199
200 /**
201 * Returns all values for a particular metatag in the result set. <br>
202 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
203 * {@link NzdlService NzdlService} object has filled the NzdlResponse
204 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
205 * @param metaTag Descriptive data such as Author, Title or Date.
206 * @return A map of all values for a particular metatag in all documents
207 * in the NzdlResultSet. The map key is document ID.
208 */
209 public Map getMetaData( String _metaTag ) {
210 Map metaData = new HashMap();
211 for (ListIterator itr = m_resultSet.listIterator(); itr.hasNext(); ) {
212 NzdlQueryHit hit = (NzdlQueryHit) itr.next();
213 metaData.put( hit.getDocumentID(), hit.getMetaDataValues(_metaTag) );
214 }
215 return metaData;
216 }
217
218 /**
219 * Returns all values for all metatags in the result set. <br>
220 * Pre: A {@link NzdlResponse NzdlResponse} object has been created. A
221 * {@link NzdlService NzdlService} object has filled the NzdlResponse
222 * object with results from servicing a {@link NzdlRequest NzdlRequest}.<br>
223 * @return The metatag values for all metatags in all documents
224 * in the NzdlResultSet. The map key is document ID.
225 */
226 public Map getAllMetaData( ) {
227 return m_docToMetaDataMap;
228 }
229
230}
Note: See TracBrowser for help on using the repository browser.