-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.rb
More file actions
106 lines (88 loc) · 3.17 KB
/
models.rb
File metadata and controls
106 lines (88 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'rubygems'
require 'active_record'
ActiveRecord::Base.logger = Logger.new(STDERR)
ActiveRecord::Base.colorize_logging = false
dbconfig = YAML.load(File.read('config/database.yml'))
ActiveRecord::Base.establish_connection dbconfig['production']
# ActiveRecord::Base.establish_connection(
# :adapter => "mysql",
# :username => "root",
# :database => 'realpolitik'
# )
ActiveRecord::Schema.define do
# create_table :entities, :options => "ENGINE=MyISAM" do |table|
# table.column :text, :string
# table.column :kind, :string
# table.column :relevance, :float
# table.column :count, :integer
# end
#
# create_table :taggings do |table|
# table.column :story_id, :integer
# table.column :entity_id, :integer
# end
#
# create_table :stories do |table|
# table.column :title, :string
# table.column :url, :string
# table.column :summary, :string
# table.column :content, :text
# table.column :published_at, :datetime
# table.column :created_at, :datetime
# end
#
# create_table :assertions do |table|
# table.column :subject_id, :integer
# table.column :predicate_id, :integer
# table.column :verb, :string
# table.column :status, :integer, :null => false, :default => 1
# table.column :true_count, :integer, :null => false, :default => 0
# table.column :false_count, :integer, :null => false, :default => 0
# table.column :created_at, :datetime
# table.column :updated_at, :datetime
# end
#execute "CREATE FULLTEXT INDEX FullText_Entities ON entities (text)"
end
class Entity < ActiveRecord::Base
validates_uniqueness_of :text, :scope => :kind
has_many :taggings
has_many :stories, :through => :taggings
has_many :as_subject, :foreign_key => 'subject_id', :class_name => 'Assertion'
has_many :as_predicate, :foreign_key => 'predicate_id', :class_name => 'Assertion'
end
class Tagging < ActiveRecord::Base
belongs_to :entity
belongs_to :story
end
class Story < ActiveRecord::Base
validates_uniqueness_of :url
require 'uri'
has_many :taggings
has_many :entities, :through => :taggings
def source
uri = URI.parse(url)
uri.host
end
end
class Assertion < ActiveRecord::Base
validates_presence_of :subject_id, :predicate_id, :verb
validates_uniqueness_of :subject_id, :scope => [:predicate_id, :verb]
belongs_to :subject, :class_name => 'Entity'
belongs_to :predicate, :class_name => 'Entity'
named_scope :true, :conditions => 'status = 1'
named_scope :false, :conditions => 'status = 0'
# igualA se utiliza con el término preferido de sujeto, sinonimoDe de predicado
# perteneceA para personas > organizaciones
VERBS = {'igualA' => 'tiene como sinónimo a',
'sinonimoDe' => 'es más conocido como',
'perteneceA' => 'pertenece a',
'tieneMiembro' => 'tiene como miembro a',
'parteDe' => 'es parte de',
'conocidoAntes' => 'era conocido antes como',
'compañeroDe' => 'es compañero de',
'resideEn' => 'reside en'
}
def text
VERBS[self.verb]
end
end