Freebase and Biohackathon 2010
This post is a quick overview of Freebase for the participants of biohackathon2010 who attended François Belleau's lecture this morning. It was suggested here that Freebase could be used to store and share some predicates for the semantic web. In the current post, I'm going to use CURL to programmatically add a new Namespace in freebase .
OK. First, let's send a MQL query to Freebase and get the schema for the type 'Namespace'. We ask for the name, the id and the expected_type of all the properties of /user/biohackathon/default_domain/namespace_1:
curl http://www.freebase.com/api/service/mqlread -d 'query={
"query1":
{
"query":
[{
"id":"/user/biohackathon/default_domain/namespace_1",
"/type/type/properties": [{
"name": null,
"id":null,
"expected_type": null
}]
}]
}
}'
The response is:"query1":
{
"query":
[{
"id":"/user/biohackathon/default_domain/namespace_1",
"/type/type/properties": [{
"name": null,
"id":null,
"expected_type": null
}]
}]
}
}'
{
"code": "/api/status/ok",
"result": [
{
"/type/type/properties": [
{
"expected_type": "/type/uri",
"id": "/user/biohackathon/default_domain/namespace_1/uri",
"name": "URI"
},
{
"expected_type": "/type/uri",
"id": "/user/biohackathon/default_domain/namespace_1/url",
"name": "Documentation URL"
}
],
"id": "/user/biohackathon/default_domain/namespace_1"
}
],
"status": "200 OK",
"transaction_id": "cache;cache01.p01.sjc1:8101;2010-02-11T17:46:20Z;0024"
}
Ok, there are two properties for this 'Namespace': URI (a '/type/uri') and Documentation URL (a '/type/uri' too) Now we're going to insert a new Namespace. The namespace will be DOAP (Description of a Project). The URI for DOAP is http://usefulinc.com/ns/doap# and the Documentation URL is http://trac.usefulinc.com/doap."code": "/api/status/ok",
"result": [
{
"/type/type/properties": [
{
"expected_type": "/type/uri",
"id": "/user/biohackathon/default_domain/namespace_1/uri",
"name": "URI"
},
{
"expected_type": "/type/uri",
"id": "/user/biohackathon/default_domain/namespace_1/url",
"name": "Documentation URL"
}
],
"id": "/user/biohackathon/default_domain/namespace_1"
}
],
"status": "200 OK",
"transaction_id": "cache;cache01.p01.sjc1:8101;2010-02-11T17:46:20Z;0024"
}
Authenticate (only once)
curl -c cookies.txt -d "username=yourusername" -d "password=yourpassword" https://www.freebase.com/api/account/login
{
"code": "/api/status/ok",
"messages": [
{
"code": "/api/status/ok/account/login",
"message": "Login succeeded",
"username": "yourusername"
}
],
"status": "200 OK",
"transaction_id": "cache;xxxxx"
}
Insert the DOAP Namespace:{
"code": "/api/status/ok",
"messages": [
{
"code": "/api/status/ok/account/login",
"message": "Login succeeded",
"username": "yourusername"
}
],
"status": "200 OK",
"transaction_id": "cache;xxxxx"
}
curl -b cookies.txt -H 'X-Requested-With: curl' https://www.freebase.com/api/service/mqlwrite -d 'query={"query":{
"create": "unless_exists",
"type":"/user/biohackathon/default_domain/namespace_1",
"id":null,
"name":"doap",
"/user/biohackathon/default_domain/namespace_1/uri":"http://usefulinc.com/ns/doap#",
"/user/biohackathon/default_domain/namespace_1/url":"http://trac.usefulinc.com/doap"
}}'
"create": "unless_exists",
"type":"/user/biohackathon/default_domain/namespace_1",
"id":null,
"name":"doap",
"/user/biohackathon/default_domain/namespace_1/uri":"http://usefulinc.com/ns/doap#",
"/user/biohackathon/default_domain/namespace_1/url":"http://trac.usefulinc.com/doap"
}}'
The anwser from freebase is:
{
"code": "/api/status/ok",
"result": {
"/user/biohackathon/default_domain/namespace_1/uri": "http://usefulinc.com/ns/doap#",
"/user/biohackathon/default_domain/namespace_1/url": "http://trac.usefulinc.com/doap",
"create": "created",
"id": "/guid/9202a8c04000641f8000000013e40eea",
"name": "doap",
"type": "/user/biohackathon/default_domain/namespace_1"
},
"status": "200 OK",
"transaction_id": "cache;cache02.p01.sjc1:8101;2010-02-11T18:47:45Z;0037"
}
You can now view this new Namespace at http://www.freebase.com/view/user/biohackathon/default_domain/views/namespace_1."code": "/api/status/ok",
"result": {
"/user/biohackathon/default_domain/namespace_1/uri": "http://usefulinc.com/ns/doap#",
"/user/biohackathon/default_domain/namespace_1/url": "http://trac.usefulinc.com/doap",
"create": "created",
"id": "/guid/9202a8c04000641f8000000013e40eea",
"name": "doap",
"type": "/user/biohackathon/default_domain/namespace_1"
},
"status": "200 OK",
"transaction_id": "cache;cache02.p01.sjc1:8101;2010-02-11T18:47:45Z;0037"
}
That's it !
Pierre
2 comments:
I know Pierre knows this, but for others who want to play with MQL:
Don't forget to use the sandbox (http://www.sandbox-freebase.com) for experimentation until your queries are debugged!
Pierre, I saw your (and my) page as author of the Beautiful Data book... do you think FreeBase might server as a social and open researcher id?
Post a Comment