~zorba-coders/zorba/bug_897616

« back to all changes in this revision

Viewing changes to src/runtime/full_text/thesaurus.cpp

Support for user-provided Thesauri using standard Zorba URI Resolver mechanism. Approved: Paul J. Lucas, Matthias Brantner

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
#endif
35
35
#include "thesauri/xqftts_thesaurus.h"
36
36
 
 
37
#include "context/default_url_resolvers.h"
 
38
 
37
39
using namespace std;
38
40
using namespace zorba::locale;
39
41
 
108
110
 
109
111
///////////////////////////////////////////////////////////////////////////////
110
112
 
111
 
ThesaurusProvider::~ThesaurusProvider() {
112
 
  // Out-of-line since it's virtual.
113
 
}
114
 
 
115
 
ThesaurusProvider const& ThesaurusProvider::get_default_provider() {
116
 
  static ThesaurusProvider default_provider;
117
 
  return default_provider;
118
 
}
119
 
 
120
 
Thesaurus::ptr
121
 
ThesaurusProvider::get_thesaurus( zstring const &in_uri,
122
 
                                  iso639_1::type lang )  const {
123
 
  thesaurus_impl::type th_impl;
124
 
  zstring uri;
125
 
  parse_mapping( in_uri, &th_impl, &uri );
126
 
 
127
 
  zstring th_path;
128
 
  switch ( uri::get_scheme( uri ) ) {
 
113
Resource*
 
114
ThesaurusURLResolver::resolveURL( zstring const &url, EntityData const *data ) {
 
115
  if ( data->getKind() != internal::EntityData::THESAURUS )
 
116
    return nullptr;
 
117
  ThesaurusEntityData const *const t_data =
 
118
    dynamic_cast<ThesaurusEntityData const*>( data );
 
119
  iso639_1::type const lang = t_data->getLanguage();
 
120
 
 
121
  thesaurus_impl::type t_impl;
 
122
  zstring mapped_url;
 
123
  parse_mapping( url, &t_impl, &mapped_url );
 
124
 
 
125
  zstring t_path;
 
126
  switch ( uri::get_scheme( mapped_url ) ) {
129
127
    case uri::file:
130
128
    case uri::none:
131
 
      th_path = fs::get_normalized_path( uri );
 
129
      t_path = fs::get_normalized_path( mapped_url );
132
130
      break;
133
131
    default:
134
132
      throw XQUERY_EXCEPTION(
137
135
      );
138
136
  }
139
137
 
140
 
  Thesaurus *result;
141
 
  switch ( th_impl ) {
 
138
  switch ( t_impl ) {
142
139
#   ifdef ZORBA_WITH_FILE_ACCESS
143
140
    case thesaurus_impl::wordnet:
144
 
      result = new wordnet::thesaurus( th_path, lang );
145
 
      break;
 
141
      return new wordnet::thesaurus( t_path, lang );
146
142
#   endif /* ZORBA_WITH_FILE_ACCESS */
147
143
    case thesaurus_impl::xqftts:
148
 
      result = new xqftts::thesaurus( th_path, lang );
149
 
      break;
 
144
      return new xqftts::thesaurus( t_path, lang );
150
145
    default:
151
 
      throw XQUERY_EXCEPTION( err::FTST0018, ERROR_PARAMS( uri ) );
 
146
      throw XQUERY_EXCEPTION( err::FTST0018, ERROR_PARAMS( url ) );
152
147
  }
153
 
  return Thesaurus::ptr( result );
 
148
  return nullptr;
154
149
}
155
150
 
156
151
///////////////////////////////////////////////////////////////////////////////