Git Product home page Git Product logo

librime-predict's Issues

构建预测数据文件时报错

使用提供的样例数据文件sample.txt构建预测数据文件时报错,如下所示:

$ cat sample.txt | ./build_predict pre.db
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0605 21:16:26.009402 3191198 build_predict.cc:25] creating pre.db
I0605 21:16:26.009490 3191198 mapped_file.cc:89] overwriting file 'pre.db'.
I0605 21:16:26.009506 3191198 mapped_file.cc:163] resize file to: 2034
I0605 21:16:26.009568 3191198 mapped_file.cc:104] opening file for read/write access.
I0605 21:16:26.009732 3191198 mapped_file.cc:163] resize file to: 5576
Segmentation fault (core dumped)

使用较大的数据文件,似乎又没有问题。可以构建成功,代码显示可能在设置生成文件头信息时发生内存读写错误,看看怎么解决?

读取数据错误

作者你好,我用这个库和librime链接之后,参考tools/build_predict.cc中的main函数在Android写了一个录入数据的方法,代码如下:

#include <rime/component.h>
#include <rime/registry.h>
#include <rime/service.h>
#include <rime_api.h>
#include <sstream>
#include <fstream>

#include "predictor.h"
#include "predict_db.h"

using namespace rime;

static bool file_exists(const char *fname) noexcept {
    FILE *const fp = fopen(fname, "r");
    if (fp) {
        fclose(fp);
        return true;
    }
    return false;
}

static void read(string file_name, rime::predict::RawData &data) {
    std::ifstream ifs1;
    ifs1.open(file_name);
    string str;
    while (getline(ifs1, str)) {
        std::istringstream ss(str);
        vector<string> words;
        string word;
        while (ss >> word) {
            words.push_back(word);
        }
        rime::predict::RawEntry entry;
        entry.text = words[1];
        entry.weight = std::stof(words[2]);
        data[words[0]].push_back(entry);
    }
    ifs1.close();
}

int init() {
    the<ResourceResolver> dres(Service::instance().CreateDeployedResourceResolver({"predict_db", "", ""}));
    string file_name_build = dres->ResolvePath("predict.db").string();
    if (file_exists(file_name_build.c_str())) {
        LOG(INFO) << "联想词目标文件已存在" << file_name_build;
        return 0;
    }
    the<ResourceResolver> res(Service::instance().CreateResourceResolver({"predict_db", "", ""}));
    string file_name = res->ResolvePath("sample.txt").string();
    if (!file_exists(file_name.c_str())) {
        LOG(ERROR) << "联想词源文件不存在" << file_name;
        return 0;
    }

    rime::predict::RawData data;
    LOG(INFO) << "联想词源文件 " << file_name;
    read(file_name, data);

    PredictDb db(file_name_build);
    LOG(INFO) << "creating " << db.file_name();
    if (!db.Build(data) || !db.Save()) {
        LOG(ERROR) << "failed to build " << db.file_name();
        return 1;
    }
    LOG(INFO) << "created: " << db.file_name();
    return 0;
}

static void rime_predict_initialize() {
    Registry &r = Registry::instance();
    init();
    r.Register("predictor", new PredictorComponent);
}

static void rime_predict_finalize() {
}

RIME_REGISTER_MODULE(predict)

但是在读取数据时候提示错误
image

希望指点

License missing

Before integrating this plugin I want to make sure the license is compatible.

[疑问] 请问此项目现在能否使用?如何使用?

各位大神好,请问这个项目现阶段能否正常使用?我现在用的Rime版本是1.9.0,已经按照使用说明将predict.db放到我的用户目录中,也按说明修改了my.schema.yaml,但好像没有任何效果。对此有下面几个问题想请教一下开发此项目的各位大神:

  • 只需要predict.db文件吗?预发布版附件中还有个predict.txt文件,这个是否都需要复制到用户目录?
  • 使用说明中其它改动全部都是写在my.schema.yaml文件中吗?全部写法都正确无误?我见有时用predictor,有时用prediction?
  • predict.db文件中会不会记录我的个人信息和输入习惯?如果我将我的方案作为项目共享的话,是否须要排除此文件以保护我的隐私?
  • 按照使用说明设置好之后,在使用此预测功能时是否需要按快捷键?还是我输入一个中文词组之后就会自动出现预测选项?
  • 如何验证已经成功加载此插件?

预测结果不支持简体

这个预测的字体只有繁体,即使开了简体也没有用,请问有没有什么办法能让预测的是简体?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.