Changeset 4209 for trunk/gsdl/src/mgpp/text/GSDLQueryParser.cpp
- Timestamp:
- 2003-05-01T10:58:25+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/mgpp/text/GSDLQueryParser.cpp
r3165 r4209 26 26 static QueryNode *ParseExpression (UCArray::const_iterator &here, 27 27 UCArray::const_iterator end, 28 int defaultBoolC Ombine,28 int defaultBoolCombine, 29 29 int defaultStemMethod); 30 30 … … 95 95 UCArray NEARBY; SetCStr(NEARBY, "NEAR"); 96 96 if (nearby == NEARBY) { // no modifier 97 termNode.startRange = -21; 98 termNode.endRange = 20; 97 termNode.startRange = (NEAR_DEFAULT+1)*-1; 98 termNode.endRange = NEAR_DEFAULT; 99 99 100 } 100 101 else { // extract number … … 215 216 216 217 // expects starting brackets to have been parsed 218 // sets error to true if something has gone wrong 217 219 static void ParseSquareBrackets(UCArray::const_iterator &here, 218 220 UCArray::const_iterator end, 219 221 ProxMatchQueryNode *proxNode, 220 int defaultStemMethod) { 222 int defaultStemMethod, 223 bool & error) { 221 224 222 225 LexEl el; … … 240 243 break; 241 244 } 242 else if (el.lexType == AndOpE) {243 // ignore, the words are AND'ed anyway244 cerr << "and inside []\n";245 }246 else if (el.lexType == OrOpE) {247 cerr << "or inside []\n";248 }249 245 else if (el.lexType == QuoteE) { 250 246 // phrase inside square brackets … … 253 249 } 254 250 else { 255 //error 256 // just ignore for now 257 cerr <<"bad syntax inside []\n"; 251 //error - we set the proxNode to NULL, 252 cerr <<"GSDLQueryParser: bad syntax inside []\n"; 253 error = true; 254 return; 258 255 } 259 256 } // while … … 267 264 UCArray::const_iterator end, 268 265 ProxMatchQueryNode &proxNode, 269 int defaultStemMethod) { 266 int defaultStemMethod, 267 bool &error) { 270 268 LexEl el; 271 269 bool first = true; … … 289 287 290 288 } else { 291 // error 292 break; 289 // error 290 error = true; 291 return; 293 292 } 294 293 } … … 316 315 oldHere = here; // dont backtrack past here 317 316 if (ParseLexEl(here, end, el) && el.lexType == NearOpE) { 318 delete proxNode; 317 delete proxNode; 318 oldHere = here; 319 // this is calling ParseTerm again, but only a subset of the things accepted by ParseTerm are appropriate here. add in some hacks to avoid segmentation faults - kjdon, 04/2003 320 321 // if the next element is a '(' have a syntax error, return NULL 322 LexEl temp_el; 323 if (ParseLexEl(here, end, temp_el) && temp_el.lexType == OpenBracketE) { 324 cerr << "GSDLQueryParser: NEAR cannot be followed by a '('\n"; 325 return NULL; 326 } 327 here = oldHere; // else backtrack 328 319 329 proxNode = (ProxMatchQueryNode *)ParseTerm(here, end, defaultBoolCombine, 320 330 defaultStemMethod); … … 322 332 proxNode->terms.push_back (termNode); 323 333 return proxNode; 324 }325 else {334 335 } else { 326 336 here = oldHere; // backtrack 327 337 proxNode->terms.push_back (termNode); … … 330 340 } 331 341 } else if (el.lexType == QuoteE) { 332 ParsePhrase (here, end, *proxNode, defaultStemMethod); 342 bool error = false; 343 ParsePhrase (here, end, *proxNode, defaultStemMethod, error); 344 if (error) { 345 delete proxNode; 346 return NULL; 347 } 333 348 return proxNode; 334 349 } 335 350 else if (el.lexType == OpenSquareBracketE) { 336 ParseSquareBrackets (here, end, proxNode, defaultStemMethod); 351 bool error = false; 352 ParseSquareBrackets (here, end, proxNode, defaultStemMethod, error); 353 if (error) { 354 delete proxNode; 355 return NULL; 356 } 337 357 ParseProxModifiers (here, end, proxNode); 338 358 return proxNode; … … 352 372 LexEl el; 353 373 QueryNode *curTree = NULL; 354 355 374 UCArray::const_iterator oldHere = here; 356 375 while (ParseLexEl (here, end, el)) { 357 if (el.lexType == OpenSquareBracketE || 358 el.lexType == OpenBracketE || 359 el.lexType == TermE || 360 el.lexType == QuoteE || 361 el.lexType == IntegerE ) { 362 // el.lexType == TagE) { //tag at end of term now 363 // some type of term, back track and parse it 364 here = oldHere; 365 // if default==1, AND, else if==0, OR 366 if (defaultBoolCombine) { 367 curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 368 defaultStemMethod)); 369 } 370 else { 371 curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 372 defaultStemMethod)); 373 } 374 375 } else if (el.lexType == AndOpE) { 376 curTree = AndAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 377 defaultStemMethod)); 378 379 } else if (el.lexType == OrOpE) { 380 curTree = OrAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 381 defaultStemMethod)); 382 383 } else if (el.lexType == NotOpE) { 384 curTree = NotAdd (curTree, ParseTerm (here, end, defaultBoolCombine, 385 defaultStemMethod)); 386 387 } else if (el.lexType == CloseBracketE) { 376 if (el.lexType == CloseBracketE) { 388 377 // parsebracketexpression is waiting for the last bracket, so put it back 389 378 here = oldHere; 390 379 break; 391 392 } else break; 393 380 381 } else if (el.lexType == OpenSquareBracketE || 382 el.lexType == OpenBracketE || 383 el.lexType == TermE || 384 el.lexType == QuoteE || 385 el.lexType == IntegerE ) { 386 387 // some type of term, back track and parse it 388 here = oldHere; 389 390 // parse the term 391 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 392 defaultStemMethod); 393 if (newTerm == NULL) { 394 delete curTree; 395 return NULL; 396 } 397 398 // if default==1, AND, else if==0, OR 399 if (defaultBoolCombine) { 400 curTree = AndAdd (curTree, newTerm); 401 } 402 else { 403 curTree = OrAdd (curTree, newTerm); 404 } 405 406 } else if (el.lexType == AndOpE) { 407 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 408 defaultStemMethod); 409 if (newTerm == NULL) { 410 delete curTree; 411 return NULL; 412 } 413 curTree = AndAdd (curTree, newTerm); 414 415 } else if (el.lexType == OrOpE) { 416 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 417 defaultStemMethod); 418 if (newTerm == NULL) { 419 delete curTree; 420 return NULL; 421 } 422 curTree = OrAdd (curTree, newTerm); 423 424 } else if (el.lexType == NotOpE) { 425 QueryNode * newTerm = ParseTerm (here, end, defaultBoolCombine, 426 defaultStemMethod); 427 if (newTerm == NULL) { 428 delete curTree; 429 return NULL; 430 } 431 curTree = NotAdd (curTree, newTerm); 432 433 } else { 434 435 // syntax error, return NUll 436 delete curTree; 437 return NULL; 438 } 439 394 440 oldHere = here; 395 441 }
Note:
See TracChangeset
for help on using the changeset viewer.