<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dipplum.com &#187; pinyin</title>
	<atom:link href="http://dipplum.com/tag/pinyin/feed/" rel="self" type="application/rss+xml" />
	<link>http://dipplum.com</link>
	<description>Be  the change you wanna see in the world</description>
	<lastBuildDate>Sat, 12 Nov 2011 07:38:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Python调用搜狗云输入法的小例子</title>
		<link>http://dipplum.com/2010/01/22/sogou-cloud-ime-python/</link>
		<comments>http://dipplum.com/2010/01/22/sogou-cloud-ime-python/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 17:52:20 +0000</pubDate>
		<dc:creator>li</dc:creator>
				<category><![CDATA[中文化]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[ime]]></category>
		<category><![CDATA[pinyin]]></category>
		<category><![CDATA[sogou]]></category>

		<guid isPermaLink="false">http://dipplum.com/2010/01/22/sogou-cloud-ime-python/</guid>
		<description><![CDATA[写了个Python的小例子，调用搜狗云输入法获取汉字。感谢xzap在搜狗论坛发布的bash脚本，但觉得bash还是略微晦涩了点，用python说明搜狗云输入法的API更加清晰一点。 #!/usr/bin/python from urllib import urlopen from cgi import parse_qs &#160; url = 'http://web.pinyin.sogou.com/web_ime/get_ajax/%s.key' &#160; py = raw_input&#40;'input pinyin: '&#41; res = urlopen&#40;url % py&#41;.read&#40;&#41; dic = parse_qs&#40;res&#41; lst = eval&#40;dic&#91;'ime_query_res'&#93;&#91;0&#93;&#41;.split&#40;'\t '&#41; words = map&#40;lambda x: x.split&#40;'\xef\xbc\x9a'&#41;&#91;0&#93;, lst&#41; counts = map&#40;lambda x: x.split&#40;'\xef\xbc\x9a'&#41;&#91;1&#93;, lst&#41; &#160; for i in range&#40;len&#40;words&#41;&#41;: print words&#91;i&#93;, counts&#91;i&#93; &#160; exit 运行该脚本的输出结果如下，每行前面是候选词/句，后面是该候选词/句消耗的英文单词字母个数： [...]]]></description>
			<content:encoded><![CDATA[<p>写了个Python的小例子，调用搜狗云输入法获取汉字。感谢xzap在搜狗论坛发布的<a href="http://pinyin.sogou.com/bbs/redirect.php?tid=140527&amp;goto=lastpost" target="_blank">bash脚本</a>，但觉得bash还是略微晦涩了点，用python说明搜狗云输入法的API更加清晰一点。</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python                                                                                                                                           </span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">urllib</span> <span style="color: #ff7700;font-weight:bold;">import</span> urlopen
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">cgi</span> <span style="color: #ff7700;font-weight:bold;">import</span> parse_qs
&nbsp;
url = <span style="color: #483d8b;">'http://web.pinyin.sogou.com/web_ime/get_ajax/%s.key'</span>
&nbsp;
py = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'input pinyin: '</span><span style="color: black;">&#41;</span>
res = urlopen<span style="color: black;">&#40;</span>url <span style="color: #66cc66;">%</span> py<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
dic = parse_qs<span style="color: black;">&#40;</span>res<span style="color: black;">&#41;</span>
lst = <span style="color: #008000;">eval</span><span style="color: black;">&#40;</span>dic<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ime_query_res'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\t</span> '</span><span style="color: black;">&#41;</span>
words = <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> x: x.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>ef<span style="color: #000099; font-weight: bold;">\x</span>bc<span style="color: #000099; font-weight: bold;">\x</span>9a'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>, lst<span style="color: black;">&#41;</span>
counts = <span style="color: #008000;">map</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> x: x.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\x</span>ef<span style="color: #000099; font-weight: bold;">\x</span>bc<span style="color: #000099; font-weight: bold;">\x</span>9a'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>, lst<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>words<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> words<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>, counts<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
&nbsp;
exit</pre></div></div>

<p>运行该脚本的输出结果如下，每行前面是候选词/句，后面是该候选词/句消耗的英文<del datetime="2010-07-02T08:58:07+00:00">单词</del>字母个数：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>sogou.py
input pinyin: nihaosgysrf
你好搜狗云输入法 <span style="color: #000000;">11</span>
你好是 <span style="color: #000000;">6</span>
倪豪士 <span style="color: #000000;">6</span>
你好 <span style="color: #000000;">5</span>
拟好 <span style="color: #000000;">5</span>
倪浩 <span style="color: #000000;">5</span>
泥蒿 <span style="color: #000000;">5</span>
倪昊 <span style="color: #000000;">5</span>
倪皓 <span style="color: #000000;">5</span>
匿号 <span style="color: #000000;">5</span>
你 <span style="color: #000000;">2</span>
拟 <span style="color: #000000;">2</span>
呢 <span style="color: #000000;">2</span>
尼 <span style="color: #000000;">2</span>
泥 <span style="color: #000000;">2</span>
逆 <span style="color: #000000;">2</span>
妮 <span style="color: #000000;">2</span>
腻 <span style="color: #000000;">2</span>
倪 <span style="color: #000000;">2</span>
伱 <span style="color: #000000;">2</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://dipplum.com/2010/01/22/sogou-cloud-ime-python/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

