Skip to content

Commit

Permalink
Moved annotation values out of alignable annotations due to bug with …
Browse files Browse the repository at this point in the history
…time slot overlap
  • Loading branch information
Aaron Hunter committed Mar 11, 2012
1 parent 0c1610e commit 68dd7a2
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/elan_parser.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ElanParser
module DB
autoload :AlignableAnnotation, 'elan_parser/db/db_alignable_annotation'
autoload :AnnotationValue, 'elan_parser/db/db_annotation_value'
autoload :AlignableAnnotationTimeSlot, 'elan_parser/db/db_alignable_annotation_time_slot'
autoload :AnnotationControlledVocabularyDocument, 'elan_parser/db/db_annotation_controlled_vocabulary_document'
autoload :AnnotationDocumentConstraint, 'elan_parser/db/db_annotation_document_constraint'
Expand Down
2 changes: 2 additions & 0 deletions lib/elan_parser/db/db_alignable_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class AlignableAnnotation < ActiveRecord::Base

has_one :alignable_annotation_time_slot, :dependent => :destroy
has_one :annotation, :dependent => :destroy

belongs_to :annotation_value
end
end
end
11 changes: 11 additions & 0 deletions lib/elan_parser/db/db_annotation_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'active_record'

module ElanParser
module DB
class AnnotationValue < ActiveRecord::Base
self.table_name = 'elan_parser_annotation_values'

has_many :alignable_annotations
end
end
end
2 changes: 1 addition & 1 deletion lib/elan_parser/xml/xml_build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def alignable_annotation(annotation_node, annotation, time_slot_ref)
alignable_annotation_node["TIME_SLOT_REF2"] = "ts" + ts2_id

annotation_value_node = Nokogiri::XML::Node.new("ANNOTATION_VALUE", @elan_parser_xml)
annotation_value_node.content = annotation.alignable_annotation.annotation_value
annotation_value_node.content = annotation.alignable_annotation.annotation_value.value

alignable_annotation_node.add_child(annotation_value_node)
annotation_node.add_child(alignable_annotation_node)
Expand Down
10 changes: 8 additions & 2 deletions lib/elan_parser/xml/xml_save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,19 @@ def create_tier(happymapper_tier)
end

def create_alignable_annotation(happymapper_alignable_annotation)
alignable_annotation = ElanParser::DB::AlignableAnnotation.find_or_create_by_annotation_value(
:annotation_value => happymapper_alignable_annotation.annotation_value
alignable_annotation = ElanParser::DB::AlignableAnnotation.create(
:annotation_value => create_or_return_annotation_value(happymapper_alignable_annotation)
)

return alignable_annotation
end

def create_or_return_annotation_value(happymapper_alignable_annotation)
return ElanParser::DB::AnnotationValue.find_or_create_by_annotation_value(
:annotation_value => happymapper_alignable_annotation.annotation_value
)
end

def create_annotation_document(doc, file_name)
annotation_document = ElanParser::DB::AnnotationDocument.create(
:author => doc.author,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require 'rails/generators/migration'

module ElanParser
module Generators
class AnnotationFixGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../../templates', __FILE__)
desc "Add the migrations"

def self.next_migration_number(path)
unless @prev_migration_nr
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
else
@prev_migration_nr += 1
end
@prev_migration_nr.to_s
end

def copy_migrations
migration_template "elan_parser_migration_to_06.rb", "db/migrate/elan_parser_migration_to_06.rb"
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class ElanParserMigrationTo06 < ActiveRecord::Migration
def self.up
drop_table :elan_parser_alignable_annotations

create_table :elan_parser_alignable_annotations do |t|
t.column :svg_ref, :string
t.column :ext_ref, :string
t.belongs_to :annotation_value
end

create_table :elan_parser_annotation_values do |t|
t.column :annotation_value, :text
end
end
end

0 comments on commit 68dd7a2

Please sign in to comment.