1 |
|
---|
2 | package org.nzdl.gsdl.service;
|
---|
3 |
|
---|
4 | import java.util.*;
|
---|
5 |
|
---|
6 | import org.nzdl.gsdl.service.*;
|
---|
7 | import org.nzdl.gsdl.corba.gsdlInterface.*;
|
---|
8 | import org.nzdl.gsdl.util.*;
|
---|
9 |
|
---|
10 | public class NzdlResponse extends java.lang.Object {
|
---|
11 |
|
---|
12 | /** */
|
---|
13 |
|
---|
14 | private corbaFilterResponseHolder m_responseHolder = null;
|
---|
15 | private corbaFilterResponse m_response = null;
|
---|
16 | private NzdlResultSet m_resultSet = null;
|
---|
17 | private Map m_frequencies = null;
|
---|
18 | private List m_queryTerms = null;
|
---|
19 |
|
---|
20 | /** */
|
---|
21 |
|
---|
22 | public NzdlResponse( ) {
|
---|
23 | m_responseHolder = NzdlCorbaFactory.createFilterResponseHolder();
|
---|
24 | }
|
---|
25 |
|
---|
26 | public corbaFilterResponseHolder getHolder() {
|
---|
27 | return m_responseHolder;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public NzdlResultSet getResultSet() {
|
---|
31 | if ( m_resultSet == null ) {
|
---|
32 | parseResponse();
|
---|
33 | }
|
---|
34 | return m_resultSet;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /*
|
---|
38 | This is a short expansion of the content of a corbaFilterResponse object.
|
---|
39 | Some of the fields are not that clear to me (those with ?????). Therefore
|
---|
40 | I am ignoring some of them for the time being.
|
---|
41 |
|
---|
42 | o Number of Documents
|
---|
43 | o Type of results
|
---|
44 | o Info on each of the search terms used:
|
---|
45 |
|
---|
46 | o Term string
|
---|
47 | o Term frequency
|
---|
48 | o Matched terms ?????
|
---|
49 |
|
---|
50 | o Info on each of the result docs returned:
|
---|
51 |
|
---|
52 | o Document ID
|
---|
53 | o Result number ?????
|
---|
54 | o Number of terms matched in this document
|
---|
55 | o Number of phrases matched in this document
|
---|
56 | o Array of document frequencies ?????
|
---|
57 | o Info on the metadata:
|
---|
58 |
|
---|
59 | o Array of the names of the meta tags
|
---|
60 | o Info on each of the meta data:
|
---|
61 |
|
---|
62 | o Params string ?????
|
---|
63 | o Is the metadata a reference ?????
|
---|
64 | o Array of values
|
---|
65 | o Id ?????
|
---|
66 | o Parentid ?????
|
---|
67 | */
|
---|
68 |
|
---|
69 | private void parseResponse () {
|
---|
70 | m_response = m_responseHolder.value;
|
---|
71 | m_resultSet = new NzdlResultSet();
|
---|
72 | m_resultSet.setNumOfDocs( m_response.numDocs );
|
---|
73 | m_resultSet.setResultType( m_response.isApprox.value() );
|
---|
74 | /** HAS SIDE EFFECT ! */
|
---|
75 | parseTermsInfo( m_response.termInfo );
|
---|
76 | /** HAS SIDE EFFECT ! */
|
---|
77 | parseDocsInfo( m_response.docInfo );
|
---|
78 | }
|
---|
79 |
|
---|
80 | private void parseTermsInfo( corbaTermInfo [] _termsInfo ) {
|
---|
81 | String term = null;
|
---|
82 | m_frequencies = new HashMap();
|
---|
83 | m_queryTerms = new ArrayList();
|
---|
84 | for (int i=0; i<_termsInfo.length; i++) {
|
---|
85 | term = NzdlCorbaFactory.toString(_termsInfo[i].term);
|
---|
86 | m_queryTerms.add( term );
|
---|
87 | m_frequencies.put( term, new Integer(_termsInfo[i].frequency) );
|
---|
88 | }
|
---|
89 | m_resultSet.setQueryTerms( m_queryTerms );
|
---|
90 | m_resultSet.setTermFrequencies( m_frequencies );
|
---|
91 | }
|
---|
92 |
|
---|
93 | private void parseDocsInfo( corbaResultDocInfo [] _docsInfo ) {
|
---|
94 | NzdlQueryHit queryHit = null;
|
---|
95 | //System.err.println("Size of DocsInfo: " + _docsInfo.length);
|
---|
96 | for (int i=0; i < _docsInfo.length; i++) {
|
---|
97 | queryHit = new NzdlQueryHit();
|
---|
98 | queryHit.setDocumentID( NzdlCorbaFactory.toString(_docsInfo[i].OID) );
|
---|
99 | queryHit.setResultNumber( _docsInfo[i].resultNum );
|
---|
100 | queryHit.setRanking( _docsInfo[i].ranking );
|
---|
101 | queryHit.setNumOfTermsMatched( _docsInfo[i].termsMatched );
|
---|
102 | queryHit.setNumOfPhrasesMatched( _docsInfo[i].phraseMatched );
|
---|
103 | /** TO DO: extract corbaDocFreq_array value */
|
---|
104 | queryHit.setMetaData( parseMetaData(_docsInfo[i].metadata) );
|
---|
105 | // add to the result set
|
---|
106 | m_resultSet.add( queryHit ) ;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | private Map parseMetaData( corbaMetadataInfo_map _metaData ) {
|
---|
111 | /*
|
---|
112 | * The key in the map will be the metaData Tag
|
---|
113 | * The value for the key will be a Set of strings
|
---|
114 | * Ex: key = "Author", value = {A. Mahoui, S. Franks}
|
---|
115 | */
|
---|
116 | Map metaData = new HashMap();
|
---|
117 | // For each meta tag can be associated more than one value (example above)
|
---|
118 | Set metaTagValues = new HashSet();
|
---|
119 | corbaMetadataInfo c_metaDataInfo = null;
|
---|
120 |
|
---|
121 | for (int i=0; i < _metaData.names.length; i++) {
|
---|
122 | // one meta data at a time please ...
|
---|
123 | c_metaDataInfo = _metaData.values[i];
|
---|
124 | // get the set of values associated with this meta tag ...
|
---|
125 | for (int j=0; j < c_metaDataInfo.values.length; j++) {
|
---|
126 | metaTagValues.add( NzdlCorbaFactory.toString(c_metaDataInfo.values[j]) );
|
---|
127 | }
|
---|
128 | // map the meta tag with its set of values ...
|
---|
129 | metaData.put( NzdlCorbaFactory.toString(_metaData.names[i]), metaTagValues);
|
---|
130 | }
|
---|
131 | return metaData;
|
---|
132 | }
|
---|
133 |
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|