Created
June 20, 2009 10:53
-
-
Save ucnv/133124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="UTF-8" ?> | |
| <table xmlns="http://query.yahooapis.com/v1/schema/table.xsd"> | |
| <meta> | |
| <sampleQuery>use "http://gist.github.com/133124.txt" as c; select * from c where q="雪が降って嬉しい"</sampleQuery> | |
| </meta> | |
| <bindings> | |
| <select itemPath="" produces="JSON"> | |
| <urls><url/></urls> | |
| <inputs> | |
| <key id="q" type="xs:string" paramType="variable" required="true"/> | |
| </inputs> | |
| <execute><![CDATA[ | |
| y.log(q); | |
| var query = y.query("select * from xml where url=@url", { | |
| url: "http://jlp.yahooapis.jp/MAService/V1/parse" | |
| + "?appid=p2Ycra.xg679U4R4wHKNh1BSjzezBU6645VmDxTQ1ImDuEYWfnmjSdUT2Rb2" | |
| + "&sentence=" + encodeURIComponent(q) | |
| }); | |
| var parsed = y.xmlToJson(query.results); | |
| var parts = parsed.results.ResultSet.ma_result.word_list.word; | |
| parts = (parts.forEach) ? parts : [parts]; | |
| var words = ['ピ', 'ピカァ', 'ピカァァ']; | |
| var verbs = words.concat(['カチュウ', 'ピカチュウ', 'ピカチュウゥ', 'ピカチュウゥゥ']); | |
| var endings= ['\uFFFD\uFFFD', 'ッ', 'アアーッ', '(。◕‿‿◕。)', '', '', '']; | |
| var dice = function(list) { return list[Math.floor(Math.random() * list.length)]; }; | |
| var converted = ''; | |
| parts.forEach(function(word) { | |
| if(word.pos == '特殊' || /@$/.test(converted)) return converted += word.surface; | |
| converted += dice((word.pos == '動詞') ? verbs : words); | |
| converted += dice(endings); | |
| }); | |
| response.object = converted; | |
| ]]> | |
| </execute> | |
| </select> | |
| </bindings> | |
| </table> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment