电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

汉字拼音的一个完整解决方法![1]


发布日期:2022/12/25
 

Imports SystemIO

Imports SystemTextRegularExpressions

Namespace BusinnessPinYin

Public Class PYService

Private gDataSet As New dsPinYin

<summary>

汉字表

</summary>

Public ReadOnly Property PinYinTable() As dsPinYinPinYinDataTable

Get

Return gDataSetPinYin

End Get

End Property

Private gTxtFile As String = AppDomainCurrentDomainSetupInformationApplicationBase & pinyintxt

Private gxmlFile As String = AppDomainCurrentDomainSetupInformationApplicationBase & pinyinxml

Private gRegex As New Regex((?<Word>^[\ue\ufa]+)(?<PingYin>*))

<summary>

加载汉字库文件名为pinyinxml在程序当前目录下

</summary>

Public Sub Load()

If Not IOFileExists(gxmlFile) Then

Throw New Exception(StringFormat(文件{}不存在 gxmlFile))

End If

DataSetInitialize()

gDataSetReadXml(gxmlFile)

End Sub

<summary>

从汉字文件中更新文件名为pinyintxt在程序当前目录下

</summary>

<remarks></remarks>

Public Sub Update()

If Not IOFileExists(gTxtFile) Then

Throw New Exception(StringFormat(文件{}不存在 gTxtFile))

End If

UpdateFromTxt(gTxtFile)

End Sub

<summary>

保存汉字库文件为pingyinxml在程序当前目录下

</summary>

<remarks></remarks>

Public Sub Save()

gDataSetWriteXml(gxmlFile)

End Sub

Private Sub DataSetInitialize()

在更新或读入时清除

MegDataSetClear()

MegDataSetAcceptChanges()

End Sub

Private Sub UpdateFromTxt(ByVal file As String)

DataSetInitialize()

Dim mLine As String

Dim mBuilder As New SystemTextStringBuilder

Dim mReader As New IOStreamReader(file SystemTextEncodingDefault)

Do

mLine = mReaderReadLine

Add(mLine)

Loop Until StringIsNullOrEmpty(mLine)

mReaderClose()

mReaderDispose()

MegDataSetPinYinAcceptChanges()

End Sub

Private Sub Add(ByVal line As String)

If line Is Nothing Then Exit Sub

With gRegexMatch(line)

If Success Then

只取单字不取词组

If Groups(Word)ValueLength = Then

Add(Groups(Word)Value Groups(PingYin)Value)

End If

End If

End With

End Sub

Private Sub Add(ByVal word As String ByVal py As String)

多音的拼音间用单个空枨符隔开

py = pyTrimReplace( )

Dim mCode As String = ChineseCode(word)

Dim mRow As dsPinYinPinYinRow = MegDataSetPinYinFindBy代码(mCode)

If mRow Is Nothing Then

MegDataSetPinYinAddPinYinRow(word mCode py)

Else

Dim pyArray() As String = pySplit( c)

For Each s As String In pyArray

If Not mRow拼音Contains(s) Then

mRow拼音 = StringConcat(mRow拼音 & s)

End If

Next

End If

End Sub

[] []

上一篇:2.6.2 Global.asax包含整个站点都可以使用的代码

下一篇:汉字拼音的一个完整解决方法![2]