Skip to content

Instantly share code, notes, and snippets.

@lucafaggianelli
Created March 7, 2016 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucafaggianelli/c08aa09ed4228759f547 to your computer and use it in GitHub Desktop.
Save lucafaggianelli/c08aa09ed4228759f547 to your computer and use it in GitHub Desktop.
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