Class: OTS::Article
- Inherits:
-
Object
- Object
- OTS::Article
- Defined in:
- ext/ots.c
Instance Method Summary collapse
- #initialize(*args) ⇒ Object constructor
-
#keywords ⇒ Object
how many times have we seen this word in the text?.
- #summarize(options) ⇒ Object
- #topics ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'ext/ots.c', line 36
VALUE article_initialize(int argc, VALUE *argv, VALUE self) {
VALUE text, options, language, dictionary = Qnil;
OtsArticle *article = article_handle(self);
rb_scan_args(argc, argv, "11", &text, &options);
language = rb_str_new2("en");
if (TYPE(text) != T_STRING)
rb_raise(rb_eArgError, "invalid +text+");
if (!NIL_P(options)) {
if (TYPE(options) != T_HASH)
rb_raise(rb_eArgError, "invalid +options+ hash");
dictionary = rb_hash_aref(options, ID2SYM(rb_intern("dictionary")));
language = rb_hash_aref(options, ID2SYM(rb_intern("language")));
}
if (!NIL_P(dictionary))
article_load_dictionary(article, CSTRING(dictionary));
else
article_load_dictionary(article, CSTRING(language));
ots_parse_stream(RSTRING_PTR(text), RSTRING_LEN(text), article);
ots_grade_doc(article);
rb_iv_set(self, "@encoding", (VALUE)rb_enc_get_index(text));
return self;
}
|
Instance Method Details
#keywords ⇒ Object
how many times have we seen this word in the text?
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'ext/ots.c', line 134
VALUE article_keywords(VALUE self) {
OtsArticle *article = article_handle(self);
rb_encoding *encoding = article_encoding(self);
VALUE words = rb_ary_new();
GList* word_ptr = article->ImpWords;
while (word_ptr) {
OtsWordEntry *data = (OtsWordEntry *)word_ptr->data;
if (data && strlen(data->word) > 0)
rb_ary_push(words, rb_enc_str_new2(data->word, encoding));
word_ptr = word_ptr->next;
}
return words;
}
|
#summarize(options) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/ots.c', line 97
VALUE article_summarize(VALUE self, VALUE options) {
VALUE lines, percent;
OtsArticle *article = article_handle(self);
if (TYPE(options) != T_HASH)
rb_raise(rb_eArgError, "expect an options hash");
lines = rb_hash_aref(options, ID2SYM(rb_intern("sentences")));
percent = rb_hash_aref(options, ID2SYM(rb_intern("percent")));
if (NIL_P(lines) && NIL_P(percent))
rb_raise(rb_eArgError, "expect +sentences+ or +percent+");
if (lines != Qnil)
ots_highlight_doc_lines(article, NUM2INT(lines));
else
ots_highlight_doc(article, NUM2INT(percent));
return article_summary(article, article_encoding(self));
}
|
#topics ⇒ Object
118 119 120 121 122 123 124 125 |
# File 'ext/ots.c', line 118
VALUE article_topics(VALUE self) {
OtsArticle *article = article_handle(self);
return
article->title ?
rb_str_split(rb_enc_str_new2(article->title, article_encoding(self)), ",") :
Qnil;
}
|