Created
March 7, 2016 15:17
-
-
Save lucafaggianelli/c08aa09ed4228759f547 to your computer and use it in GitHub Desktop.
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
module Freebase | |
require 'rest-client' | |
NS = 'http://rdf.freebase.com/ns' | |
API_URL = 'https://www.googleapis.com/freebase/v1' | |
API_KEY = 'your_key_here' | |
RestClient.proxy = ENV['http_proxy'] | |
MQLClient = RestClient::Resource.new(API_URL) | |
def Freebase.mql(q) | |
response = MQLClient['/mqlread'].get({params: { query: q.to_json }}) | |
return false if response.code != 200 # If errors | |
return JSON.parse response # Otherwise | |
end | |
def Freebase.get_type_schema(type) | |
_t = type.gsub(NS, '') # Strip the namespace if any | |
q = [{ schema: _t, | |
type: "/type/property", | |
name: nil, | |
id: nil, | |
expected_type: { | |
:'/freebase/type_hints/mediator' => nil, | |
name: nil, | |
id: nil }, | |
:"/freebase/property_hints/disambiguator" => nil, | |
master_property: nil, | |
reverse_property: nil, | |
unique: nil }]; | |
return Freebase.mql(q) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment