Changeset 29042

Show
Ignore:
Timestamp:
08.05.2014 15:38:11 (5 years ago)
Author:
ak19
Message:

First of 2 part commit for improving FormatConversion? from GS2 to GS3. formatconverter.exe now takes an additional optional parameter which can be documentNode or classifierNode. This then determines what the formatconverter.exe does when it sees an If test on the existence of the numleafdocs variable, since a positive test applies only to classifierNodes, while a negative test applies only to documentNodes. Further, [link][icon][link] should output something slightly different for classifierNodes than for documentNodes.

Location:
main/trunk/greenstone2/runtime-src/src/recpt
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/recpt/formatconverter.cpp

    r28761 r29042  
    4646here" | ./formatconverter --silent 
    4747***********************************************************************/ 
     48void print_usage() { 
     49  cout << endl << "Usage: formatconverter [options]" << endl; 
     50  cout << "\tOptions: --help, [--silent] [--documentNode|--classifierNode]" << endl << endl; 
     51} 
    4852 
    4953int main(int argc, char **argv) { 
     
    5458  text_t resultstring; 
    5559 
    56    
     60  text_t nodeType = ""; 
    5761  bool silent = false; 
     62 
    5863  if(argc > 1) { 
    59     silent = (strcmp(argv[1], "--silent") == 0); 
     64 
     65    if((strcmp(argv[1], "--help") == 0)) { 
     66      print_usage(); 
     67      return 0; 
     68    } 
     69 
     70    else { 
     71      for(int i = 1; i < argc; i++) { 
     72    if (strcmp(argv[i], "--silent") == 0) { silent = true; } 
     73    else if(strcmp(argv[i], "--documentNode") == 0) { nodeType = "document"; }  
     74    else if(strcmp(argv[i], "--classifierNode") == 0) { nodeType = "classifier"; } 
     75    else {  
     76      print_usage();  
     77      return 0; 
     78    } 
     79      } 
     80    } 
    6081  } 
    6182 
     
    7596 
    7697  parse_formatstring (argstr, formatlistptr, metadata, getParents);   
    77   resultstring = get_GS3_formatstring (formatlistptr); 
     98  resultstring = get_GS3_formatstring (formatlistptr, nodeType); 
    7899 
    79100  delete formatlistptr; 
  • main/trunk/greenstone2/runtime-src/src/recpt/formattools.cpp

    r28960 r29042  
    5959                  ostream &logout); 
    6060 
    61 static text_t transform_to_GS3_format (format_t *formatlistptr); 
     61static text_t transform_to_GS3_format (format_t *formatlistptr, const text_t& nodeType); 
    6262 
    6363void metadata_t::clear() { 
     
    21542154} 
    21552155 
    2156 static text_t get_gs3_if (const decision_t &decision, format_t *ifptr, format_t *elseptr) 
     2156static text_t get_gs3_if (const decision_t &decision, format_t *ifptr, format_t *elseptr, const text_t& nodeType) 
    21572157{ 
    21582158  text_t ifstmt ="<gsf:switch>"; 
     
    22152215  text_t if_body = ""; 
    22162216  while(ifptr != NULL) { // body of if can contain a list of items to be transformed into GS3 format stmts 
    2217     if_body += transform_to_GS3_format (ifptr); 
     2217    if_body += transform_to_GS3_format (ifptr, nodeType); 
    22182218    ifptr = ifptr->nextptr; 
    22192219  } 
     
    22272227    text_t else_body = ""; // body of else can contain a list of items to be transformed into GS3 format stmts 
    22282228    while(elseptr != NULL) { 
    2229       else_body += transform_to_GS3_format (elseptr); 
     2229      else_body += transform_to_GS3_format (elseptr, nodeType); 
    22302230      elseptr = elseptr->nextptr; 
    22312231    } 
     
    22392239 
    22402240 
    2241 static text_t get_gs3_or (format_t *orptr) { 
     2241static text_t get_gs3_or (format_t *orptr, const text_t& nodeType) { 
    22422242  text_t result = "<gsf:choose-metadata>"; 
    22432243 
    22442244  while(orptr != NULL) { 
    2245     text_t or_body = transform_to_GS3_format (orptr); 
     2245    text_t or_body = transform_to_GS3_format (orptr, nodeType); 
    22462246    if (!or_body.empty()) { 
    22472247      result += or_body; 
     
    22552255 
    22562256// what about all the <td>? Does that get stored in formatlistptr, such as under the ->text field? 
    2257 text_t get_GS3_formatstring (format_t *formatlistptr) { 
     2257text_t get_GS3_formatstring (format_t *formatlistptr, const text_t& nodeType) { 
    22582258  text_t result; 
    22592259 
    22602260  while (formatlistptr != NULL) { 
    2261     result += transform_to_GS3_format(formatlistptr);     
     2261    result += transform_to_GS3_format(formatlistptr, nodeType);     
    22622262    formatlistptr = formatlistptr->nextptr; 
    22632263  } 
     
    22662266} 
    22672267 
    2268 text_t transform_to_GS3_format (format_t *formatlistptr) { 
    2269  
     2268text_t transform_to_GS3_format (format_t *formatlistptr, const text_t& nodeType) { 
    22702269  if (formatlistptr == NULL) return ""; 
    22712270   
     
    22802279    return formatlistptr->text; // [text]? or any string that is not a command or reserved 
    22812280  case comLink: 
    2282     return "<gsf:link type='document'>"; // type? 
     2281    if(nodeType == "classifier") { 
     2282      return "<gsf:link type='classifier'>"; 
     2283    } else { // if nodeType is document or not set 
     2284      return "<gsf:link type='document'>"; 
     2285    } 
    22832286  case comEndLink: 
    22842287    return "</gsf:link>"; 
     
    22862289    return "<gsf:lib name=\"href\"/>"; // ??? in gslib xsl, output comment marking not sure what this maps to 
    22872290  case comIcon: 
    2288     return "<gsf:icon type='document'/>"; 
     2291    if(nodeType == "classifier") { 
     2292      return "<gsf:icon type='classifier'/>"; 
     2293    } else { // if nodeType is document or not set 
     2294      return "<gsf:icon type='document'/>"; 
     2295    } 
    22892296  case comNum: 
    22902297    return "<gsf:lib name=\"num\"/>"; // ??? in gslib xsl, output comment marking not sure what this maps to 
     
    23352342    break; 
    23362343  case comIf: 
    2337     return get_gs3_if (formatlistptr->decision, formatlistptr->ifptr, formatlistptr->elseptr); 
     2344    if(formatlistptr->decision.meta.metaname == "numleafdocs") { 
     2345      if(nodeType == "classifier") { 
     2346    text_t if_body = ""; 
     2347    while(formatlistptr->ifptr != NULL) { // body of if can contain a list of items to be transformed into GS3 format stmts 
     2348      if_body += transform_to_GS3_format (formatlistptr->ifptr, nodeType); 
     2349      formatlistptr->ifptr = formatlistptr->ifptr->nextptr; 
     2350    } 
     2351    return if_body; 
     2352      } else if(nodeType == "document") { 
     2353    text_t else_body = ""; // body of else can contain a list of items to be transformed into GS3 format stmts 
     2354    while(formatlistptr->elseptr != NULL) { 
     2355      else_body += transform_to_GS3_format (formatlistptr->elseptr, nodeType); 
     2356      formatlistptr->elseptr = formatlistptr->elseptr->nextptr; 
     2357    } 
     2358    return else_body; 
     2359      } 
     2360    } 
     2361     
     2362    // if nodeType not specified as classifier or document, or if the If test is not for numleafdocs' existence 
     2363    return get_gs3_if (formatlistptr->decision, formatlistptr->ifptr, formatlistptr->elseptr, nodeType); 
    23382364  case comOr: 
    2339     return get_gs3_or (formatlistptr->orptr); 
    2340     //return "<gsf:choose-metadata>"+get_gs3_or (formatlistptr->orptr)+"</gsf:choose-metadata>"; 
     2365    return get_gs3_or (formatlistptr->orptr, nodeType); 
     2366    //return "<gsf:choose-metadata>"+get_gs3_or (formatlistptr->orptr, nodeType)+"</gsf:choose-metadata>"; 
    23412367  case comDocTermsFreqTotal: 
    23422368    return "<gsf:lib name=\"DocTermsFreqTotal\"/>"; 
  • main/trunk/greenstone2/runtime-src/src/recpt/formattools.h

    r28760 r29042  
    148148                 ostream& logout); 
    149149 
    150 text_t get_GS3_formatstring (format_t *formatlistptr); 
     150text_t get_GS3_formatstring (format_t *formatlistptr, const text_t& nodetype=""); 
    151151 
    152152#endif