Created
August 4, 2014 13:56
-
-
Save shirayuca/14e8b2cb031baafed526 to your computer and use it in GitHub Desktop.
Yahoo! 日本語形態素解析APIの利用
This file contains 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
/** | |
* Yahoo! 日本語形態素解析APIの利用 | |
*/ | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var mySheet = ss.getActiveSheet(); | |
function yahooTextSegmentation(cell) | |
{ | |
var myAppid = "ここにアプリケーションIDを入力"; | |
var text = cell; | |
var myUrl = "http://jlp.yahooapis.jp/MAService/V1/parse?appid="+myAppid+"&results=ma&sentence="+text; | |
Utilities.sleep(1000); | |
var myXml = UrlFetchApp.fetch(myUrl); | |
var myDoc = XmlService.parse(myXml.getContentText()); | |
var namespace = XmlService.getNamespace("urn:yahoo:jp:jlp"); | |
var root = myDoc.getRootElement(); | |
var ma_result = root.getChild("ma_result", namespace); | |
var word_list = ma_result.getChild("word_list", namespace); | |
var word_array = word_list.getChildren("word", namespace); | |
var surface = word_array[0].getChild("surface", namespace); | |
var array = []; | |
for (var i=0; i < word_array.length; i++) { | |
array[i] = [ | |
word_array[i].getAllContent()[0].asElement().getText(), | |
word_array[i].getAllContent()[1].asElement().getText(), | |
word_array[i].getAllContent()[2].asElement().getText() | |
]; | |
} | |
return array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment