如何制作 Windows 10 微软拼音格式的词库?

Window 10红石更新后,输入法增加导入「用户自定义短语」功能 [图片] 但是,其并不支持文本词库。 参考下面文章后,我仍然不清楚如何制作微软拼音…
关注者
58
被浏览
124,837
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

其实也没那么难,研究了6个多小时,把百度输入法备份的自定义短语导进来了。除了0020-0023是什么没有搞明白,其他的都清楚了。我得睡一会儿,明天又精力了再回答。

先把代码贴上来

Sub WF()
    Dim N As Long
    Dim TN As Integer
    Dim TB As Byte
    Dim WordCount As Long
    Dim FileLength As Long
    Dim WordLength() As Integer
    Dim WordOrder() As Byte
    Dim WordCode() As String
    Dim WordMean() As String
    Dim StringByte() As Byte
    WordCount = 0
    FileLength = &H40
    Open "I:\My Documents\常用\个人\自定义短语导出1.txt" For Binary As #2
    Seek #2, 3
    WordCount = 0
    Do
        Get #2, , TN
        ReDim Preserve WordOrder(WordCount)
        ReDim Preserve WordLength(WordCount)
        ReDim Preserve WordCode(WordCount)
        ReDim Preserve WordMean(WordCount)
        WordOrder(WordCount) = TN - &H30
        Seek #2, Seek(2) + 2
        I = 0
        Do
            DoEvents
            Get 2, , TB
            If TB = &H3D Then Exit Do
            ReDim Preserve StringByte(I)
            StringByte(I) = TB
            I = I + 1
        Loop
        WordCode(WordCount) = StringByte
        FileLength = FileLength + I + 2
        Do
            Get #2, , TB
        Loop Until TB = &H7D
        Seek 2, Seek(2) + 1
        I = 0
        Do
            DoEvents
            Get #2, , TB
            If TB = &HD Then Exit Do
            ReDim Preserve StringByte(I)
            StringByte(I) = TB
            I = I + 1
        Loop While Seek(2) <= LOF(2)
        WordMean(WordCount) = StringByte
        FileLength = FileLength + I + 2
        FileLength = FileLength + 8
        Seek 2, Seek(2) + 3
        If Seek(2) > LOF(2) Then Exit Do
        WordCount = WordCount + 1
        DoEvents
    Loop
    Close #2
    FileLength = FileLength + (WordCount + 1) * 4
    S = StrConv("mschxudp", vbFromUnicode)
    Open "H:\T" For Binary As #1
    For I = 1 To LenB(S)
        Put #1, , AscB(MidB(S, I, 1))
    Next
    N = 1
    Put #1, , N
    N = &H40
    Put #1, , N
    Put #1, , &H40 + (WordCount + 1) * 4
    Put #1, , FileLength
    Put #1, , WordCount
    N = 0
    For I = 1 To 9
        Put #1, , N
    Next
    N = 0
    For I = 0 To WordCount
        Put #1, , N
        N = N + LenB(WordMean(I)) + LenB(WordCode(I)) + 12
    Next
    N = &H80008
    TB = &H6
    For I = 0 To WordCount
        Put #1, , N
        TN = LenB(WordCode(I)) + 10
        Put #1, , TN
        Put #1, , WordOrder(I)
        Put #1, , TB
        StringByte = WordCode(I)
        Put #1, , StringByte
        Put #1, , 0
        StringByte = WordMean(I)
        Put #1, , StringByte
        Put #1, , 0
    Next
    Close #1
End Sub