Changeset 16004

Show
Ignore:
Timestamp:
13.06.2008 15:22:38 (12 years ago)
Author:
mdewsnip
Message:

(Adding dynamic classifiers) Moved some common code out of output_top_level_page() and output_internal_page() into a new process_metadata_values() function, in preparation for adding special date support.

Location:
gsdl/trunk/src/recpt
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/src/recpt/dynamicclassifieraction.cpp

    r15999 r16004  
    155155  // The metadata element to classify by should be left after all the options have been parsed off 
    156156  classifier_options["metadata_element_name"] = classifier_specification; 
     157  classifier_options["current_position"] = args["dcn"]; 
    157158 
    158159  // Output the "<ID>Header" format statement if there is one 
     
    193194  get_metadata_values (metadata_element_name, "", args["c"], collectproto, metadata_values_response, logout); 
    194195 
    195   // Deal with any hierarchical metadata values 
    196   map<text_t, int, lttext_t> classifier_nodes; 
    197   ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin(); 
    198   while (metadata_value_iterator != metadata_values_response.docInfo.end()) 
    199   { 
     196  // After processing any hierarchical metadata values, we're left with the top-level classifer nodes 
     197  map<text_t, int, lttext_t> classifier_nodes = process_metadata_values (classifier_options, metadata_values_response.docInfo); 
     198 
     199  // Display the top-level classifier nodes 
     200  map<text_t, int, lttext_t>::iterator classifier_nodes_iterator = classifier_nodes.begin(); 
     201  while (classifier_nodes_iterator != classifier_nodes.end()) 
     202  { 
     203    text_t classifier_node_OID = (*classifier_nodes_iterator).first; 
     204    text_t classifier_node_label = (*classifier_nodes_iterator).first; 
     205    int classifier_node_numleafdocs = (*classifier_nodes_iterator).second; 
     206    output_classifier_node (classifier_node_OID, classifier_node_label, classifier_node_numleafdocs, 0, args, collectproto, browsers, disp, outconvert, textout, logout); 
     207    classifier_nodes_iterator++; 
     208  } 
     209} 
     210 
     211 
     212void dynamicclassifieraction::output_internal_page (text_tmap classifier_options, cgiargsclass &args, 
     213                            recptproto *collectproto, browsermapclass *browsers, 
     214                            displayclass &disp, outconvertclass &outconvert, 
     215                            ostream &textout, ostream &logout) 
     216{ 
     217  text_t arg_dcn = args["dcn"]; 
     218  text_t classifier_node_OID = arg_dcn; 
     219  text_t classifier_node_metadata_value = arg_dcn; 
     220  int node_indent = 0; 
     221 
     222  // Get all the classifier nodes at this level 
     223  text_t metadata_element_name = classifier_options["metadata_element_name"]; 
     224  text_t metadata_value_filter = classifier_node_metadata_value + "|*"; 
     225  FilterResponse_t metadata_values_response; 
     226  get_metadata_values (metadata_element_name, metadata_value_filter, args["c"], collectproto, metadata_values_response, logout); 
     227 
     228  // Get all the documents at this level 
     229  FilterResponse_t document_OIDs_response; 
     230  get_documents_with_metadata_value (metadata_element_name, classifier_node_metadata_value, "dls.Title", args["c"], collectproto, document_OIDs_response, logout); 
     231 
     232  // Check there are some classifier nodes or some documents at this level, otherwise the "dcn" argument was invalid 
     233  if (metadata_values_response.docInfo.empty() && document_OIDs_response.docInfo.empty()) 
     234  { 
     235    textout << outconvert << disp << "Error: Invalid dcn value \"" << arg_dcn << "\".\n"; 
     236    return; 
     237  } 
     238 
     239  // Determine the parent classifier nodes 
     240  text_tarray parent_classifier_node_labels; 
     241  splitchar(classifier_node_OID.begin(), classifier_node_OID.end(), '|', parent_classifier_node_labels); 
     242  text_t classifier_node_label = parent_classifier_node_labels.back(); 
     243  parent_classifier_node_labels.pop_back(); 
     244 
     245  // Display the parent classifier nodes 
     246  text_t parent_classifier_node_OID = ""; 
     247  text_tarray::iterator parent_classifier_node_labels_iterator = parent_classifier_node_labels.begin(); 
     248  while (parent_classifier_node_labels_iterator != parent_classifier_node_labels.end()) 
     249  { 
     250    parent_classifier_node_OID += (parent_classifier_node_OID != "" ? "|" : ""); 
     251    parent_classifier_node_OID += *parent_classifier_node_labels_iterator; 
     252    text_t parent_classifier_node_label = *parent_classifier_node_labels_iterator; 
     253    text_t parent_classifier_node_numleafdocs = "?";  // We can't determine this without more database requests 
     254    output_classifier_node (parent_classifier_node_OID, parent_classifier_node_label, parent_classifier_node_numleafdocs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
     255    node_indent++; 
     256 
     257    parent_classifier_node_labels_iterator++; 
     258  } 
     259 
     260  // Display the selected classifier node 
     261  int classifier_node_numleafdocs = metadata_values_response.docInfo.size() + document_OIDs_response.docInfo.size(); 
     262  output_classifier_node (classifier_node_OID, classifier_node_label, classifier_node_numleafdocs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
     263  node_indent++; 
     264 
     265  // After processing any hierarchical metadata values, we're left with the child classifer nodes 
     266  map<text_t, int, lttext_t> child_classifier_nodes = process_metadata_values (classifier_options, metadata_values_response.docInfo); 
     267 
     268  // Display the child classifier nodes 
     269  map<text_t, int, lttext_t>::iterator child_classifier_nodes_iterator = child_classifier_nodes.begin(); 
     270  while (child_classifier_nodes_iterator != child_classifier_nodes.end()) 
     271  { 
     272    text_t child_classifier_node_OID = classifier_node_OID + "|" + (*child_classifier_nodes_iterator).first; 
     273    text_t child_classifier_node_label = (*child_classifier_nodes_iterator).first; 
     274    int child_classifier_node_numleafdocs = (*child_classifier_nodes_iterator).second; 
     275    output_classifier_node (child_classifier_node_OID, child_classifier_node_label, child_classifier_node_numleafdocs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
     276    child_classifier_nodes_iterator++; 
     277  } 
     278 
     279  // Display the documents at this level 
     280  text_tarray document_OIDs; 
     281  ResultDocInfo_tarray::iterator document_OID_iterator = document_OIDs_response.docInfo.begin(); 
     282  while (document_OID_iterator != document_OIDs_response.docInfo.end()) 
     283  { 
     284    document_OIDs.push_back ((*document_OID_iterator).OID); 
     285    document_OID_iterator++; 
     286  } 
     287 
     288  output_document_nodes (document_OIDs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
     289} 
     290 
     291 
     292map<text_t, int, lttext_t> dynamicclassifieraction::process_metadata_values (text_tmap classifier_options, 
     293                                         ResultDocInfo_tarray metadata_values) 
     294{ 
     295  map<text_t, int, lttext_t> metadata_values_grouped; 
     296 
     297  text_t current_position = classifier_options["current_position"]; 
     298  ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values.begin(); 
     299  while (metadata_value_iterator != metadata_values.end()) 
     300  { 
     301    text_t metadata_value = (*metadata_value_iterator).OID; 
     302 
     303    // If we're not at the top-level we need to remove the current position from the metadata values 
     304    if (current_position != "" && starts_with(metadata_value, current_position + "|")) 
     305    { 
     306      metadata_value = substr(metadata_value.begin() + (current_position + "|").size(), metadata_value.end()); 
     307    } 
     308 
    200309    // Is this metadata value hierarchical? 
    201     text_t metadata_value = (*metadata_value_iterator).OID; 
    202310    text_t::iterator hierarchy_split_position = findchar(metadata_value.begin(), metadata_value.end(), '|'); 
    203311    if (hierarchy_split_position != metadata_value.end()) 
     
    208316 
    209317    // Create a node for this metadata value if we haven't seen it before 
    210     if (classifier_nodes.find(metadata_value) == classifier_nodes.end()) 
     318    if (metadata_values_grouped.find(metadata_value) == metadata_values_grouped.end()) 
    211319    { 
    212       classifier_nodes[metadata_value] = 0; 
     320      metadata_values_grouped[metadata_value] = 0; 
    213321    } 
    214322 
    215323    // Increment the occurrence count 
    216     classifier_nodes[metadata_value] += (*metadata_value_iterator).result_num; 
     324    metadata_values_grouped[metadata_value] += (*metadata_value_iterator).result_num; 
    217325 
    218326    metadata_value_iterator++; 
    219327  } 
    220328 
    221   // Display the top-level classifier nodes 
    222   map<text_t, int, lttext_t>::iterator classifier_nodes_iterator = classifier_nodes.begin(); 
    223   while (classifier_nodes_iterator != classifier_nodes.end()) 
    224   { 
    225     text_t classifier_node_OID = (*classifier_nodes_iterator).first; 
    226     text_t classifier_node_label = (*classifier_nodes_iterator).first; 
    227     int classifier_node_numleafdocs = (*classifier_nodes_iterator).second; 
    228     output_classifier_node (classifier_node_OID, classifier_node_label, classifier_node_numleafdocs, 0, args, collectproto, browsers, disp, outconvert, textout, logout); 
    229     classifier_nodes_iterator++; 
    230   } 
    231 } 
    232  
    233  
    234 void dynamicclassifieraction::output_internal_page (text_tmap classifier_options, cgiargsclass &args, 
    235                             recptproto *collectproto, browsermapclass *browsers, 
    236                             displayclass &disp, outconvertclass &outconvert, 
    237                             ostream &textout, ostream &logout) 
    238 { 
    239   text_t arg_dcn = args["dcn"]; 
    240   text_t classifier_node_OID = arg_dcn; 
    241   text_t classifier_node_metadata_value = arg_dcn; 
    242   int node_indent = 0; 
    243  
    244   // Get all the classifier nodes at this level 
    245   text_t metadata_element_name = classifier_options["metadata_element_name"]; 
    246   text_t metadata_value_filter = classifier_node_metadata_value + "|*"; 
    247   FilterResponse_t metadata_values_response; 
    248   get_metadata_values (metadata_element_name, metadata_value_filter, args["c"], collectproto, metadata_values_response, logout); 
    249  
    250   // Get all the documents at this level 
    251   FilterResponse_t document_OIDs_response; 
    252   get_documents_with_metadata_value (metadata_element_name, classifier_node_metadata_value, "dls.Title", args["c"], collectproto, document_OIDs_response, logout); 
    253  
    254   // Check there are some classifier nodes or some documents at this level, otherwise the "dcn" argument was invalid 
    255   if (metadata_values_response.docInfo.empty() && document_OIDs_response.docInfo.empty()) 
    256   { 
    257     textout << outconvert << disp << "Error: Invalid dcn value \"" << arg_dcn << "\".\n"; 
    258     return; 
    259   } 
    260  
    261   // Determine the parent classifier nodes 
    262   text_tarray parent_classifier_node_labels; 
    263   splitchar(classifier_node_OID.begin(), classifier_node_OID.end(), '|', parent_classifier_node_labels); 
    264   text_t classifier_node_label = parent_classifier_node_labels.back(); 
    265   parent_classifier_node_labels.pop_back(); 
    266  
    267   // Display the parent classifier nodes 
    268   text_t parent_classifier_node_OID = ""; 
    269   text_tarray::iterator parent_classifier_node_labels_iterator = parent_classifier_node_labels.begin(); 
    270   while (parent_classifier_node_labels_iterator != parent_classifier_node_labels.end()) 
    271   { 
    272     parent_classifier_node_OID += (parent_classifier_node_OID != "" ? "|" : ""); 
    273     parent_classifier_node_OID += *parent_classifier_node_labels_iterator; 
    274     text_t parent_classifier_node_label = *parent_classifier_node_labels_iterator; 
    275     text_t parent_classifier_node_numleafdocs = "?";  // We can't determine this without more database requests 
    276     output_classifier_node (parent_classifier_node_OID, parent_classifier_node_label, parent_classifier_node_numleafdocs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
    277     node_indent++; 
    278  
    279     parent_classifier_node_labels_iterator++; 
    280   } 
    281  
    282   // Display the selected classifier node 
    283   int classifier_node_numleafdocs = metadata_values_response.docInfo.size() + document_OIDs_response.docInfo.size(); 
    284   output_classifier_node (classifier_node_OID, classifier_node_label, classifier_node_numleafdocs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
    285   node_indent++; 
    286  
    287   // Determine the child classifier nodes 
    288   map<text_t, int, lttext_t> child_classifier_nodes; 
    289   ResultDocInfo_tarray::iterator metadata_value_iterator = metadata_values_response.docInfo.begin(); 
    290   while (metadata_value_iterator != metadata_values_response.docInfo.end()) 
    291   { 
    292     text_t metadata_value = (*metadata_value_iterator).OID; 
    293  
    294     // If the classifier is hierarchical we need to remove the current position from the metadata value 
    295     if (starts_with(metadata_value, arg_dcn + "|")) 
    296     { 
    297       metadata_value = substr(metadata_value.begin() + (arg_dcn + "|").size(), metadata_value.end()); 
    298     } 
    299  
    300     // Is this metadata value hierarchical? 
    301     text_t::iterator hierarchy_split_position = findchar(metadata_value.begin(), metadata_value.end(), '|'); 
    302     if (hierarchy_split_position != metadata_value.end()) 
    303     { 
    304       // Yes, so split off the first part of the hierarchy for the classifier node 
    305       metadata_value = substr(metadata_value.begin(), hierarchy_split_position); 
    306     } 
    307  
    308     // Create a node for this metadata value if we haven't seen it before 
    309     if (child_classifier_nodes.find(metadata_value) == child_classifier_nodes.end()) 
    310     { 
    311       child_classifier_nodes[metadata_value] = 0; 
    312     } 
    313  
    314     // Increment the occurrence count 
    315     child_classifier_nodes[metadata_value] += (*metadata_value_iterator).result_num; 
    316  
    317     metadata_value_iterator++; 
    318   } 
    319  
    320   // Display the child classifier nodes 
    321   map<text_t, int, lttext_t>::iterator child_classifier_nodes_iterator = child_classifier_nodes.begin(); 
    322   while (child_classifier_nodes_iterator != child_classifier_nodes.end()) 
    323   { 
    324     text_t child_classifier_node_OID = classifier_node_OID + "|" + (*child_classifier_nodes_iterator).first; 
    325     text_t child_classifier_node_label = (*child_classifier_nodes_iterator).first; 
    326     int child_classifier_node_numleafdocs = (*child_classifier_nodes_iterator).second; 
    327     output_classifier_node (child_classifier_node_OID, child_classifier_node_label, child_classifier_node_numleafdocs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
    328     child_classifier_nodes_iterator++; 
    329   } 
    330  
    331   // Display the documents at this level 
    332   text_tarray document_OIDs; 
    333   ResultDocInfo_tarray::iterator document_OID_iterator = document_OIDs_response.docInfo.begin(); 
    334   while (document_OID_iterator != document_OIDs_response.docInfo.end()) 
    335   { 
    336     document_OIDs.push_back ((*document_OID_iterator).OID); 
    337     document_OID_iterator++; 
    338   } 
    339  
    340   output_document_nodes (document_OIDs, node_indent, args, collectproto, browsers, disp, outconvert, textout, logout); 
     329  return metadata_values_grouped; 
    341330} 
    342331 
  • gsdl/trunk/src/recpt/dynamicclassifieraction.h

    r15999 r16004  
    7373                 ostream &textout, ostream &logout); 
    7474 
     75  map<text_t, int, lttext_t> process_metadata_values (text_tmap classifier_options, 
     76                              ResultDocInfo_tarray metadata_values); 
     77 
    7578  void output_classifier_node (text_t classifier_node_OID, text_t classifier_node_label, 
    7679                   text_t classifier_node_numleafdocs, int classifier_node_indent,