Changeset 1296


Ignore:
Timestamp:
2000-07-24T14:10:01+12:00 (24 years ago)
Author:
kjm18
Message:

incorporated default stemMethod to Parse functions, used if stemMethod
not explicitly set in query string

Location:
trunk/gsdl/src/mgpp/text
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/mgpp/text/GSDLQueryParser.cpp

    r1127 r1296  
    2727
    2828static QueryNode *ParseExpression (UCArray::const_iterator &here,
    29                    UCArray::const_iterator end);
     29                   UCArray::const_iterator end,
     30                   int defaultStemMethod);
    3031
    3132static QueryNode *AndAdd (QueryNode *t1, QueryNode *t2) {
     
    6263// and discarded
    6364static QueryNode *ParseBracketExpression (UCArray::const_iterator &here,
    64                       UCArray::const_iterator end) {
     65                      UCArray::const_iterator end,
     66                      int defaultStemMethod) {
    6567  // get everything in the expression
    66   QueryNode *curTree = ParseExpression (here, end);
     68  QueryNode *curTree = ParseExpression (here, end, defaultStemMethod);
    6769 
    6870  // gobble up tokens until a closing bracket is found
     
    9294  UCArray NEAR; SetCStr(NEAR, "NEAR");
    9395  if (near == NEAR) { // no modifier
    94     termNode.startRange = -20;
     96    termNode.startRange = -21;
    9597    termNode.endRange = 20;
    9698  }
     
    104106    }
    105107    cerr <<"size= "<<size<<endl;
    106     termNode.startRange = -1 * size;
     108    termNode.startRange = -1 * (size+1);
    107109    termNode.endRange = size;
    108110  }
     
    110112
    111113}
    112 static unsigned long GetStemMethod(LexEl &el) {
     114static unsigned long GetStemMethod(LexEl &el, int defaultStemMethod) {
    113115  // here expect el to contain some of c,s,i,u
    114   // stem method 0 = i,u  00
    115   // stem method 1 = c,u  01
    116   // stem method 2 = i, s  10
    117   // stem method 3 = c,s  11
    118 
    119   unsigned long stem = 4;
     116  // stem method 0 = c,u  00
     117  // stem method 1 = i,u  01  - default for DL
     118  // stem method 2 = c, s  10
     119  // stem method 3 = i,s  11
     120
     121  unsigned long stem = (unsigned long)defaultStemMethod;
     122     
    120123  UCArray::const_iterator here = el.text.begin();
    121124  UCArray::const_iterator end = el.text.end();
    122125
    123126  unsigned char c1 = *here;
    124   if (c1 == 'c'| c1 == 'i' | c1 == 'u' | c1 == 's')
    125     stem = 0;
    126   else return 4; // incorrect format
     127  if (!(c1 == 'c'| c1 == 'i' | c1 == 'u' | c1 == 's'))
     128    return 4; // incorrect format
    127129 
    128130  here++;
    129131  unsigned char c2 = 'a';
    130   if (here !=end) c2 = *here;
    131    
    132   if (c1 == 'c'|| c2=='c') stem |= 1;
    133   if (c1 == 's'|| c2 == 's') stem |= 2;
     132  if (here !=end) {
     133    c2 = *here;
     134    if (!(c2 == 'c'| c2 == 'i' | c2 == 'u' | c2 == 's'))
     135      return 4; // incorrect format
     136  }
     137 
     138  if (c1 == 'i'|| c2=='i') stem |= 1; // set bit 0 to 1
     139  if (c1 == 'c' || c2 == 'c') stem &=0xe; //set bit 0 to 0
     140  if (c1 == 's'|| c2 == 's') stem |= 2; // set bit 1 to 1
     141  if (c1 == 'u' || c2 =='u') stem &=0xd; // set bit 1 to 0
    134142  cerr << "stem is "<<stem<<endl;
    135143  return stem;
     
    139147static void ParseTermModifiers (UCArray::const_iterator &here,
    140148                UCArray::const_iterator end,
    141                 TermNode &termNode) {
     149                TermNode &termNode,
     150                int defaultStemMethod) {
     151 
     152  termNode.stemMethod = defaultStemMethod;
     153
    142154  LexEl el;
    143155  UCArray::const_iterator oldHere = here;
     
    147159     
    148160    } else if (el.lexType == StemMethodE) {
    149       //  termNode.stemMethod = ParseInt (here, end);
    150       cerr << "in stem method bit"<<endl;
    151161      oldHere = here;
    152162      LexEl stem;
    153163      if (ParseLexEl (here, end, stem) && stem.lexType == TermE) {
    154     termNode.stemMethod = GetStemMethod(stem);
     164    termNode.stemMethod = GetStemMethod(stem, defaultStemMethod);
    155165    if (termNode.stemMethod == 4) { // error so backtrack
    156166      here = oldHere;
     167      termNode.stemMethod = (unsigned long)defaultStemMethod;
    157168    }
    158169      }else here = oldHere; //ignore - wrong syntax
     
    207218// expects starting brackets to have been parsed
    208219static void ParseSquareBrackets(UCArray::const_iterator &here,
    209              UCArray::const_iterator end,
    210              ProxMatchQueryNode *proxNode) {
     220                UCArray::const_iterator end,
     221                ProxMatchQueryNode *proxNode,
     222                int defaultStemMethod) {
    211223
    212224  LexEl el;
     
    215227      TermNode termNode;
    216228      termNode.term = el.text;
    217       ParseTermModifiers (here, end, termNode);
     229      ParseTermModifiers (here, end, termNode, defaultStemMethod);
    218230      proxNode->terms.push_back(termNode);
    219231    }
    220232    else if (el.lexType == CloseSquareBracketE) {
    221233      break;
     234    }
     235    else if (el.lexType == AndOpE) {
     236      // ignore, the words are AND'ed anyway
     237      cerr << "and inside []\n";
     238    }
     239    else if (el.lexType == OrOpE) {
     240      cerr << "or inside []\n";
    222241    }
    223242    else {
    224243      //error
    225       break;
     244      // just ignore for now
     245      cerr <<"bad syntax inside []\n";
    226246    }
    227247  } // while
     
    261281
    262282static QueryNode *ParseTerm (UCArray::const_iterator &here,
    263                  UCArray::const_iterator end) {
     283                 UCArray::const_iterator end,
     284                 int defaultStemMethod) {
    264285  LexEl el;
    265286
     
    268289
    269290  if (el.lexType == OpenBracketE)
    270     return ParseBracketExpression (here, end);
     291    return ParseBracketExpression (here, end, defaultStemMethod);
    271292
    272293  ProxMatchQueryNode *proxNode = new ProxMatchQueryNode;
    273294
    274   // check for a tag
    275   /* if (el.lexType == TagE) {
    276     oldHere = here; // don't backtrack past here
    277     if (!ParseLexEl (here, end, el)) return NULL;
    278     if (el.lexType == TermE) {
    279       proxNode->tagNodePtr = new TagNode;
    280       proxNode->tagNodePtr->tagName = el.text;
    281       if (!ParseLexEl (here, end, el)) return NULL;
    282     }
    283   }
    284   */
    285295  if (el.lexType == TermE || el.lexType == IntegerE) {
    286296    TermNode termNode;
    287297    termNode.term = el.text;
    288     ParseTermModifiers (here, end, termNode);
     298    ParseTermModifiers (here, end, termNode, defaultStemMethod);
    289299    oldHere = here;  // dont backtrack past here
    290300    if (ParseLexEl(here, end, el) && el.lexType == NearOpE) {
    291301      delete proxNode;
    292       proxNode = (ProxMatchQueryNode *)ParseTerm(here, end);
     302      proxNode = (ProxMatchQueryNode *)ParseTerm(here, end, defaultStemMethod);
    293303      SetRangeValues(termNode, el.text);
    294304      proxNode->terms.push_back (termNode);
     
    306316  }
    307317  else if (el.lexType == OpenSquareBracketE) {
    308     ParseSquareBrackets (here, end, proxNode);
     318    ParseSquareBrackets (here, end, proxNode, defaultStemMethod);
    309319    ParseProxModifiers (here, end, proxNode);
    310320    return proxNode;
     
    319329
    320330static QueryNode *ParseExpression (UCArray::const_iterator &here,
    321                    UCArray::const_iterator end) {
     331                   UCArray::const_iterator end,
     332                   int defaultStemMethod) {
    322333  LexEl el;
    323334  QueryNode *curTree = NULL;
     
    330341    el.lexType == QuoteE ||
    331342    el.lexType == IntegerE ) {
    332     //  el.lexType == TagE) { tag at end of term now
     343    //  el.lexType == TagE) { //tag at end of term now
    333344      // some type of term, back track and parse it
    334345      here = oldHere;
    335       curTree = OrAdd (curTree, ParseTerm (here, end));
     346      curTree = OrAdd (curTree, ParseTerm (here, end, defaultStemMethod));
    336347     
    337348    } else if (el.lexType == AndOpE) {
    338       curTree = AndAdd (curTree, ParseTerm (here, end));
     349      curTree = AndAdd (curTree, ParseTerm (here, end, defaultStemMethod));
    339350     
    340351    } else if (el.lexType == OrOpE) {
    341       curTree = OrAdd (curTree, ParseTerm (here, end));
     352      curTree = OrAdd (curTree, ParseTerm (here, end, defaultStemMethod));
    342353     
    343354    } else if (el.lexType == NotOpE) {
    344       curTree = NotAdd (curTree, ParseTerm (here, end));
     355      curTree = NotAdd (curTree, ParseTerm (here, end, defaultStemMethod));
    345356     
    346357    } else if (el.lexType == CloseBracketE) {
     
    357368}
    358369
    359 QueryNode *ParseQuery (const UCArray &queryStr) {
     370QueryNode *ParseQuery (const UCArray &queryStr, int defaultStemMethod) {
    360371  UCArray::const_iterator here = queryStr.begin();
    361372  UCArray::const_iterator end = queryStr.end();
    362   return ParseExpression (here, end);
    363 }
     373  return ParseExpression (here, end, defaultStemMethod);
     374}
  • trunk/gsdl/src/mgpp/text/GSDLQueryParser.h

    r1127 r1296  
    2929
    3030// returns NULL if the query could not be parsed
    31 QueryNode *ParseQuery (const UCArray &queryStr);
     31// defaultStemMethod used to set stemming and casefolding for terms where
     32// its not set explicitly in the query string. THe defaultStemMethod value
     33// should be set using the values from the preferences page
     34QueryNode *ParseQuery (const UCArray &queryStr, int defaultStemMethod);
    3235
    3336#endif
Note: See TracChangeset for help on using the changeset viewer.