コード例 #1
0
/** Recursively free a list, if retain_node == 0, the corresponding nodex are
 * also freed.
 */
void pt_list_free(pt_changes_feed_ll handle, int retain_node)
{
  if (!handle) return;
  pt_list_free(handle->next_node, retain_node);
  if (!retain_node) pt_free_node(handle->line); 
  free(handle);
}
コード例 #2
0
/** Perform a loop over the list in the handle, and call the callback function.
 */
void pt_pop_from_list_and_callback(pt_changes_feed handle)                
{
  pt_node_t* anode;
  while (!handle->stop_requested && 
          (anode = pt_pop_from_list(handle))) {   
    if (handle->data_callback) {
      handle->stop_requested = (handle->data_callback(anode) < 0); 
    }
    pt_free_node(anode);                                     
  }
}
コード例 #3
0
//------------------------------------------------
//-- S t a t i c    I m p l e m e n t a t i o n --
//------------------------------------------------
static void conceptualize(m2pp::request& req)
{
  printf("Conceptualize\n");
  //const char* cand = chb_rq_param_get(req,"candidates");
  char* cand = (char* )"Amazon|Apple|Steve Jobs|Google|United States|America|Yahoo|iPhone|iPad";
  char* cand_copy = NULL;

  if (!cand) 
    cand_copy = strdup("");
  else
    cand_copy = strdup(cand);

  SnippetList candidates;
  split_into_vector(candidates,cand_copy);

  ResolvedConceptList concepts;
  __cr->resolve(candidates,concepts);

  pt_node_t* result = pt_array_new();
  for(ResolvedConceptList::const_iterator ii = concepts.begin(); ii != concepts.end(); ii++) {
    resolved_concept_t conc = *ii;
    pt_node_t* entry = pt_map_new();
    pt_map_set(entry,"text_rep", pt_string_new(conc.text_rep));
    pt_map_set(entry,"concept", pt_string_new(conc.canonical));
    pt_map_set(entry,"score", pt_integer_new(conc.score));
    cout << "Concept:" << conc.text_rep << ":" << conc.canonical << ":" << conc.score <<  endl;
    pt_array_push_back(result,entry);
  }

  pt_node_t* payload = pt_map_new();
  pt_map_set(payload,"payload",result);

  char* json_str = pt_to_json(payload,0);
  pt_free_node(payload);

  ReqRes rr;
  rr.req = req;
  rr.res = json_str;

  free(json_str);

  __res_queue.enqueue(rr);
}