blocklyでobjectを動かす。その17
概要
blocklyでobjectを動かす。
bdpediaからsparqlで取得してみる。
stageを書く。
function dbpedia(query) {
var endpoint = "http://ja.dbpedia.org/sparql";
query = "SELECT DISTINCT * WHERE { dbpedia-ja:" + query + " dbpedia-owl:abstract ?abstract .}"
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200)
{
var json = JSON.parse(xhr.responseText);
alert(json.results.bindings[0].abstract.value)
}
};
xhr.open("POST", endpoint, true);
xhr.setRequestHeader("Accept", "application/sparql-results+json");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("query=" + encodeURIComponent(query));
}
objectを書く。
Blockly.Blocks.dbpedia = {
init: function() {
this.jsonInit({
message0: "dbpedia %1",
args0: [{
type: "input_value",
name: "TEXT"
}],
previousStatement: null,
nextStatement: null,
style: "text_blocks",
tooltip: Blockly.Msg.TEXT_PRINT_TOOLTIP,
helpUrl: Blockly.Msg.TEXT_PRINT_HELPURL
})
}};
Blockly.JavaScript.dbpedia = function(a) {
return "dbpedia(" + (Blockly.JavaScript.valueToCode(a, "TEXT", Blockly.JavaScript.ORDER_NONE) || "''") + ");\n"
};
フローを書く。
function dbpedia(query) {
var endpoint = "http://ja.dbpedia.org/sparql";
query = "SELECT DISTINCT * WHERE { dbpedia-ja:" + query + " dbpedia-owl:abstract ?abstract .}"
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200)
{
var json = JSON.parse(xhr.responseText);
alert(json.results.bindings[0].abstract.value)
}
};
xhr.open("POST", endpoint, true);
xhr.setRequestHeader("Accept", "application/sparql-results+json");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("query=" + encodeURIComponent(query));
}
Blockly.Blocks.dbpedia = {
init: function() {
this.jsonInit({
message0: "dbpedia %1",
args0: [{
type: "input_value",
name: "TEXT"
}],
previousStatement: null,
nextStatement: null,
style: "text_blocks",
tooltip: Blockly.Msg.TEXT_PRINT_TOOLTIP,
helpUrl: Blockly.Msg.TEXT_PRINT_HELPURL
})
}};
Blockly.JavaScript.dbpedia = function(a) {
return "dbpedia(" + (Blockly.JavaScript.valueToCode(a, "TEXT", Blockly.JavaScript.ORDER_NONE) || "''") + ");\n"
};
フローを書く。
成果物
以上。
Author And Source
この問題について(blocklyでobjectを動かす。その17), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/d9cc26df43db68415798著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .