找回密码
 加入
搜索
查看: 2885|回复: 5

[原创] 在线英汉字典

  [复制链接]
发表于 2013-7-15 11:15:11 | 显示全部楼层 |阅读模式
额,粗糙的一个工具,这只是在线用的,未连网不能使用.
第二个,只能英汉使用,也就是英语单词翻译成汉语

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2013-7-17 08:16:43 | 显示全部楼层
谢谢学习一下。。
发表于 2013-7-17 18:47:22 | 显示全部楼层
还这么多人下载? 我放一个自己弄的, 截取百度词典的,
可以英转汉,也可以汉转英,还截取注音,例句....
最重要的是, 我这个不要钱!
#include <inet.au3>
#include <array.au3>
Local $result
$result = _baidu_dict('love you')
If Not @error Then _ArrayDisplay($result)
$result = _baidu_dict('你好')
If Not @error Then _ArrayDisplay($result)
Func _baidu_dict($sString)
        Local $tmp = '', $tmp1 = '', $tmp_str = ''

        ; 检测是否已连接上因特网
        ;Local Const $NETWORK_ALIVE_LAN = 0x1
        ;Local Const $NETWORK_ALIVE_WAN = 0x2
        $tmp = DllCall("sensapi.dll", "int", "IsNetworkAlive", "str", 0x2)
        If @error Then Return SetError(1)
        If $tmp[0] <> 1 Then Return SetError(2)

        Local $cn_phrase ; 示例 词组
        Local $pronounce = '';发音,注音
        Local $bushou = '' ;汉字所属部首
        Local $cn_basicmean = '' ; 中文简单释义
        Local $en_simple_means ; 英文简单释义

        Local $url = 'http://dict.baidu.com/s?wd='
        Local $bool
        
        If StringRegExp($sString, '[^\x00-\xff]') Then ;[\u4E00-\u9FA5]
                $bool = True
                $url &= _convert_chinese($sString)
                Local $aResult[6][2] = [['发音', ''],['英文释义', ''],['中文释义', ''],['部首', ''],['示例词组', ''],['示例句子', '']]
        Else
                $bool = False
                $url &= $sString
                Local $aResult[3][2] = [['发音', ''],['中文释义', ''],['示例句子', '']]
        EndIf

        $data = _INetGetSource($url, False)
        $data = BinaryToString($data, 4)

        If $bool Then
                $tmp = StringRegExp($data, '(?is)id="pronounce".+?\[(.+?)\]', 1)
                If Not @error Then $pronounce = $tmp[0]
                $aResult[0][1] = $pronounce
                ;中文的简单英文释义
                $tmp = StringRegExp($data, '(?is)<div id="en\-simple\-means"(.+)</p>\h*<div', 1)
                If Not @error Then
                        $tmp = StringRegExp($tmp[0], '(?i)>([^<>]+)</a>', 3)
                        If Not @error Then
                                $en_simple_means = _ArrayToString($tmp, ';')
                        EndIf
                Else ; 网络释义
                        $tmp = StringRegExp($data, '(?is)id="cn\-net\-means".+?<dl>(.+?)</dl>', 1)
                        If Not @error Then
                                $tmp = StringRegExp($tmp[0], '(?i)<p>(.+?)</p>', 3)
                                If Not @error Then
                                        $en_simple_means = _ArrayToString($tmp, ';')
                                EndIf
                        EndIf
                EndIf
                $aResult[1][1] = $en_simple_means
                ;中文的中文基本释义
                $tmp = StringRegExp($data, '(?i)id="cn\-basicmean".+?<p>(.+?)</p>', 1)
                If Not @error Then $cn_basicmean = $tmp[0]
                $aResult[2][1] = $cn_basicmean
                ;部首
                $tmp = StringRegExp($data, '(?i)<p>部首:\h*([^<>]+)<', 1)
                If Not @error Then $bushou = $tmp[0]
                $aResult[3][1] = $bushou
                ;词组
                $tmp = StringRegExp($data, '(?is)id="cn\-phrase".+?<ol>(.+?)</ol>', 1)
                If Not @error Then
                        $tmp = StringRegExp($tmp[0], '(?i)<li>(.+?)</li>', 3)
                        If Not @error Then
                                For $i = 0 To UBound($tmp) - 1
                                        $tmp1 = StringRegExp($tmp[$i], '(?i)<p>(.+?)</p>', 3)
                                        If @error Then ContinueLoop
                                        $tmp_str = ''
                                        For $ii = 0 To UBound($tmp1) - 1
                                                $tmp_str &= $tmp1[$ii] & @CRLF
                                        Next
                                        $cn_phrase &= $tmp_str & '**'
                                Next
                                $aResult[4][1] = $cn_phrase
                        EndIf
                EndIf
                ;获取例句
                $aResult[5][1] = _get_example_data($data)
        Else
                ;获取发音注音
                $tmp = StringRegExp($data, '(?s)xml:lang="EN\-US">([^<>]*)', 1)
                If Not @error Then $pronounce = $tmp[0]
                $aResult[0][1] = $pronounce
                ;获取英文的中文释义
                $tmp = StringRegExp($data, '(?is)id="en\-simple\-means".+?<span>(.+?)</span>', 1)
                If Not @error Then
                        $cn_basicmean = $tmp[0]
                Else ; 网络释义
                        $tmp = StringRegExp($data, '(?is)id="en\-net\-means".+?<dl>(.+?)</dl>', 1)
                        If Not @error Then
                                $tmp = StringRegExp($tmp[0], '(?i)<p>(.+?)</p>', 3)
                                If Not @error Then $cn_basicmean = _ArrayToString($tmp, ';')
                        EndIf
                EndIf
                $aResult[1][1] = $cn_basicmean
                ;获取例句
                $aResult[2][1] = _get_example_data($data)
        EndIf
        Return $aResult
EndFunc   ;==>_baidu_dict

Func _get_example_data($sData); 例句
        Local $tmp, $tmp_str, $tmp_str2, $tmp_str3, $t, $tt
        Local $example_data
        $tmp = StringRegExp($sData, '\[{4}.+\]{2}', 1)
        If @error Then Return $example_data
        $tmp = StringRegExp($tmp[0], '\[?(\[{3}.+?)http:', 3)
        If @error Then Return $example_data
        For $i = 0 To UBound($tmp) - 1
                $t = StringRegExp($tmp[$i], '(\[{2}.+?\]{2})', 3)
                If @error Then ContinueLoop
                $tmp_str = ''
                For $ii = 0 To UBound($t) - 1
                        $tmp_str2 = ''
                        $tmp_str3 = ''
                        $tt = StringRegExp($t[$ii], '\["([^"]+)"', 3)
                        If @error Then ContinueLoop
                        For $iii = 0 To UBound($tt) - 1
                                $tmp_str3 = StringReplace($tt[$iii], '\', '')
                                If Not StringRegExp($tmp_str3, '\W') Then $tmp_str3 = ' ' & $tmp_str3
                                $tmp_str2 &= $tmp_str3
                        Next
                        $tmp_str &= $tmp_str2 & '##'
                Next
                $example_data &= $tmp_str & '**'
        Next
        Return $example_data
EndFunc   ;==>_get_example_data

Func _convert_chinese($sChinese)
        If $sChinese = '' Then Return SetError(1)
        If StringRegExp($sChinese, '[a-zA-Z]') Then Return SetError(2)
        $sChinese &= '生产'
        $sChinese = StringToBinary($sChinese, 4)
        $sChinese = StringReplace($sChinese, '0x', '')
        $sChinese = StringRegExpReplace($sChinese, '(\w{2})', '%\1')
        $sChinese = StringRegExpReplace($sChinese, '(?:%\w\w){6}$', '')
        Return $sChinese
EndFunc   ;==>_convert_chinese
发表于 2013-7-18 07:46:44 | 显示全部楼层
回复 3# user3000

谢谢很实用。。
 楼主| 发表于 2013-7-20 16:27:23 | 显示全部楼层
回复 3# user3000


good
发表于 2013-12-4 11:19:14 | 显示全部楼层
谢谢,学习一下,非常感谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-8 17:04 , Processed in 0.074196 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表