GList * ots_get_doc_sections (const OtsArticle * Doc) { GList *li; GList *sections; GString *current_section; unsigned char *utf8_data; size_t line_len = 0; gboolean previous_line_selected = FALSE; sections = NULL; current_section = g_string_new(NULL); for (li = (GList *) Doc->lines; li != NULL; li = li->next) { utf8_data = ots_get_line_text ((OtsSentence *) li->data, TRUE, &line_len); if (line_len) { if (! previous_line_selected) { sections = g_list_append(sections, current_section->str); g_string_free(current_section, FALSE); current_section = g_string_new(NULL); } g_string_append_len(current_section, utf8_data, line_len); previous_line_selected = TRUE; } else { previous_line_selected = FALSE; } g_free (utf8_data); } if( current_section != NULL) { sections = g_list_append(sections, current_section->str); } g_string_free(current_section, FALSE); return sections; }
static void ots_print_line (FILE * stream, const OtsSentence * aLine) { unsigned char *utf8_txt; size_t len = 0; utf8_txt = ots_get_line_text (aLine, TRUE, &len); fwrite (utf8_txt, 1, len, stream); g_free (utf8_txt); }
void ots_article_summary(OtsArticle *article, void *summary) { for (GList *line = article->lines; line != NULL; line = g_list_next(line)) { OtsSentence *sentence = (OtsSentence *)line->data; if (!sentence->selected) continue; size_t size; unsigned char *content = ots_get_line_text(sentence, TRUE, &size); summary_append(summary, content, sentence->score); sentence->selected = FALSE; } }
unsigned char * ots_get_doc_text (const OtsArticle * Doc, size_t * out_len) { GList *li; GString *text; unsigned char *utf8_data; size_t line_len = 0; text = g_string_new (NULL); for (li = (GList *) Doc->lines; li != NULL; li = li->next) { utf8_data = ots_get_line_text ((OtsSentence *) li->data, TRUE, &line_len); g_string_append_len (text, utf8_data, line_len); g_free (utf8_data); } if (out_len) *out_len = text->len; utf8_data = text->str; g_string_free (text, FALSE); return utf8_data; }