ken 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'extlib'
4
+ gem 'json'
5
+ gem 'addressable'
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ gem 'jeweler'
10
+ gem 'shoulda'
11
+ gem 'jnunemaker-matchy', '0.4.0'
12
+ end
data/Rakefile CHANGED
@@ -9,11 +9,6 @@ begin
9
9
  gem.email = "ma[at]zive[dot]at"
10
10
  gem.homepage = "http://github.com/michael/ken"
11
11
  gem.authors = ["michael"]
12
- gem.add_dependency('extlib')
13
- gem.add_dependency('json')
14
- gem.add_dependency('addressable')
15
- # gem.files = FileList["[A-Z]*.*"]
16
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
12
  end
18
13
 
19
14
  rescue LoadError
@@ -57,4 +52,4 @@ Rake::RDocTask.new do |rdoc|
57
52
  rdoc.rdoc_files.include('lib/**/*.rb')
58
53
  end
59
54
 
60
- Jeweler::GemcutterTasks.new
55
+ Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -1,96 +1,92 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ken}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["michael"]
12
- s.date = %q{2009-11-02}
11
+ s.authors = [%q{michael}]
12
+ s.date = %q{2011-07-08}
13
13
  s.email = %q{ma[at]zive[dot]at}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
16
- "README.textile",
17
- "README.txt"
16
+ "README.textile",
17
+ "TODO"
18
18
  ]
19
19
  s.files = [
20
- ".gitignore",
21
- "History.txt",
22
- "LICENSE",
23
- "README.textile",
24
- "README.txt",
25
- "Rakefile",
26
- "TODO",
27
- "VERSION",
28
- "examples/artist.rb",
29
- "examples/artist_links.rb",
30
- "ken.gemspec",
31
- "lib/ken.rb",
32
- "lib/ken/attribute.rb",
33
- "lib/ken/collection.rb",
34
- "lib/ken/logger.rb",
35
- "lib/ken/property.rb",
36
- "lib/ken/resource.rb",
37
- "lib/ken/session.rb",
38
- "lib/ken/topic.rb",
39
- "lib/ken/type.rb",
40
- "lib/ken/util.rb",
41
- "lib/ken/view.rb",
42
- "rails/init.rb",
43
- "tasks/ken.rb",
44
- "tasks/spec.rb",
45
- "test/fixtures/music_artist.json",
46
- "test/fixtures/the_police.json",
47
- "test/fixtures/the_police_topic.json",
48
- "test/integration/ken_test.rb",
49
- "test/test_helper.rb",
50
- "test/unit/attribute_test.rb",
51
- "test/unit/property_test.rb",
52
- "test/unit/resource_test.rb",
53
- "test/unit/session_test.rb",
54
- "test/unit/topic_test.rb",
55
- "test/unit/type_test.rb",
56
- "test/unit/view_test.rb"
20
+ "Gemfile",
21
+ "History.txt",
22
+ "LICENSE",
23
+ "README.textile",
24
+ "Rakefile",
25
+ "TODO",
26
+ "VERSION",
27
+ "examples/artist.rb",
28
+ "examples/artist_links.rb",
29
+ "ken.gemspec",
30
+ "lib/ken.rb",
31
+ "lib/ken/attribute.rb",
32
+ "lib/ken/collection.rb",
33
+ "lib/ken/logger.rb",
34
+ "lib/ken/property.rb",
35
+ "lib/ken/resource.rb",
36
+ "lib/ken/session.rb",
37
+ "lib/ken/topic.rb",
38
+ "lib/ken/type.rb",
39
+ "lib/ken/util.rb",
40
+ "lib/ken/view.rb",
41
+ "rails/init.rb",
42
+ "tasks/ken.rb",
43
+ "tasks/spec.rb",
44
+ "test/fixtures/music_artist.json",
45
+ "test/fixtures/the_police.json",
46
+ "test/fixtures/the_police_topic.json",
47
+ "test/integration/ken_test.rb",
48
+ "test/test_helper.rb",
49
+ "test/unit/attribute_test.rb",
50
+ "test/unit/property_test.rb",
51
+ "test/unit/resource_test.rb",
52
+ "test/unit/session_test.rb",
53
+ "test/unit/topic_test.rb",
54
+ "test/unit/type_test.rb",
55
+ "test/unit/view_test.rb"
57
56
  ]
58
57
  s.homepage = %q{http://github.com/michael/ken}
59
- s.rdoc_options = ["--charset=UTF-8"]
60
- s.require_paths = ["lib"]
61
- s.rubygems_version = %q{1.3.5}
58
+ s.require_paths = [%q{lib}]
59
+ s.rubygems_version = %q{1.8.5}
62
60
  s.summary = %q{Ruby API for Accessing the Freebase}
63
- s.test_files = [
64
- "test/integration/ken_test.rb",
65
- "test/test_helper.rb",
66
- "test/unit/attribute_test.rb",
67
- "test/unit/property_test.rb",
68
- "test/unit/resource_test.rb",
69
- "test/unit/session_test.rb",
70
- "test/unit/topic_test.rb",
71
- "test/unit/type_test.rb",
72
- "test/unit/view_test.rb",
73
- "examples/artist.rb",
74
- "examples/artist_links.rb"
75
- ]
76
61
 
77
62
  if s.respond_to? :specification_version then
78
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
79
63
  s.specification_version = 3
80
64
 
81
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
65
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
66
  s.add_runtime_dependency(%q<extlib>, [">= 0"])
83
67
  s.add_runtime_dependency(%q<json>, [">= 0"])
84
68
  s.add_runtime_dependency(%q<addressable>, [">= 0"])
69
+ s.add_development_dependency(%q<rake>, [">= 0"])
70
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
71
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
72
+ s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
85
73
  else
86
74
  s.add_dependency(%q<extlib>, [">= 0"])
87
75
  s.add_dependency(%q<json>, [">= 0"])
88
76
  s.add_dependency(%q<addressable>, [">= 0"])
77
+ s.add_dependency(%q<rake>, [">= 0"])
78
+ s.add_dependency(%q<jeweler>, [">= 0"])
79
+ s.add_dependency(%q<shoulda>, [">= 0"])
80
+ s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
89
81
  end
90
82
  else
91
83
  s.add_dependency(%q<extlib>, [">= 0"])
92
84
  s.add_dependency(%q<json>, [">= 0"])
93
85
  s.add_dependency(%q<addressable>, [">= 0"])
86
+ s.add_dependency(%q<rake>, [">= 0"])
87
+ s.add_dependency(%q<jeweler>, [">= 0"])
88
+ s.add_dependency(%q<shoulda>, [">= 0"])
89
+ s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
94
90
  end
95
91
  end
96
92
 
@@ -51,6 +51,7 @@ module Ken
51
51
  :login => '/api/account/login',
52
52
  :upload => '/api/service/upload',
53
53
  :topic => '/experimental/topic',
54
+ :search => '/api/service/search'
54
55
  }
55
56
 
56
57
  # get the service url for the specified service.
@@ -117,6 +118,19 @@ module Ken
117
118
  Ken.logger.info "<<< Received Topic Response: #{inner['result'].inspect}"
118
119
  inner['result']
119
120
  end
121
+
122
+ def search(query, options = {})
123
+ Ken.logger.info ">>> Sending Search Query: #{query}"
124
+ options.merge!({:query => query})
125
+
126
+ response = http_request search_service_url, options
127
+ result = JSON.parse response
128
+
129
+ handle_read_error(result)
130
+
131
+ Ken.logger.info "<<< Received Topic Response: #{result['result'].inspect}"
132
+ result['result']
133
+ end
120
134
 
121
135
  protected
122
136
  # returns parsed json response from freebase mqlread service
@@ -141,6 +155,7 @@ module Ken
141
155
  def http_request(url, parameters = {})
142
156
  params = params_to_string(parameters)
143
157
  url << '?'+params unless params !~ /\S/
158
+ Ken.logger.info "<<< URL queried: #{url}"
144
159
 
145
160
  return Net::HTTP.get_response(::URI.parse(url)).body
146
161
 
@@ -3,8 +3,6 @@ require 'test/unit'
3
3
  require 'shoulda'
4
4
  require 'pathname'
5
5
  require 'json'
6
-
7
- gem 'jnunemaker-matchy', '0.4.0'
8
6
  require 'matchy'
9
7
 
10
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
@@ -29,20 +27,20 @@ class Test::Unit::TestCase
29
27
  matcher.negative_failure_message = "Expected #{receiver} not to be nil but it was"
30
28
  receiver.nil?
31
29
  end
32
-
30
+
33
31
  custom_matcher :have do |receiver, matcher, args|
34
32
  count = args[0]
35
33
  something = matcher.chained_messages[0].name
36
34
  actual = receiver.send(something).size
37
35
  actual == count
38
36
  end
39
-
37
+
40
38
  custom_matcher :be_true do |receiver, matcher, args|
41
39
  matcher.positive_failure_message = "Expected #{receiver} to be true but it wasn't"
42
40
  matcher.negative_failure_message = "Expected #{receiver} not to be true but it was"
43
41
  receiver.eql?(true)
44
42
  end
45
-
43
+
46
44
  custom_matcher :be_false do |receiver, matcher, args|
47
45
  matcher.positive_failure_message = "Expected #{receiver} to be false but it wasn't"
48
46
  matcher.negative_failure_message = "Expected #{receiver} not to be false but it was"
@@ -54,8 +52,8 @@ class Object
54
52
  # nice for debugging
55
53
  # usage: print_call_stack(:method_name, 2, 10)
56
54
  def print_call_stack(from = 2, to = nil, html = false)
57
- (from..(to ? to : caller.length)).each do |idx|
55
+ (from..(to ? to : caller.length)).each do |idx|
58
56
  p "[#{idx}]: #{caller[idx]}#{html ? '<br />' : ''}"
59
57
  end
60
58
  end
61
- end
59
+ end
@@ -35,5 +35,10 @@ class SessionTest < Test::Unit::TestCase
35
35
  should 'do topic requests' do
36
36
  Ken.session.topic("/en/the_police")
37
37
  end
38
+
39
+ should 'do search requests' do
40
+ Ken.session.search("the police").length.should >= 1
41
+ end
42
+
38
43
  end # context
39
44
  end # SessionTest
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ken
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 1
10
+ version: 0.2.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - michael
@@ -9,39 +15,108 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-02 00:00:00 +01:00
13
- default_executable:
18
+ date: 2011-07-08 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: extlib
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
23
31
  version: "0"
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: json
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
30
39
  requirements:
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
33
45
  version: "0"
34
- version:
46
+ type: :runtime
47
+ version_requirements: *id002
35
48
  - !ruby/object:Gem::Dependency
36
49
  name: addressable
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
37
60
  type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: jeweler
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ type: :development
89
+ version_requirements: *id005
90
+ - !ruby/object:Gem::Dependency
91
+ name: shoulda
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
40
95
  requirements:
41
96
  - - ">="
42
97
  - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
43
101
  version: "0"
44
- version:
102
+ type: :development
103
+ version_requirements: *id006
104
+ - !ruby/object:Gem::Dependency
105
+ name: jnunemaker-matchy
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - "="
111
+ - !ruby/object:Gem::Version
112
+ hash: 15
113
+ segments:
114
+ - 0
115
+ - 4
116
+ - 0
117
+ version: 0.4.0
118
+ type: :development
119
+ version_requirements: *id007
45
120
  description:
46
121
  email: ma[at]zive[dot]at
47
122
  executables: []
@@ -51,13 +126,12 @@ extensions: []
51
126
  extra_rdoc_files:
52
127
  - LICENSE
53
128
  - README.textile
54
- - README.txt
129
+ - TODO
55
130
  files:
56
- - .gitignore
131
+ - Gemfile
57
132
  - History.txt
58
133
  - LICENSE
59
134
  - README.textile
60
- - README.txt
61
135
  - Rakefile
62
136
  - TODO
63
137
  - VERSION
@@ -90,43 +164,38 @@ files:
90
164
  - test/unit/topic_test.rb
91
165
  - test/unit/type_test.rb
92
166
  - test/unit/view_test.rb
93
- has_rdoc: true
94
167
  homepage: http://github.com/michael/ken
95
168
  licenses: []
96
169
 
97
170
  post_install_message:
98
- rdoc_options:
99
- - --charset=UTF-8
171
+ rdoc_options: []
172
+
100
173
  require_paths:
101
174
  - lib
102
175
  required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
103
177
  requirements:
104
178
  - - ">="
105
179
  - !ruby/object:Gem::Version
180
+ hash: 3
181
+ segments:
182
+ - 0
106
183
  version: "0"
107
- version:
108
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
109
186
  requirements:
110
187
  - - ">="
111
188
  - !ruby/object:Gem::Version
189
+ hash: 3
190
+ segments:
191
+ - 0
112
192
  version: "0"
113
- version:
114
193
  requirements: []
115
194
 
116
195
  rubyforge_project:
117
- rubygems_version: 1.3.5
196
+ rubygems_version: 1.8.5
118
197
  signing_key:
119
198
  specification_version: 3
120
199
  summary: Ruby API for Accessing the Freebase
121
- test_files:
122
- - test/integration/ken_test.rb
123
- - test/test_helper.rb
124
- - test/unit/attribute_test.rb
125
- - test/unit/property_test.rb
126
- - test/unit/resource_test.rb
127
- - test/unit/session_test.rb
128
- - test/unit/topic_test.rb
129
- - test/unit/type_test.rb
130
- - test/unit/view_test.rb
131
- - examples/artist.rb
132
- - examples/artist_links.rb
200
+ test_files: []
201
+
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- test_log
2
- pkg
3
- pkg/*
4
- */pkg/*
5
- bundle
6
- bundle/*
7
- doc
8
- *.log
9
- log
10
- !log*.rb
11
- */log
12
- log/*
13
- */log/*
14
- coverage
15
- */coverage
16
- lib/dm-more.rb
17
- *.db
18
- nbproject
19
- .DS_Store
20
- rspec_report.html
21
- *.swp
22
- _Yardoc
23
- */ri
data/README.txt DELETED
@@ -1,76 +0,0 @@
1
- = Ken
2
-
3
- * http://www.github.com/michael/ken
4
-
5
- == DESCRIPTION:
6
-
7
- Ken is a Data Layer for Knowledge Representation.
8
-
9
- It's being built to access the Metaweb Services supplied by Freebase.com.
10
- Just born, the project’s goals are the provision of a concise API for querying and writing.
11
- Therefore it wraps the Metaweb Architecture to smart Ruby Objects (that represent the Metaweb Architecture).
12
-
13
- You can navigate the Freebase Graph using a rubyish syntax.
14
-
15
- You should be able to use this Library as a Data Layer (instead of or in addition to
16
- ActiveRecord/DataMapper) for your Web Framework of choice (Merb, Rails).
17
-
18
-
19
- == FEATURES/PROBLEMS:
20
-
21
- Features
22
-
23
- * Fetching of single Resources
24
- * Type inspection
25
- * Attributes inspection
26
- * Views on Resources to group Attributes based on the Resource's types
27
- * Some specs
28
-
29
- Roadmap
30
-
31
- 1. Much more specs
32
- 2. Support for querying of multiple Resources
33
- 3. Better Type Support
34
- 4. API for Set Based Browsing (see http://mqlx.com/~david/parallax/)
35
- 5. Accessing Properties/Attributes directly (e.g. resource.genres )
36
- 6. Write-Support
37
-
38
- == SYNOPSIS:
39
-
40
- resource = Ken.get('/en/new_order') # => <Resource id="/en/new_order" name="New Order">
41
-
42
- == REQUIREMENTS:
43
-
44
- - Ruby >=1.8.x
45
- - RubyGems >=1.2.x
46
- - Extlib >=0.9.x
47
-
48
- == INSTALL:
49
-
50
- $ gem sources -a http://gems.github.com (you only have to do this once)
51
- $ sudo gem install michael-ken
52
-
53
- == LICENSE:
54
-
55
- (The MIT License)
56
-
57
- Copyright (c) 2009 Michael Aufreiter
58
-
59
- Permission is hereby granted, free of charge, to any person obtaining
60
- a copy of this software and associated documentation files (the
61
- 'Software'), to deal in the Software without restriction, including
62
- without limitation the rights to use, copy, modify, merge, publish,
63
- distribute, sublicense, and/or sell copies of the Software, and to
64
- permit persons to whom the Software is furnished to do so, subject to
65
- the following conditions:
66
-
67
- The above copyright notice and this permission notice shall be
68
- included in all copies or substantial portions of the Software.
69
-
70
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
71
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
72
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
73
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
74
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
75
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
76
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.