Exemplo n.º 1
0
static void load_seg()
{
      clear_seg_label();
      struct anthy_conv_stat acs;
      anthy_get_stat(ac, &acs);
      segN = 0;
      if (acs.nr_segment > 0) {
        char buf[256];
        int i;

        for(i=0; i < acs.nr_segment; i++) {
          anthy_get_segment(ac, i, 0, buf, sizeof(buf));

          seg[i].selidx = 0;
          gtk_label_set_text(GTK_LABEL(seg[i].label), buf);

          struct anthy_segment_stat ss;
          anthy_get_segment_stat(ac, i, &ss);

          seg[i].selN = ss.nr_candidate;
          segN++;
        }

        state=STATE_CONVERT;
//        cursor = 0;
        if (cursor >= acs.nr_segment)
          cursor = acs.nr_segment - 1;
        disp_convert();
      }
      keysN=0;
}
Exemplo n.º 2
0
void
Conversion::select_segment (int segment_id)
{
    if (!is_converting ()) return;

    if (segment_id < 0) {
        m_cur_segment = -1;
        m_anthy.reset_cursor(0);
        return;
    }

    struct anthy_conv_stat conv_stat;
    anthy_get_stat (m_anthy_context, &conv_stat);

    int real_segment_id = segment_id + m_start_id;

    if (segment_id >= 0 && real_segment_id < conv_stat.nr_segment) {
        if (m_cur_segment != segment_id) {
            if (segment_id < m_segments.size()) {
                m_anthy.reset_cursor(m_segments[segment_id].get_candidate_id());
            }
            m_cur_segment = segment_id;
        }
    }
}
Exemplo n.º 3
0
int main(int argc,char **argv){
	if(anthy_init()) {
		printf("anthy_init() is failed.\n");
		return 1;
	}
	anthy_set_personality("");
	ac = anthy_create_context();
	if(!ac) {
		printf("anthy_create_context() is failed.\n");
		return 1;
	}
	//準備完了!
	for(k=0; k<1000; k++){
	  anthy_set_string(ac, "わたしのなまえはおくのです。");
	  //anthy_commit_segment(ac);
	  anthy_get_stat(ac, &cs);
	  //printf("segment:%d\n",cs.nr_segment);
	  for(i=0; i<cs.nr_segment; i++){
	    struct anthy_segment_stat ss;
	    anthy_get_segment_stat(ac,i,&ss);
	    //printf("can:%d,len:%d |", ss.nr_candidate, ss.seg_len);
	    for(j=0; j<ss.nr_candidate; j++){
	      char buffer[256];
	      anthy_get_segment(ac,i,j,buffer,256);
	      //printf(" %s ", buffer);
	    }
	    //printf("\n");
	  }
	  //printf("\n");
	  //anthy_print_context(ac);
	}
	anthy_release_context(ac);
	anthy_quit();
	return 0;
}
Exemplo n.º 4
0
void toHira(char* str) {
    int len, cur, isquestion;
    char buf[BUFSIZE];
    struct anthy_conv_stat cs;

    replaceSign(str);
    replaceGrass(str);
    printf("rgr_str:%s\n", str);

    if (anthy_init()) {
        fprintf(stderr, "anthy init error\n");
        abort();
    }

    anthy_context_t ctx = anthy_create_context();

    if (!ctx) {
        fprintf(stderr, "can not create context\n");
        abort();
    }

    anthy_context_set_encoding(ctx, ANTHY_UTF8_ENCODING);

    if (anthy_set_string(ctx, str)) {
        fprintf(stderr, "can not set string\n");
        abort();
    }

    if (anthy_get_stat(ctx, &cs)) {
        fprintf(stderr, "can not get stat\n");
        abort();
    }

    cur = 0;
    for (int i = 0; i < cs.nr_segment; i++) {
        if ((len = anthy_get_segment(ctx, i, NTH_UNCONVERTED_CANDIDATE,
                    buf, BUFSIZE)) == -1) {
            fprintf(stderr, "can not get segment %d\n", i);
            abort();
        }
        if (istalk(buf)) {
            memcpy(str + cur, buf, len);
            cur += len;
        }
        if (i < cs.nr_segment - 1)
            if (i == cs.nr_segment - 3 && isquestion)
                continue;
            else if (i == cs.nr_segment - 2)
                continue;
            else
                str[cur] = '/';
        else
            str[cur] = '\0';
        cur++;
    }

    anthy_release_context(ctx);
}
Exemplo n.º 5
0
//
// segments of the converted sentence
//
int
Conversion::get_nr_segments (void)
{
    if (!is_converting ()) return 0;

    struct anthy_conv_stat conv_stat;
    anthy_get_stat (m_anthy_context, &conv_stat);

    return conv_stat.nr_segment - m_start_id;
}
Exemplo n.º 6
0
void
Conversion::resize_segment (int relative_size, int segment_id)
{
    if (is_predicting ()) return;
    if (!is_converting ()) return;

    struct anthy_conv_stat conv_stat;
    anthy_get_stat (m_anthy_context, &conv_stat);

    int real_segment_id;

    if (segment_id < 0) {
        if (m_cur_segment < 0)
            return;
        else
            segment_id = m_cur_segment;
        real_segment_id = segment_id + m_start_id;
    } else {
        real_segment_id = segment_id + m_start_id;
        if (m_cur_segment > segment_id)
            m_cur_segment = segment_id;
    }

    if (real_segment_id >= conv_stat.nr_segment)
        return;

    // do resize
    anthy_resize_segment (m_anthy_context, real_segment_id, relative_size);

    // reset candidates of trailing segments
    anthy_get_stat (m_anthy_context, &conv_stat);
    ConversionSegments::iterator start_iter = m_segments.begin();
    ConversionSegments::iterator end_iter   = m_segments.end();
    m_segments.erase (start_iter + segment_id, end_iter);
    for (int i = real_segment_id; i < conv_stat.nr_segment; i++) {
        struct anthy_segment_stat seg_stat;
        anthy_get_segment_stat (m_anthy_context, i, &seg_stat);
        m_segments.push_back (
            ConversionSegment (get_segment_string (i - m_start_id, 0), 0,
                               seg_stat.seg_len));
    }
}
Exemplo n.º 7
0
static void
validate_segment_index(anthy_context_t ac, int i)
{
  int err;
  struct anthy_conv_stat cs;

  err = anthy_get_stat(ac, &cs);
  if (err)
    uim_fatal_error("anthy_get_stat() failed");
  if (!(0 <= i && i < cs.nr_segment))
    ERROR_OBJ("invalid segment index", MAKE_INT(i));
}
Exemplo n.º 8
0
//
// starting and finishing
//
void
Conversion::convert (std::string source, CandidateType ctype,
                     bool single_segment)
{
    if (is_converting ())
        return;

    clear ();

    std::string dest;

    // convert
    struct anthy_conv_stat conv_stat;
    anthy_get_stat (m_anthy_context, &conv_stat);
    if (conv_stat.nr_segment <= 0) {
        dest = source;
        anthy_set_string (m_anthy_context, dest.c_str ());
    }

    if (single_segment)
        join_all_segments ();

    // get information about conversion string
    anthy_get_stat (m_anthy_context, &conv_stat);
    if (conv_stat.nr_segment <= 0)
        return;

    // select first segment
    m_cur_segment = 0;

    // create segments
    m_segments.clear();
    for (int i = m_start_id; i < conv_stat.nr_segment; i++) {
        struct anthy_segment_stat seg_stat;
        anthy_get_segment_stat (m_anthy_context, i, &seg_stat);
        m_segments.push_back (
            ConversionSegment (get_segment_string (i, ctype), ctype,
                               seg_stat.seg_len));
    }
}
Exemplo n.º 9
0
static void load_seg()
{
    dbg("load_seg sel_segN:%d\n", sel_segN);
    clear_seg_label();
    struct anthy_conv_stat acs;
    anthy_get_stat(ac, &acs);
    segN = 0;
    if (acs.nr_segment > 0) {
        char buf[256];
        int i;

        int ofs = 0;
        for(i=0; i < acs.nr_segment; i++) {
          struct anthy_segment_stat ss;
          anthy_get_segment_stat(ac, i, &ss);
          int len = ss.seg_len;
          int idx = get_sel_seg_with_ofs(ofs);
          dbg("%d] sel idx:%d ofs:%d\n",i, idx, ofs);
          int selN = seg[i].selN = ss.nr_candidate;

          char *old_str = NULL;
          seg[i].selidx = 0;
          if (idx < sel_segN && sel_seg[idx].len==len) {
            int j;
            for(j=0;j<selN;j++) {
                anthy_get_segment(ac, i, j, buf, sizeof(buf));
                if (!strcmp(buf, sel_seg[idx].sel_str) ) {
                  dbg("old found %s", buf);
                  seg[i].selidx = j;
                  break;
              }
            }
          }

          anthy_get_segment(ac, i, seg[i].selidx, buf, sizeof(buf));
          gtk_label_set_text(GTK_LABEL(seg[i].label), buf);

          dbg("seg len:%d\n", len);
          seg[i].ofs = ofs;
          seg[i].len = len;
          segN++;
          ofs += len;
        }

        state=STATE_CONVERT;
//        cursor = 0;
        if (cursor >= acs.nr_segment)
          cursor = acs.nr_segment - 1;
        disp_convert();
      }
      keysN=0;
}
Exemplo n.º 10
0
static uim_lisp
get_nr_segments(uim_lisp ac_)
{
  anthy_context_t ac;
  struct anthy_conv_stat cs;
  int err;

  ac = get_anthy_context(ac_);
  err = anthy_get_stat(ac, &cs);
  if (err)
    uim_fatal_error("anthy_get_stat() failed");

  return MAKE_INT(cs.nr_segment);
}
Exemplo n.º 11
0
int
Conversion::get_segment_size (int segment_id)
{
    if (!is_converting ()) return -1;

    struct anthy_conv_stat conv_stat;
    anthy_get_stat (m_anthy_context, &conv_stat);

    if (segment_id < 0) {
        if (m_cur_segment < 0)
            return -1;
        else
            segment_id = m_cur_segment;
    }
    int real_segment_id = segment_id + m_start_id;

    if (real_segment_id >= conv_stat.nr_segment)
        return -1;

    struct anthy_segment_stat seg_stat;
    anthy_get_segment_stat (m_anthy_context, real_segment_id, &seg_stat);

    return seg_stat.seg_len;
}
Exemplo n.º 12
0
std::string
Conversion::get_segment_string (int segment_id, int candidate_id)
{
    if (segment_id < 0) {
        if (m_cur_segment < 0)
            return std::string ();
        else
            segment_id = m_cur_segment;
    }

    struct anthy_conv_stat conv_stat;
    anthy_get_stat (m_anthy_context, &conv_stat);

    if (conv_stat.nr_segment <= 0)
        return std::string ();

    if (m_start_id < 0 ||
        m_start_id >= conv_stat.nr_segment)
    {
        return std::string (); // error
    }

    if (segment_id < 0 ||
        segment_id + m_start_id >= conv_stat.nr_segment)
    {
        return std::string (); //error
    }

    // character position of the head of segment.
    unsigned int real_seg_start = 0;
    for (int i = m_start_id; i < m_start_id + segment_id; i++) {
        struct anthy_segment_stat seg_stat;
        anthy_get_segment_stat (m_anthy_context, i, &seg_stat);
        real_seg_start += seg_stat.seg_len;
    }

    int real_seg = segment_id + m_start_id;
    int cand;
    if (candidate_id <= FCITX_ANTHY_LAST_SPECIAL_CANDIDATE)
        cand = m_segments[segment_id].get_candidate_id ();
    else
        cand = candidate_id;

    // get information of this segment
    struct anthy_segment_stat seg_stat;
    anthy_get_segment_stat (m_anthy_context, real_seg, &seg_stat);

    // get string of this segment
    std::string segment_str;
    if (cand < 0) {
        get_reading_substr (segment_str, segment_id, cand,
                            real_seg_start, seg_stat.seg_len);
    } else {
        int len = anthy_get_segment (m_anthy_context, real_seg, cand, NULL, 0);
        if (len > 0) {
            char buf[len + 1];
            anthy_get_segment (m_anthy_context, real_seg, cand, buf, len + 1);
            buf[len] = '\0';
            segment_str = buf;
        }
    }

    return segment_str;
}