rime / librime-predict Goto Github PK
View Code? Open in Web Editor NEWlibrime plugin. predict next word.
License: BSD 3-Clause "New" or "Revised" License
librime plugin. predict next word.
License: BSD 3-Clause "New" or "Revised" License
这个预测的字体只有繁体,即使开了简体也没有用,请问有没有什么办法能让预测的是简体?
作者你好,我用这个库和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)
希望指点
Before integrating this plugin I want to make sure the license is compatible.
请问怎么使用data/sample.txt
的内容生成 predict.db?
使用提供的样例数据文件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)
使用较大的数据文件,似乎又没有问题。可以构建成功,代码显示可能在设置生成文件头信息时发生内存读写错误,看看怎么解决?
各位大神好,请问这个项目现阶段能否正常使用?我现在用的Rime版本是1.9.0,已经按照使用说明将predict.db放到我的用户目录中,也按说明修改了my.schema.yaml,但好像没有任何效果。对此有下面几个问题想请教一下开发此项目的各位大神:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.