V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  ShikiSuen  ›  全部回复第 13 页 / 共 48 页
回复总数  960
1 ... 9  10  11  12  13  14  15  16  17  18 ... 48  
@zzxxisme 是这样:这要载入的内容最多也就是十几万行的全字库的读音(虽然用户辞典的内容撑死应该不会超过一千行吧)。因为我后来对这个 vector 引入了排序与去重复的功能(以及对 non-break 型英数空格的支援),所以整个操作仍旧需要在记忆体内完成。这也是为了减少 SSD 的重复读写次数(如果我没搞错的话)。

@IRuNamu 威注音专案在此,目前只有 macOS 版本: https://github.com/ShikiSuen/vChewing-macOS
目前对全字库的支援有些问题,我还在慢慢排查。
@IRuNamu 就佛振對大千並擊注音與台灣慣用普通話漢字讀音的不屑態度,我維護 RIME 才怪。
然后还得防止那些在经过清理后出现的空行被写入档案内:
```cpp
for(int i=0;i<vecEntry.size();i++)
{
if (vecEntry[i].size() != 0) { // 不要理會空行,否則給空行加上 endl 等於再加空行。
// RegEx 處理順序:先將全形空格換成西文空格,然後合併任何意義上的連續空格(包括 tab 等),最後去除每行首尾空格。
vecEntry[i] = regex_replace(vecEntry[i], sedCJKWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedLeadingSpace, "").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedTrailingSpace, "").c_str();
}
if (vecEntry[i].size() != 0) { // 這句得單獨拿出來,不然還是會把經過 RegEx 處理後出現的空行搞到檔案裡。
zfdFormatConsolidatorOutput<<vecEntry[i]<<endl; // 這裡是必須得加上 endl 的,不然所有行都變成一個整合行。
}
}
```
上述脚本还有一个问题:每跑一遍都会让空行倍增。
得让循环部分仅对非空行做处理才行:
```cpp
for(int i=0;i<vecEntry.size();i++)
{
if (vecEntry[i].size() != 0) { // 不要理會空行,否則給空行加上 endl 等於再加空行。
// RegEx 處理順序:先將全形空格換成西文空格,然後合併任何意義上的連續空格(包括 tab 等),最後去除每行首尾空格。
vecEntry[i] = regex_replace(vecEntry[i], sedCJKWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedLeadingSpace, "").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedTrailingSpace, "").c_str();
zfdFormatConsolidatorOutput<<vecEntry[i]<<endl; // 這裡是必須得加上 endl 的,不然所有行都變成一個整合行。
}
}
```
另外,\s 不包含中日韩全形空格,需要补一道前置处理。改过的处理模组如下:
```cpp
regex sedCJKWhiteSpace("\\u3000"), sedWhiteSpace("\\s+"), sedLeadingSpace("^\\s"), sedTrailingSpace("\\s$"); // RegEx 先定義好。
for(int i=0;i<vecEntry.size();i++)
{ // RegEx 處理順序:先將全形空格換成西文空格,然後合併任何意義上的連續空格(包括 tab 等),最後去除每行首尾空格。
vecEntry[i] = regex_replace(vecEntry[i], sedCJKWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedLeadingSpace, "").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedTrailingSpace, "").c_str();
if (hypy) {
// 該功能尚未正式引入。
}
zfdFormatConsolidatorOutput<<vecEntry[i]<<endl;
}
```
@zzxxisme 我重写了逐行处理的版本,倒是成功了。
看来是我今天早上写的版本有别的错误。
```cpp
// FORMAT CONSOLIDATOR. CREDIT: Shiki Suen.
bool LMConsolidator::ConsolidateFormat(const char *path, bool hypy) {
ifstream zfdFormatConsolidatorIncomingStream(path);
vector<string>vecEntry;
while(!zfdFormatConsolidatorIncomingStream.eof())
{
string zfdBuffer;
getline(zfdFormatConsolidatorIncomingStream,zfdBuffer);
vecEntry.push_back(zfdBuffer);
}
ofstream zfdFormatConsolidatorOutput(path); // 這裡是要從頭開始重寫檔案內容,所以不需要「 ios_base::app 」。
// RegEx 先定義好。
regex sedWhiteSpace("\\s+"), sedLeadingSpace("^\\s+"), sedTrailingSpace("\\s+$");
for(int i=0;i<vecEntry.size();i++)
{
vecEntry[i] = regex_replace(vecEntry[i], sedWhiteSpace, " ").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedLeadingSpace, "").c_str();
vecEntry[i] = regex_replace(vecEntry[i], sedTrailingSpace, "").c_str();
if (hypy) {
// 該功能尚未正式引入。
}
zfdFormatConsolidatorOutput<<vecEntry[i]<<endl;
}
zfdFormatConsolidatorOutput.close();
if (zfdFormatConsolidatorOutput.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to write format-consolidated data to the file. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
zfdFormatConsolidatorIncomingStream.close();
if (zfdFormatConsolidatorIncomingStream.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for format-consolidation. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
return true;
} // END: FORMAT CONSOLIDATOR.
```
@zzxxisme ObjCpp 其实就是 C++ 与 Objective C 的缝合怪。
C++ 的东西改 cpp 后缀为 mm 、改 hpp 后缀为 hh 之后就变成了 ObjCpp 。
不过因为 Objective C 本来就支持对象特性,所以 ObjCpp 的知名度并不是很高。
@zzxxisme 逐行处理的话,我今天早上倒是有测试过,问题没有任何改善就是了。
相关的脚本已经被我盖掉了。我现在想想干脆用 swift 写算了。
没想到 Cpp 这语言居然如此麻烦。
@zzxxisme 我改用 ObjCpp 利用 NSString 与 Foundation 内部的正则,却发现整个词库档案的内容被替换成了一个数字。

```cpp
// FORMAT CONSOLIDATOR. CREDIT: Shiki Suen.
bool LMConsolidator::ConsolidateFormat(const char *path, bool hypy) {
stringstream zfdLoadedFileStreamToConsolidateBuff; // 設立字串流。
ifstream zfdFormatConsolidatorIncomingStream(path);
zfdLoadedFileStreamToConsolidateBuff << zfdFormatConsolidatorIncomingStream.rdbuf();
ofstream zfdFormatConsolidatorOutput(path); // 這裡是要從頭開始重寫檔案內容,所以不需要「 ios_base::app 」。

// 下面這幾句用來執行非常複雜的 Regex 取代。
string zfdBufferStringC = zfdLoadedFileStreamToConsolidateBuff.str().c_str();
NSString *zfdBufferString = [NSString stringWithCString:zfdBufferStringC.c_str() encoding:[NSString defaultCStringEncoding]];
zfdBufferString = [zfdBufferString replacingWithPattern:@"[^\\S\\r\\n]+" withTemplate:@" " error:nil]; // Replace consecutive spaces to single spaces.
zfdBufferString = [zfdBufferString replacingWithPattern:@"^\\s" withTemplate:@"" error:nil]; // Initial Spaces in a line.
zfdBufferString = [zfdBufferString replacingWithPattern:@"\\s$" withTemplate:@"" error:nil]; // Trailing Spaces in a line.

// 漢語拼音二式轉注音。
if (hypy) {
// 該功能尚未正式引入。
}

// 最終將取代結果寫入檔案。
zfdFormatConsolidatorOutput << zfdBufferString << std::endl;
zfdFormatConsolidatorOutput.close();
if (zfdFormatConsolidatorOutput.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to write format-consolidated data to the file. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
zfdFormatConsolidatorIncomingStream.close();
if (zfdFormatConsolidatorIncomingStream.fail()) {
syslog(LOG_CONS, "// REPORT: Failed to read lines through the data file for format-consolidation. Insufficient Privileges?\n");
syslog(LOG_CONS, "// DATA FILE: %s", path);
return false;
}
return true;
} // END: FORMAT CONSOLIDATOR.
```
@zzxxisme 我在想「\h 」是否受 C++11 / ObjCpp 11 的支持。
\h 的话,是不会包含 \n 的。
@zzxxisme 我保留\n 是有原因的,因为输入法的用户辞典每个词音定义占一行。
@Inn0Vat10n 谢谢。没注意到居然会有这种情况。
@KuroNekoFan 我确实是威注音输入法的开源专案的维护人。
最近在做新的启发式自订语汇格式统整功能,但正好在正则这一块吃了瘪。
要是 C++ 真不行的话,我就只能用 swift 写这段了。
@zzxxisme 谢谢。程序正常执行了(不卡住了),但 Xcode 编译出来之后我发现我这 txt 档案的内容会被清空。
忘了给出需要 include 的清单了:
```
#include <syslog.h>
#include <stdio.h>
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <regex>
```
2021-08-16 18:57:24 +08:00
回复了 AkideLiu 创建的主题 macOS macOS Bug Sir 11.5.1 外接 eGPU 休眠的时候 crash
我也遇到了。之前 macOS 11.4 就没这个问题。
2021-04-09 20:16:05 +08:00
回复了 warcraft1236 创建的主题 macOS 移动线路下不能 ssh 连接,求帮忙分析
广东移动也是一个德性。
2021-01-27 12:06:38 +08:00
回复了 chitanda 创建的主题 iOS iOS14.4 谨慎升级
迫使用户手机上的应用全部重新下载。
不这样的话,就没藉口除掉那些已经下载到用户手机上的 Parler 应用了。
(这个应用是川粉聚集地,前一段时间被 Apple 强制下架。)
2020-07-30 14:56:26 +08:00
回复了 ShikiSuen 创建的主题 macOS 怎样彻底禁用 Catalina 的 GateKeeper?
@sinopapa 也就是说这个 spctl 关闭指令只能在恢复模式下执行?
2020-07-29 18:19:32 +08:00
回复了 ShikiSuen 创建的主题 macOS 怎样彻底禁用 Catalina 的 GateKeeper?
@sinopapa SIP 關不掉。
忽然发现光是「 spctl --master-disable 」不算,还得「 sudo defaults write /Library/Preferences/com.apple.security GKAutoRearm -bool NO 」,然后必须得重新开机。终于能正常扫插件了。
1 ... 9  10  11  12  13  14  15  16  17  18 ... 48  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   817 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 21ms · UTC 22:20 · PVG 06:20 · LAX 15:20 · JFK 18:20
Developed with CodeLauncher
♥ Do have faith in what you're doing.