lib/cultural_network/import/feature_data.rb
# ##################################################################### #
# Given a snippet of XML defining a feature name, extract the secondary feature names, 
# create FeatureName objects for them to tie them to their parent FeatureName, and
# call this method again recursively if they contain a transliteration of their own
Given a snippet of XML defining a feature name, extract the secondary feature names,
create FeatureName objects for them to tie them to their parent FeatureName, and
call this method again recursively if they contain a transliteration of their own
Given a snippet of XML defining a feature name extract the secondary feature names create FeatureName objects for them to tie them to their parent FeatureName and call this method again recursively if they contain a transliteration of their own
def extract_secondary_feature_names(doc, feature, primary_feature_name)
      transliterations = (doc/'/transliteration|/altspell') 
      transliterations.each do |transliteration|
        fn = FeatureName.new
        fn.feature_id = feature.id
        fn.name = extract_geogname(transliteration)
        fn.language_id = primary_feature_name.language_id 
        fn.writing_system_id = determine_writing_system(transliteration)
        raise "Secondary FeatureName not saved!" unless fn.save
        set_timespan(transliteration, fn)
        extract_citations(transliteration, fn)
        fnr = FeatureNameRelation.new
        fnr.child_node_id = fn.id
        fnr.parent_node_id = primary_feature_name.id
        if(transliteration.attributes['type'] == 'orthographic')
          fnr.is_orthographic = true
          fnr.orthographic_system_id = OrthographicSystem.find_or_create_by_code(transliteration.attributes['scheme']).id
        end
        if(transliteration.attributes['type'] == 'phonetic')
          fnr.is_phonetic = true
          fnr.phonetic_system_id = PhoneticSystem.find_or_create_by_code(transliteration.attributes['scheme']).id
        end
        if(transliteration.name == 'altspell')
          fnr.is_alt_spelling = true
          fnr.alt_spelling_system_id = AltSpellingSystem.find_or_create_by_code(transliteration.attributes['type']).id
        end
        raise "FeatureNameRelation not saved!" unless fnr.save
        set_timespan(transliteration, fnr)
        extract_citations(transliteration, fnr)
        if(transliteration/'transliteration')
          secondary_fnames = extract_secondary_feature_names(transliteration, feature, fn) 
        end
      end
    end
def extract_secondary_feature_names ( doc , feature , primary_feature_name ) transliterations = ( doc / '/transliteration|/altspell' ) transliterations . each do | transliteration | fn = FeatureName . new fn . feature_id = feature . id fn . name = extract_geogname ( transliteration ) fn . language_id = primary_feature_name . language_id fn . writing_system_id = determine_writing_system ( transliteration ) raise "Secondary FeatureName not saved!" unless fn . save set_timespan ( transliteration , fn ) extract_citations ( transliteration , fn ) fnr = FeatureNameRelation . new fnr . child_node_id = fn . id fnr . parent_node_id = primary_feature_name . id if ( transliteration . attributes [ 'type' ] == 'orthographic' ) fnr . is_orthographic = true fnr . orthographic_system_id = OrthographicSystem . find_or_create_by_code ( transliteration . attributes [ 'scheme' ] ) . id end if ( transliteration . attributes [ 'type' ] == 'phonetic' ) fnr . is_phonetic = true fnr . phonetic_system_id = PhoneticSystem . find_or_create_by_code ( transliteration . attributes [ 'scheme' ] ) . id end if ( transliteration . name == 'altspell' ) fnr . is_alt_spelling = true fnr . alt_spelling_system_id = AltSpellingSystem . find_or_create_by_code ( transliteration . attributes [ 'type' ] ) . id end raise "FeatureNameRelation not saved!" unless fnr . save set_timespan ( transliteration , fnr ) extract_citations ( transliteration , fnr ) if ( transliteration / 'transliteration' ) secondary_fnames = extract_secondary_feature_names ( transliteration , feature , fn ) end end end
Given a snippet of XML defining a feature name, extract the secondary feature names,
create FeatureName objects for them to tie them to their parent FeatureName, and
call this method again recursively if they contain a transliteration of their own
Given a snippet of XML defining a feature name extract the secondary feature names create FeatureName objects for them to tie them to their parent FeatureName and call this method again recursively if they contain a transliteration of their own
# only get the top level transliterations, not *their* transliterations # altspells are also treated as a FeatureName in their own right... treat # them just like a <transliteration> element # a transliteration has the same language as its parent  # now relate this fn to its parent feature_name # Is it orthographic, and if so what's the system? # Is it phonetic, and if so, what's the system? # Is it an altspelling, and if so, what's the system?  # Is it a translation?  # There are no translations in the current data set, so I'm not writing this in # Does this FeatureName contain a translation or transliteration? # Call this method recursively if any of these transliterations have their own transliterations
doc
<not_specific>
feature
<not_specific>
primary_feature_name
<not_specific>