lib/cultural_network/import/feature_data.rb
# ##################################################################### #
# create and save the FeatureRelation object(s) from this hpricot document
# this will need to throw an error if the parent object doesn't exist yet
create and save the FeatureRelation object(s) from this hpricot document
this will need to throw an error if the parent object doesn't exist yet
create and save the FeatureRelation object ( s ) from this hpricot document this will need to throw an error if the parent object doesn ' t exist yet
def extract_feature_relations(hpricot_doc, feature)
      doc = hpricot_doc
      if(doc/'/feature/frel')
        fr_array = (doc/'/feature/frel')
        fr_array.each do |fr|
          feature_relation = FeatureRelation.new()
          target_pid = (fr/'extref')[0].attributes['href']
          target_feature = Feature.find_or_create_by_pid(target_pid)
          feature_relation.child_node_id = feature.id
          feature_relation.parent_node_id = target_feature.id
          target_role = fr.attributes['role']
          if target_role != 'partof'
            feature_relation.role = target_role.underscore
          end
          feature_relation.perspective = @current_perspective
          raise "FeatureRelation not saved!" unless feature_relation.save
          set_timespan(fr, feature_relation)
          extract_citations(fr, feature_relation)
        end
      end
    end
def extract_feature_relations ( hpricot_doc , feature ) doc = hpricot_doc if ( doc / '/feature/frel' ) fr_array = ( doc / '/feature/frel' ) fr_array . each do | fr | feature_relation = FeatureRelation . new ( ) target_pid = ( fr / 'extref' ) [ 0 ] . attributes [ 'href' ] target_feature = Feature . find_or_create_by_pid ( target_pid ) feature_relation . child_node_id = feature . id feature_relation . parent_node_id = target_feature . id target_role = fr . attributes [ 'role' ] if target_role != 'partof' feature_relation . role = target_role . underscore end feature_relation . perspective = @current_perspective raise "FeatureRelation not saved!" unless feature_relation . save set_timespan ( fr , feature_relation ) extract_citations ( fr , feature_relation ) end end end
create and save the FeatureRelation object(s) from this hpricot document
this will need to throw an error if the parent object doesn't exist yet
create and save the FeatureRelation object ( s ) from this hpricot document this will need to throw an error if the parent object doesn ' t exist yet
# Is there a frel section in this document? #puts '------------' #puts 'Target Role is :: ' + target_role #puts '------------' # "partof" and "contains" are the default (child_node_id and parent_node_id) #type = FeatureRelationType.find_or_create_by_code(target_role) # Set (and save) the FeatureRelationType name #type.update_attribute(:name, target_role) #feature_relation.feature_relation_type_id = type.id #Perspective.find_or_create_by_code(@current_perspective_code)
hpricot_doc
<not_specific>
feature
<not_specific>