Skip to content

Instantly share code, notes, and snippets.

@shirayuca
Created August 13, 2014 10:42
Show Gist options
  • Save shirayuca/c82bbf3abbb3fb61696c to your computer and use it in GitHub Desktop.
Save shirayuca/c82bbf3abbb3fb61696c to your computer and use it in GitHub Desktop.
Googleスプレッドシートで形態素解析 ref: http://qiita.com/shirayuca/items/f2da6af69c50f38602a3
/**
* 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