Skip to content

Commit

Permalink
birthday
Browse files Browse the repository at this point in the history
  • Loading branch information
michael committed Aug 23, 2009
0 parents commit 1198b21
Show file tree
Hide file tree
Showing 61 changed files with 7,033 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gems
@@ -0,0 +1,2 @@
michael-ken --version '>= 0.0.3' --source gems.github.com
extlib --version '>= 0.9.10'
24 changes: 24 additions & 0 deletions .gitignore
@@ -0,0 +1,24 @@
test_log
pkg
pkg/*
*/pkg/*
bundle
bundle/*
doc
*.log
log
!log*.rb
*/log
log/*
*/log/*
coverage
*/coverage
lib/dm-more.rb
*.db
nbproject
.DS_Store
rspec_report.html
*.swp
_Yardoc
*/ri

13 changes: 13 additions & 0 deletions README.textile
@@ -0,0 +1,13 @@
h1. ASK KEN™ - Visual Knowledge Browser

"ASK KEN™":http://askken.heroku.com is some sort of a Node-Link diagram that allows to visually navigate through the "Freebase":http://www.freebase.com graph.

It uses "Rails":http://rubyonrails.org and the "Ken Ruby Freebase API Wrapper":http://github.com/michael/ken in the backend and "Processing.js":http://processingjs.org on front.

Using the new canvas element for drawing ASK KEN™ takes advantage of the latest HTML5 features.

Although it's basically working the project is far from being complete. Originally, it was just an attempt to build something useful on top of the Ken Freebase Library. ;)

Anyway, I hope you like it!

Please feel free to check out the code and share your ideas! :)
10 changes: 10 additions & 0 deletions Rakefile
@@ -0,0 +1,10 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

require 'tasks/rails'
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
@@ -0,0 +1,10 @@
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details

# Scrub sensitive parameters from your log
# filter_parameter_logging :password
end
19 changes: 19 additions & 0 deletions app/controllers/resources_controller.rb
@@ -0,0 +1,19 @@
class ResourcesController < ApplicationController
include ResourcesHelper

def details
@resource = params[:id] ? Ken.get(params[:id]) : Ken.get("/en/new_order")

response = render_to_string(:partial => "details", :locals => { :resource => @resource })
render :text => response
end

def show
@resource = params[:id] ? Ken.get(params[:id]) : Ken.get("/en/new_order")
render :json => {
:data => resource_json(@resource),
:details_html => render_to_string(:partial => "details", :locals => { :resource => @resource })
}
end

end
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
@@ -0,0 +1,3 @@
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
33 changes: 33 additions & 0 deletions app/helpers/resources_helper.rb
@@ -0,0 +1,33 @@
module ResourcesHelper
def resource_json(resource)
response = {
:id => resource.id,
:name => resource.name,
:attributes => []
}

resource.attributes.each do |a|
attribute = {
:id => a.property.id.to_s,
:name => a.property.name.to_s,
:values => []
}
value_count = 0
if a.property.object_type? && a.values.length>=1 # && a.values.length<10
a.values.each do |v|
value = {
:id => v.id,
:name => v.name
}

if (v.name != "")
attribute[:values] << value if value_count <= 20
value_count += 1
end
end
end
response[:attributes] << attribute if a.property.object_type? && a.values.length>=1 && a.property.type.id != "/common/topic" # && a.values.length<10
end
response
end
end
31 changes: 31 additions & 0 deletions app/views/layouts/application.html.haml
@@ -0,0 +1,31 @@
!!! XML
!!!
%html
%head
%link{:rel => 'stylesheet', :href => '/stylesheets/global.css', :type => 'text/css', :media => 'screen, projection'}
%script{:type => 'text/javascript', :src => '/javascripts/jquery-1.3.2.min.js'}
%script{:type => 'text/javascript', :src => '/javascripts/processing.min.js'}
%script{:type => 'text/javascript', :src => '/javascripts/freebase.suggest.min.js'}
= yield :head
%title Ask Ken - Showcase
%body
%header
%section#title
%h1 ASK KEN™
%p Visual Knowledge Browser
%section#search
%input#fb-suggest{:type => "text", :name => "fb-suggest", :default => "Search 8 million interconnected topics ...", :autocomplete => "off"}
%br{:style => "clear: both;"}
%section#content
= yield
%footer
.left
A
%a{:href => "http://quasipartikel.at"} Quasipartikel
Production
.right
-# %a#about{:href => "#"} About
feeded by
%a{:href => "http://freebase.com", :target => "_blank"} Freebase
| Code available at
%a{:href => "http://github.com/michael/askken", :target => "_blank"} Github
17 changes: 17 additions & 0 deletions app/views/resources/_details.html.haml
@@ -0,0 +1,17 @@
-# fur future use
%h2= @resource.name
- @resource.views.each do |view|
- if view.attributes.length>0
%h3= view
- view.attributes.each do |attribute|
%h4
= attribute.property.name
%ul
- attribute.values.each do |value|
%li
- if attribute.property.expected_type=="/common/image"
%img{:src => "http://img.freebase.com/api/trans/image_thumb/#{value.id}?maxheight=70&mode=fit&maxwidth=70"}
- elsif attribute.property.object_type?
%a{:href => "/resources/show?id=#{value.id}"}= value
- else
= value
48 changes: 48 additions & 0 deletions app/views/resources/index.html.erb
@@ -0,0 +1,48 @@
<script type="text/javascript">
var p = null;
$(function() {
var canvas = document.getElementById("kenviz");
p = Processing(canvas);

var initialized = false;

var search = $("#fb-suggest")
search.suggest()
.bind("fb-select", function(e, data) {
p.resourceId = data.id;
if (!initialized) {
p.init(p.ajax("/javascripts/pjs/physics.pjs")+p.ajax("/javascripts/pjs/value.pjs")+p.ajax("/javascripts/pjs/attribute.pjs")+p.ajax("/javascripts/pjs/resource.pjs")+p.ajax("/javascripts/pjs/node.pjs")+p.ajax("/javascripts/pjs/edge.pjs")+p.ajax("/javascripts/pjs/graph.pjs")+p.ajax("/javascripts/pjs/network.pjs"));
initialized = true;
} else {
p.setup();
}
})
.focus(function(e) {
if ($(this).val() == $(this).attr('default')) {
$(this).val("");
}
else {
$(this).select();
}
$(this).removeClass('ghost-input');
})
.blur(function(e) {
if (!$(this).val()) {
$(this).val($(this).attr('default')).addClass('ghost-input');
}
});

search.val(search.attr('default')).addClass('ghost-input');

// init
p.resourceId = null; // "/en/new_order";
p.init(p.ajax("/javascripts/pjs/physics.pjs")+p.ajax("/javascripts/pjs/value.pjs")+p.ajax("/javascripts/pjs/attribute.pjs")+p.ajax("/javascripts/pjs/resource.pjs")+p.ajax("/javascripts/pjs/node.pjs")+p.ajax("/javascripts/pjs/edge.pjs")+p.ajax("/javascripts/pjs/graph.pjs")+p.ajax("/javascripts/pjs/network.pjs"));
initialized = true;

$(window).resize(function(){
p.resize();
});
});
</script>

<canvas id="kenviz"></canvas>
110 changes: 110 additions & 0 deletions config/boot.rb
@@ -0,0 +1,110 @@
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb

RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)

module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end

def booted?
defined? Rails::Initializer
end

def pick_boot
(vendor_rails? ? VendorBoot : GemBoot).new
end

def vendor_rails?
File.exist?("#{RAILS_ROOT}/vendor/rails")
end

def preinitialize
load(preinitializer_path) if File.exist?(preinitializer_path)
end

def preinitializer_path
"#{RAILS_ROOT}/config/preinitializer.rb"
end
end

class Boot
def run
load_initializer
Rails::Initializer.run(:set_load_path)
end
end

class VendorBoot < Boot
def load_initializer
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
Rails::Initializer.run(:install_gem_spec_stubs)
Rails::GemDependency.add_frozen_gem_path
end
end

class GemBoot < Boot
def load_initializer
self.class.load_rubygems
load_rails_gem
require 'initializer'
end

def load_rails_gem
if version = self.class.gem_version
gem 'rails', version
else
gem 'rails'
end
rescue Gem::LoadError => load_error
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
exit 1
end

class << self
def rubygems_version
Gem::RubyGemsVersion rescue nil
end

def gem_version
if defined? RAILS_GEM_VERSION
RAILS_GEM_VERSION
elsif ENV.include?('RAILS_GEM_VERSION')
ENV['RAILS_GEM_VERSION']
else
parse_gem_version(read_environment_rb)
end
end

def load_rubygems
require 'rubygems'
min_version = '1.3.1'
unless rubygems_version >= min_version
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
exit 1
end

rescue LoadError
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
exit 1
end

def parse_gem_version(text)
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
end

private
def read_environment_rb
File.read("#{RAILS_ROOT}/config/environment.rb")
end
end
end
end

# All that for this:
Rails.boot!
22 changes: 22 additions & 0 deletions config/database.yml
@@ -0,0 +1,22 @@
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

0 comments on commit 1198b21

Please sign in to comment.