1 /*
2 * Copyright 2006-2008 The FLWOR Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "stdafx.h"
17
18 #include <algorithm> /* for lower_bound() */
19 #include <cstring>
20
21 #include "util/less.h"
22 #include "iso2788.h"
23 #include "diagnostics/assert.h"
24
25 #define eacute "\xC3\xA9"
26 #define uuml "\xC3\xBC"
27
28 using namespace std;
29 using namespace zorba::locale;
30
31 namespace zorba {
32 namespace iso2788 {
33
34 ///////////////////////////////////////////////////////////////////////////////
35
36 struct rel_table_entry {
37 rel_type type;
38 char const *name;
39 };
40
41 struct less_rel_table_entry :
42 binary_function<rel_table_entry const&,rel_table_entry const&,bool>
43 {
less_rel_table_entryzorba::iso2788::less_rel_table_entry44 less_rel_table_entry() { }
operator ()zorba::iso2788::less_rel_table_entry45 result_type operator()( first_argument_type i, second_argument_type j ) {
46 return ::strcmp( i.name, j.name ) < 0;
47 }
48 };
49
50 #define REL_TABLE_END(LANG) \
51 static rel_table_entry const *const rel_table_##LANG##_end = \
52 rel_table_##LANG + \
53 sizeof( rel_table_##LANG ) / sizeof( rel_table_##LANG[0] )
54
55 static rel_table_entry rel_table_de[] = {
56 // This MUST be sorted by name.
57 { USE, "benutzen" },
58 { UF , "benutzt f" uuml "r" },
59 { UF , "bf" },
60 { USE, "bs" },
61 { SN , "d" },
62 { SN , "definition" },
63 { BTG, "oa" },
64 { BT , "ob" },
65 { BT , "oberbegriff" },
66 { BTG, "oberbegriff abstraktionsrelation" },
67 { TT , "sb" },
68 { BTP, "sp" },
69 { TT , "spitzenbegriff" },
70 { NTP, "teilbegriff bestandsrelation" },
71 { NTP, "tp" },
72 { NTG, "ua" },
73 { NT , "ub" },
74 { NT , "unterbegriff" },
75 { NTG, "unterbegriff abstraktionsrelation" },
76 { RT , "vb" },
77 { BTP, "verbandsbegriff bestandsrelation" },
78 { RT , "verwandter begriff" },
79 //{ BTI, /* TODO */ },
80 //{ NTI, /* TODO */ },
81 };
82 REL_TABLE_END(de);
83
84 static rel_table_entry rel_table_en[] = {
85 // This MUST be sorted by name.
86 { BT , "broader term" },
87 { BTG, "broader term generic" },
88 { BTI, "broader term instance" },
89 { BTP, "broader term partitive" },
90 { BT , "bt" },
91 { BTG, "btg" },
92 { BTI, "bti" },
93 { BTP, "btp" },
94 { NT , "narrower term" },
95 { NTG, "narrower term generic" },
96 { NTI, "narrower term instance" },
97 { NTP, "narrower term partitive" },
98 { NT , "nt" },
99 { NTG, "ntg" },
100 { NTI, "nti" },
101 { NTP, "ntp" },
102 { RT , "related term" },
103 { RT , "rt" },
104 { SN , "scope note" },
105 { TT , "top term" },
106 { TT , "tt" },
107 { UF , "uf" },
108 { USE, "use" },
109 { UF , "use for" },
110 };
111 REL_TABLE_END(en);
112
113 static rel_table_entry rel_table_fr[] = {
114 // This MUST be sorted by name.
115 { USE, "em" },
116 { USE, "employer" },
117 { UF , "employ" eacute " pour" },
118 { UF , "ep" },
119 { TT , "mv" },
120 { SN , "ne" },
121 { TT , "nom de la classe la plus g" eacute "n" eacute "ale" },
122 { SN , "note explicative" },
123 { BT , "term g" eacute "n" eacute "rique" },
124 { BTG, "term g" eacute "n" eacute "rique g" eacute "n" eacute "rique" },
125 { BTP, "term g" eacute "n" eacute "rique partitif" },
126 { NT , "terme sp" eacute "cifique" },
127 { NTG, "terme sp" eacute "cifique g" eacute "n" eacute "rique" },
128 { NTP, "terme sp" eacute "cifique partitif" },
129 { BT , "tg" },
130 { BTG, "tgg" },
131 { BTP, "tgp" },
132 { NT , "ts" },
133 { NTG, "tsg" },
134 { NTP, "tsp" },
135 { RT , "va" },
136 { RT , "voir aussi" },
137 //{ BTI, /* TODO */ },
138 //{ NTI, /* TODO */ },
139 };
140 REL_TABLE_END(fr);
141
142 #ifdef LANG
143 # undef LANG
144 #endif
145 #define LANG(CODE) \
146 iso639_1::CODE: \
147 *begin = rel_table_##CODE; \
148 *end = rel_table_##CODE##_end; \
149 return true
150
get_rel_table(iso639_1::type code,rel_table_entry const ** begin,rel_table_entry const ** end)151 static bool get_rel_table( iso639_1::type code, rel_table_entry const **begin,
152 rel_table_entry const **end ) {
153 switch ( code ) {
154 case LANG(de);
155 case LANG(en);
156 case LANG(fr);
157 default:
158 return false;
159 }
160 }
161
162 ///////////////////////////////////////////////////////////////////////////////
163
find_rel(char const * relationship,iso639_1::type lang)164 rel_type find_rel( char const *relationship, iso639_1::type lang ) {
165 typedef pair<rel_table_entry const*,rel_table_entry const*> range_type;
166
167 rel_table_entry const *begin, *end;
168 if ( !get_rel_table( lang, &begin, &end ) ) {
169 begin = rel_table_en;
170 end = rel_table_en_end;
171 }
172
173 rel_table_entry entry_to_find;
174 entry_to_find.name = relationship;
175
176 range_type const result =
177 ::equal_range( begin, end, entry_to_find, less_rel_table_entry() );
178 return result.first == result.second ? unknown : result.first->type;
179 }
180
get_dir(rel_type t)181 rel_dir get_dir( rel_type t ) {
182 switch ( t ) {
183 case BT :
184 case BTG:
185 case BTI:
186 case BTP:
187 case TT :
188 return broader;
189 case NT :
190 case NTG:
191 case NTI:
192 case NTP:
193 return narrower;
194 case RT :
195 case SN :
196 case UF :
197 case USE:
198 case unknown:
199 return neutral;
200 default:
201 ZORBA_ASSERT( false );
202 }
203 }
204
205 ///////////////////////////////////////////////////////////////////////////////
206
207 char const *const string_of[] = {
208 // This MUST be in sorted order.
209 "#UNKNOWN",
210 "bt",
211 "btg",
212 "bti",
213 "btp",
214 "nt",
215 "ntg",
216 "nti",
217 "ntp",
218 "rt",
219 "sn",
220 "tt",
221 "uf",
222 "use",
223 };
224
225 ///////////////////////////////////////////////////////////////////////////////
226
227 } // namespace iso2788
228 } // namespace zorba
229 /* vim:set et sw=2 ts=2: */
230