https://github.com/sixarm/sixarm_ruby_freebase
SixArm.com » Ruby » Freebase client with a simple way to query Freebase.com
https://github.com/sixarm/sixarm_ruby_freebase
freebase freebase-client gem ruby
Last synced: over 1 year ago
JSON representation
SixArm.com » Ruby » Freebase client with a simple way to query Freebase.com
- Host: GitHub
- URL: https://github.com/sixarm/sixarm_ruby_freebase
- Owner: SixArm
- License: other
- Created: 2010-05-25T07:21:41.000Z (about 16 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T19:28:10.000Z (almost 3 years ago)
- Last Synced: 2025-02-06T00:25:22.093Z (over 1 year ago)
- Topics: freebase, freebase-client, gem, ruby
- Language: Ruby
- Homepage: http://sixarm.com
- Size: 325 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# SixArm.com → Ruby →
Freebase client with a simple way to query Freebase.com
* Doc:
* Gem:
* Repo:
## Introduction
Freebase client with a simple way to query Freebase.com
For docs go to
Want to help? We're happy to get pull requests.
## Install
### Gem
To install this gem in your shell or terminal:
gem install sixarm_ruby_freebase
### Gemfile
To add this gem to your Gemfile:
gem 'sixarm_ruby_freebase'
### Require
To require the gem in your code:
require 'sixarm_ruby_freebase'
## Examples
Install:
gem install sixarm_ruby_freebase
Example:
require "sixarm_ruby_freebase"
require "pp"
query = '{"id":"/en/china","capital":null,"type":"/location/country"}'
pp Freebase.read(query)
#=> {"id"=>"/en/china", "type"=>"/location/country", "capital"=>"Beijing"}
pp Freebase.read(query)['capital']
#=> "Beijing"
Example of multiple queries"
query1 = '{"id":"/en/india","capital":null,"type":"/location/country"}'
query2 = '{"id":"/en/japan","capital":null,"type":"/location/country"}'
pp Freebase.read(query1,query2)
#=> [{"id"=>"/en/india", "type"=>"/location/country", "capital"=>"New Delhi"},
{"id"=>"/en/japan", "type"=>"/location/country", "capital"=>"Tokyo"}]
pp Freebase.read(query1,query2).map{|result| result['capital']}
#=> ["New Delhi","Tokyo"]
## Name Query
Example:
query = Freebase.name_query('Cher')
#=> {"/type/reflect/any_value"=>[{
"lang"=>"/lang/en",
"link|="=>
[
"/type/object/name",
"/common/topic/alias"
],
"type"=>"/type/text",
"value"=>"cher"
}],
"t1:type"=>"/people/person",
"t2:type"=>"/common/topic",
"t3:type"=>{
"name"=>"/people/deceased_person",
"optional"=>"optional"
},
"id"=>"null"
}
Example of finding a person's id:
Freebase.read(Freebase.name_query('Cher'))['id']
#=> "/en/cher"
## Query Formats
You can provide a query as a JSON string or as a Hash.
The query methods will convert:
* a Hash to a JSON string e.g. {:foo=>'bar'} to '{"foo":"bar"}
* a nil value to the freebase 'null' string e.g. {:foo=>nil} to {"foo":null}
* anything else: we call to_s then to_json