semantically-taggable 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +2 -1
- data/README.rdoc +58 -17
- data/lib/railtie.rb +14 -0
- data/spec/debug.log +10645 -0
- data/spec/spec_helper.rb +2 -0
- metadata +4 -4
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,29 +1,70 @@
|
|
1
1
|
= semantically-taggable
|
2
2
|
|
3
|
-
A tagging system, based *extremely* heavily on acts_as_taggable_on (to the point of being a little grubby
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
A tagging system, based *extremely* heavily on acts_as_taggable_on (to the point of being a little grubby, so please,
|
4
|
+
if you need a general non-semantic tagging system, see Mike Bleigh's excellent
|
5
|
+
https://github.com/mbleigh/acts-as-taggable-on), but which moves the <tt>acts-as-taggable-on</tt> 'context' concept into
|
6
|
+
semantic tagging _schemes_. So, for example, "Environment" in a +green_tags+ scheme is not semantically equivalent
|
7
|
+
to "Environment" in a +sysadmin_tags+ tagging scheme.
|
8
|
+
|
9
|
+
It also adds support for (poly)hierarchical thesaurus/taxonomy with SKOS import support and hierarchy tagging.
|
10
|
+
For example, if you had a hierarchical taxonomy called +animal_classifications+ which had a topic hierarchy
|
11
|
+
Animals > Marsupials > Kangaroo, the following code would create a kangaroo called "Skippy" and then retrieve him
|
12
|
+
via hierarchy tagging:
|
13
|
+
|
14
|
+
class Animal < ActiveRecord::Base
|
15
|
+
semantically_taggable :animal_classifications
|
16
|
+
end
|
17
|
+
|
18
|
+
animal = Animal.create(:name => 'Skippy', :animal_classification_list => 'Kangaroo')
|
19
|
+
|
20
|
+
Animal.tagged_with('Marsupials', :on => :animal_classifications)
|
21
|
+
=> #<Animal id: 1, Name: "Skippy">
|
22
|
+
|
23
|
+
Also removes tagger/related capability, Postgres support and
|
7
24
|
restricts compatibility to Rails 3 and above - so you need to be sure you need semantic tagging before using this!
|
8
25
|
|
9
26
|
== Using semantically-taggable
|
10
27
|
|
11
|
-
|
28
|
+
Add to your Rails 3 or higher application's Gemfile:
|
12
29
|
|
13
30
|
gem "semantically-taggable"
|
14
31
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
32
|
+
You'll need to run the rails migration generator:
|
33
|
+
|
34
|
+
rails g semantically_taggable:migration
|
35
|
+
|
36
|
+
This will create a migration in your rails project. Run with
|
37
|
+
|
38
|
+
rake db:migrate
|
39
|
+
|
40
|
+
This gem is purposely less ad-hoc than <tt>acts-as-taggable-on</tt>. All tags must exist in a <tt>SemanticallyTaggable::Scheme</tt>.
|
41
|
+
This means you'll need to add schemes to your database before you can tag.
|
42
|
+
The easiest way to do this is by using <tt>rake db:seed</tt>. An example <tt>db/seeds.rb</tt> file
|
43
|
+
may help here:
|
44
|
+
|
45
|
+
SemanticallyTaggable::Scheme.create(
|
46
|
+
[
|
47
|
+
{
|
48
|
+
:name => 'taxonomy_topics', :meta_name => 'DC.subject', :meta_scheme => 'MyTaxonomy.Topic',
|
49
|
+
:description => 'A polyhierarchical taxonomy', :delimiter => ';', :polyhierarchical => true
|
50
|
+
},
|
51
|
+
{
|
52
|
+
:name => 'keywords', :meta_name => 'keywords',
|
53
|
+
:description => 'Folksonomic keyword taggings'
|
54
|
+
},
|
55
|
+
]
|
56
|
+
)
|
57
|
+
|
58
|
+
== Important notes for indirect tagging support in hierarchical schemes
|
59
|
+
|
60
|
+
You'll need to import your taxonomy/thesaurus first. Grab a handy SKOS file which your favourite tool has produced,
|
61
|
+
and import to a scheme (which must be marked polyhierarchical) as follows:
|
62
|
+
|
63
|
+
rake import:skos[my_scheme_topics,db/my_skos_file.rdf]
|
64
|
+
|
65
|
+
This will create your hierarchy, but to enable indirect tagging support, you'll also need
|
66
|
+
|
67
|
+
rake import:refresh_closure
|
27
68
|
|
28
69
|
== Contributing to semantically-taggable
|
29
70
|
|
data/lib/railtie.rb
CHANGED
@@ -6,5 +6,19 @@ module SemanticallyTaggable
|
|
6
6
|
rake_tasks do
|
7
7
|
load File.join(File.dirname(__FILE__), 'tasks/import.rake')
|
8
8
|
end
|
9
|
+
|
10
|
+
unless defined? SEMANTICALLYTAGGABLE_SPECRUNNING
|
11
|
+
# No idea why this loads too late if it's a railtie initializer
|
12
|
+
ActiveSupport.on_load :active_record do
|
13
|
+
# Workaround for semantically-taggable's habtm
|
14
|
+
database_yml = File.expand_path('config/database.yml')
|
15
|
+
if File.exists?(database_yml)
|
16
|
+
active_record_configuration = YAML.load_file(database_yml)[Rails.env]
|
17
|
+
ActiveRecord::Base.establish_connection(active_record_configuration)
|
18
|
+
else
|
19
|
+
raise "Please create #{database_yml} first to configure your database."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
9
23
|
end
|
10
24
|
end
|