class ELDC::Detector
Public Instance Methods
Source
static VALUE
rb_eldc_detector_m_detect (VALUE self, VALUE text)
{
const char *text_cstr = rb_string_value_cstr (&text);
const char *language = eldc_detect (text_cstr);
return rb_eldc_make_language_value (language);
}
Source
static VALUE
rb_eldc_detector_m_detect_details (VALUE self, VALUE text)
{
const char *text_cstr = rb_string_value_cstr (&text);
EldcDetectResult *result = malloc (sizeof (EldcDetectResult));
eldc_detect_details (text_cstr, result);
return rb_data_typed_object_wrap (rb_cDetectResult, result,
&rb_eldc_detect_result_type);
}
Alias for: set_languages
Source
static VALUE
rb_eldc_detector_m_scheme_set (VALUE self, VALUE scheme)
{
(void)self;
eldc_set_scheme (rb_string_value_cstr (&scheme));
return RUBY_Qnil;
}
Source
static VALUE
rb_eldc_detector_m_scores_set (VALUE self, VALUE scores)
{
eldc_set_scores (rb_num2int_inline (scores));
return RUBY_Qnil;
}
Controls how many top scores will be returned. SCORES is clamped between 1 and ELDC::MAX_SCORES. Default is 3.
Source
static VALUE
rb_eldc_detector_m_languages_set (VALUE self, VALUE languages)
{
(void)self;
VALUE codes_value;
switch (rb_type (languages))
{
case RUBY_T_NIL:
codes_value = RUBY_Qnil;
break;
case RUBY_T_ARRAY:
{
const VALUE *ptr = rb_array_const_ptr (languages);
const long len = rb_array_len (languages);
codes_value = rb_str_new (NULL, 0);
for (long index = 0; index < len; index++)
{
if (index)
rb_str_append (codes_value, rb_str_new_lit (","));
VALUE language = ptr[index];
rb_str_append (codes_value, language);
}
}
break;
default: /* including string */
codes_value = rb_obj_as_string (languages);
}
const char *actual = eldc_set_languages (
RB_NIL_P (codes_value) ? NULL : rb_string_value_cstr (&codes_value));
return rb_str_split (rb_str_new_cstr (actual), ",");
}
Empty-ish value resets languages. If one or more language codes are given, it returns an array of actually applied language code String. The codes which are not applied is printed to the standard error.
Please note that if you writeβ¦
codes = (detector.languages = "LANG1,LANG2")
β¦ then the codes is always "LANG1,LANG2". For checking the returned value, use set_languages instead.
Also aliased as: languages=