Last active
August 29, 2015 14:26
-
-
Save tsunagun/b9135b2027d59a8e2551 to your computer and use it in GitHub Desktop.
LOD4ALLで利用できなかったSPARQL式のサンプルなど.元のソースコードはFUJITSU LABORATORIESによるAPIサンプルコード(http://lod4all.net/api.html)
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
require 'open-uri' | |
# 問い合わせ先のURL | |
uri = URI.parse("http://lod4all.net/api/search.cgi") | |
# SPARQL式 | |
sparql =<<-EOS | |
SELECT ?s | |
WHERE { | |
?s ?p <http://ja.dbpedia.org/resource/東京都> . | |
} | |
EOS | |
# 問い合わせ時のパラメータ | |
params = { | |
type: "sparql", | |
format: "json", | |
appID: "xawsaykmcb", | |
query: sparql, | |
} | |
uri.query = URI.encode_www_form(params) | |
# 最終的なリクエストURL | |
puts uri | |
# レスポンスの表示 | |
puts open(uri, &:read) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script type="text/javascript" src="http://lod4all.net/api/lfasparql-2.0.0.js"></script> | |
<script type="text/javascript"> | |
var lfasparql = new LFASparql(); | |
$(document).ready( function() { | |
test(); | |
}); | |
function test() { | |
var sparql_query = "select distinct * from <http://ja> where { ?s ?p <http://ja.dbpedia.org/resource/東京都> . }"; | |
lfasparql.executeSparql({ | |
appID: "xawsaykmcb", | |
sparql: sparql_query, | |
success: getResult, | |
error: getError | |
}); | |
function getResult(data) { | |
for(var i = 0; i < data.length; i++) { | |
var items = data[i]; | |
var s_type = items["s"]["type"]; | |
var s_value = items["s"]["value"]; | |
var p_type = items["p"]["type"]; | |
var p_value = items["p"]["value"]; | |
$("#result") | |
.append( | |
"<li>" + | |
s_type + ": " + s_value + ", " + | |
p_type + ": " + p_value + ", " + | |
"</li>" | |
); | |
} | |
} | |
function getError(jqXHR, textStatus, errorThrown) { | |
console.log(textStatus); | |
} | |
} | |
</script> | |
<title>API Test</title> | |
</head> | |
<body> | |
<h3>API Test</h3> | |
<ol id="result"> | |
</ol> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script type="text/javascript" src="http://lod4all.net/api/lfasparql-2.0.0.js"></script> | |
<script type="text/javascript"> | |
var lfasparql = new LFASparql(); | |
$(document).ready( function() { | |
test(); | |
}); | |
function test() { | |
var sparql_query = "select distinct * where { graph ?g { ?s ?p <http://ja.dbpedia.org/resource/東京都> . } }"; | |
lfasparql.executeSparql({ | |
appID: "xawsaykmcb", | |
sparql: sparql_query, | |
success: getResult, | |
error: getError | |
}); | |
function getResult(data) { | |
for(var i = 0; i < data.length; i++) { | |
var items = data[i]; | |
var s_type = items["s"]["type"]; | |
var s_value = items["s"]["value"]; | |
var p_type = items["p"]["type"]; | |
var p_value = items["p"]["value"]; | |
$("#result") | |
.append( | |
"<li>" + | |
s_type + ": " + s_value + ", " + | |
p_type + ": " + p_value + ", " + | |
"</li>" | |
); | |
} | |
} | |
function getError(jqXHR, textStatus, errorThrown) { | |
console.log(textStatus); | |
} | |
} | |
</script> | |
<title>API Test</title> | |
</head> | |
<body> | |
<h3>API Test</h3> | |
<ol id="result"> | |
</ol> | |
</body> | |
</html> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script> | |
<script type="text/javascript" src="http://lod4all.net/api/lfasparql-2.0.0.js"></script> | |
<script type="text/javascript"> | |
var lfasparql = new LFASparql(); | |
$(document).ready( function() { | |
test(); | |
}); | |
function test() { | |
var sparql_query = "select distinct * where { ?s ?p '東京都'@ja . }"; | |
lfasparql.executeSparql({ | |
appID: "xawsaykmcb", | |
sparql: sparql_query, | |
success: getResult, | |
error: getError | |
}); | |
function getResult(data) { | |
for(var i = 0; i < data.length; i++) { | |
var items = data[i]; | |
var s_type = items["s"]["type"]; | |
var s_value = items["s"]["value"]; | |
var p_type = items["p"]["type"]; | |
var p_value = items["p"]["value"]; | |
$("#result") | |
.append( | |
"<li>" + | |
s_type + ": " + s_value + ", " + | |
p_type + ": " + p_value + ", " + | |
"</li>" | |
); | |
} | |
} | |
function getError(jqXHR, textStatus, errorThrown) { | |
console.log(textStatus); | |
} | |
} | |
</script> | |
<title>API Test</title> | |
</head> | |
<body> | |
<h3>API Test</h3> | |
<ol id="result"> | |
</ol> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment