lib/cultural_network/import/feature_data.rb
# ##################################################################### #
# Given an hpricot snippet, determine the writing system. (This may not always be possible.)
# To add another code, just put in in the array in the appropriate place. 
Given an hpricot snippet, determine the writing system. (This may not always be possible.)
To add another code, just put in in the array in the appropriate place.
Given an hpricot snippet determine the writing system . ( This may not always be possible . ) To add another code just put in in the array in the appropriate place .
def determine_writing_system(doc)
      writing_system_codes = {
        "latin" => ["pinyin", "wylie", "eng","romanized","wyl","pin","nep.no-diacritics"],
        "tibetan" => ["tib"],
        "chi_simplified" => ["chi.simplified"],
        "chi_traditional" => ["chi.traditional"],
        "nep_diacritics" => ["nep.diacritics"],
        "nepalese" => ["nep"]
      }
      writing_system_codes.keys.sort.each do |key|  
        writing_system_codes[key].each do |k|
          if(doc.attributes['scheme'] =~ /#{k}/)
            writing_system = WritingSystem.find_or_create_by_code(key)
            return writing_system.id 
          elsif(doc.attributes['type'] =~ /#{k}/)
              writing_system = WritingSystem.find_or_create_by_code(key)
              return writing_system.id
          elsif(doc.attributes['lang'] =~ /#{k}/)
            writing_system = WritingSystem.find_or_create_by_code(key)
            return writing_system.id
          end
        end
      end
      return nil 
    end
def determine_writing_system ( doc ) writing_system_codes = { "latin" => [ "pinyin" , "wylie" , "eng" , "romanized" , "wyl" , "pin" , "nep.no-diacritics" ] , "tibetan" => [ "tib" ] , "chi_simplified" => [ "chi.simplified" ] , "chi_traditional" => [ "chi.traditional" ] , "nep_diacritics" => [ "nep.diacritics" ] , "nepalese" => [ "nep" ] } writing_system_codes . keys . sort . each do | key | writing_system_codes [ key ] . each do | k | if ( doc . attributes [ 'scheme' ] =~ / #{ k } / ) writing_system = WritingSystem . find_or_create_by_code ( key ) return writing_system . id elsif ( doc . attributes [ 'type' ] =~ / #{ k } / ) writing_system = WritingSystem . find_or_create_by_code ( key ) return writing_system . id elsif ( doc . attributes [ 'lang' ] =~ / #{ k } / ) writing_system = WritingSystem . find_or_create_by_code ( key ) return writing_system . id end end end return nil end
Given an hpricot snippet, determine the writing system.
Given an hpricot snippet determine the writing system .
# sort the keys so latin comes before tibetan, otherwise, tib-wylie always matches on tibetan instead of latin # Match on scheme first, to weed out all the transliterations (e.g., wylie, pinyin, romanized) # Then try the type attribute, because some records use that instead # Then, if it still hasn't found a match, assume that the value in lang also describes # the writing system # If it hasn't matched anything yet, return nil
doc
<not_specific>