myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2555] branches/neiss: added skos model


From: noreply
Subject: [myexperiment-hackers] [2555] branches/neiss: added skos model
Date: Tue, 1 Feb 2011 11:29:16 -0500 (EST)

Revision
2555
Author
dgc
Date
2011-02-01 11:29:16 -0500 (Tue, 01 Feb 2011)

Log Message

added skos model

Modified Paths

Added Paths

Diff

Added: branches/neiss/app/models/concept.rb (0 => 2555)


--- branches/neiss/app/models/concept.rb	                        (rev 0)
+++ branches/neiss/app/models/concept.rb	2011-02-01 16:29:16 UTC (rev 2555)
@@ -0,0 +1,15 @@
+# myExperiment: app/models/concept.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class Concept < ActiveRecord::Base
+
+  acts_as_structured_data
+
+  def preferred_label
+    preferred_labels.first
+  end
+
+end
+

Modified: branches/neiss/app/models/vocabulary.rb (2554 => 2555)


--- branches/neiss/app/models/vocabulary.rb	2011-02-01 16:29:04 UTC (rev 2554)
+++ branches/neiss/app/models/vocabulary.rb	2011-02-01 16:29:16 UTC (rev 2555)
@@ -9,10 +9,11 @@
 
   belongs_to :user
 
-  has_many :tags, :dependent => :destroy
-
   validates_presence_of :title
+  validates_presence_of :prefix
 
+  validates_uniqueness_of :prefix
+
   format_attribute :description
 end
 

Added: branches/neiss/config/schema.d/skos.xml (0 => 2555)


--- branches/neiss/config/schema.d/skos.xml	                        (rev 0)
+++ branches/neiss/config/schema.d/skos.xml	2011-02-01 16:29:16 UTC (rev 2555)
@@ -0,0 +1,119 @@
+<?xml version="1.0"?>
+<schema>
+
+  <table name="vocabularies">
+
+    <column type="integer"  name="user_id"/>
+    <column type="string"   name="uri"/>
+    <column type="string"   name="title"/>
+    <column type="string"   name="prefix"/>
+    <column type="text"     name="description"/>
+    <column type="text"     name="description_html"/>
+    <column type="datetime" name="created_at"/>
+    <column type="datetime" name="updated_at"/>
+
+    <has-many target="concepts" dependent="destroy"/>
+
+  </table>
+  
+  <table name="concepts">
+
+    <column type="integer"  name="vocabulary_id"/>
+    <column type="text"     name="description"/>
+    <column type="text"     name="description_html"/>
+    <column type="datetime" name="created_at"/>
+    <column type="datetime" name="updated_at"/>
+
+    <belongs-to target="vocabularies"/>
+
+    <!-- Broader relations -->
+
+    <has-many target      = "broader_relations"
+              foreign_key = "object_concept_id"
+              class_name  = "ConceptRelation"
+              conditions  = "relation_type = 'broader'"/>
+
+    <has-many target      = "broader_concepts"
+              class_name  = "Concept"
+              through     = "broader_relations"
+              source      = "object_concept"/>
+
+    <!-- Narrower relations -->
+
+    <has-many target      = "narrower_relations"
+              foreign_key = "subject_concept_id"
+              class_name  = "ConceptRelation"
+              conditions  = "relation_type = 'broader'"/>
+
+    <has-many target      = "narrower_concepts"
+              class_name  = "Concept"
+              through     = "narrower_relations"
+              source      = "subject_concept"/>
+
+    <!-- Related relations -->
+
+    <has-many target      = "related_relations"
+              foreign_key = "subject_concept_id"
+              class_name  = "ConceptRelation"
+              conditions  = "relation_type = 'related'"/>
+
+    <has-many target      = "related_concepts"
+              class_name  = "Concept"
+              through     = "related_relations"
+              source      = "object_concept"/>
+
+    <!-- Labels -->
+
+    <has-many target="labels" dependent="destroy"/>
+
+    <has-many target      = "preferred_labels"
+              dependent   = "destroy"
+              class_name  = "Label"
+              foreign_key = "concept_id"
+              conditions  = "label_type = 'preferred'"/> 
+
+    <has-many target      = "alternate_labels"
+              dependent   = "destroy"
+              class_name  = "Label"
+              foreign_key = "concept_id"
+              conditions  = "label_type = 'alternate'"/> 
+
+    <has-many target      = "hidden_labels"
+              dependent   = "destroy"
+              class_name  = "Label"
+              foreign_key = "concept_id"
+              conditions  = "label_type = 'hidden'"/> 
+
+  </table>
+
+  <table name="concept_relations">
+
+    <column type="integer"  name="subject_concept_id"/>
+    <column type="integer"  name="object_concept_id"/>
+    <column type="string"   name="relation_type"/>
+
+    <belongs-to target      = "subject_concepts"
+                class_name  = "Concept"
+                foreign_key = "subject_concept_id"/>
+
+    <belongs-to target      = "object_concepts"
+                class_name  = "Concept"
+                foreign_key = "object_concept_id"/>
+
+  </table>
+
+  <table name="labels">
+
+    <column type="string"   name="text"/>
+    <column type="string"   name="label_type"/>
+    <column type="string"   name="language"/>
+    <column type="integer"  name="concept_id"/>
+    <column type="integer"  name="vocabulary_id"/>
+
+    <belongs-to target="vocabularies"/>
+    <belongs-to target="concepts"/>
+
+  </table>
+
+</schema>
+

Added: branches/neiss/lib/load_vocabulary.rb (0 => 2555)


--- branches/neiss/lib/load_vocabulary.rb	                        (rev 0)
+++ branches/neiss/lib/load_vocabulary.rb	2011-02-01 16:29:16 UTC (rev 2555)
@@ -0,0 +1,66 @@
+# myExperiment: lib/load_vocabulary.rb
+#
+# Copyright (c) 2010 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+module LoadVocabulary
+
+  def self.load_vocabulary
+
+    file_name = ENV['FILE']
+
+    if file_name.nil?
+      puts "Missing file name."
+      return
+    end
+
+    data = ""
+
+    exising_vocabulary = Vocabulary.find_by_uri(data["uri"])
+    exising_vocabulary.destroy if exising_vocabulary
+
+    vocabulary = Vocabulary.create(
+        :uri         => data["uri"],
+        :title       => data["title"],
+        :prefix      => data["prefix"],
+        :description => data["description"])
+
+    data["concepts"].each do |concept|
+      
+      c = Concept.create(:description => concept["description"])
+
+      c.labels << Label.create(
+          :vocabulary => vocabulary,
+          :text       => concept["label"],
+          :label_type => 'preferred',
+          :language   => 'en')
+
+      if concept["alternate"]
+        concept["alternate"].each do |alternate|
+          
+          c.labels << Label.create(
+              :vocabulary => vocabulary,
+              :text       => alternate,
+              :label_type => 'alternate',
+              :language   => 'en')
+        end
+      end
+
+      if concept["hidden"]
+        concept["hidden"].each do |hidden|
+
+          c.labels << Label.create(
+              :vocabulary => vocabulary,
+              :text       => hidden,
+              :label_type => 'hidden',
+              :language   => 'en')
+        end
+      end
+
+      vocabulary.concepts << c
+
+    end
+  end
+
+end
+

reply via email to

[Prev in Thread] Current Thread [Next in Thread]