Changeset 1759


Ignore:
Timestamp:
02/21/12 12:11:39 (12 years ago)
Author:
teckart
Message:

*added utility method for creation of reverse map out of CMDI file
*extended extraction of language code by using language names

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo_webapp/src/main/java/eu/clarin/cmdi/vlo/importer/LanguageCodePostProcessor.java

    r1546 r1759  
    3030    private Map<String, String> threeLetterCodesMap;
    3131    private Map<String, String> silToIso639Map;
     32    private Map<String, String> languageNameToIso639Map;
     33    private Map<String, String> iso639ToLanguageNameMap;   
    3234
    3335    /**
    34      * Returns the lanaguage name based on the mapping defined in the CMDI components: See http://trac.clarin.eu/ticket/40 for the mapping.
     36     * Returns the language name based on the mapping defined in the CMDI components: See http://trac.clarin.eu/ticket/40 for the mapping.
    3537     * If no mapping is found the original value is returned.
    3638     */
     
    6971                    result = isoCode;
    7072                }
     73            } else {                            // guessing based on language name
     74                if(getLanguageNameToIso639Map().containsKey(value))
     75                        result = getLanguageNameToIso639Map().get(value).toLowerCase();
    7176            }
    7277        }
    7378        return result;
     79    }
     80   
     81    public String getLanguageNameForLanguageCode(String langCode) {
     82        String result = getIso639ToLanguageNameMap().get(langCode);
     83       
     84        if(result == null)
     85                result = langCode;
     86       
     87        return result;
    7488    }
    7589
     
    94108        return threeLetterCodesMap;
    95109    }
    96 
     110   
     111    private Map<String, String> getLanguageNameToIso639Map() {
     112        if (languageNameToIso639Map == null) {
     113                        languageNameToIso639Map = createReverseCodeMap(Configuration.getInstance().getLanguage3LetterCodeComponentUrl());
     114        }
     115        return languageNameToIso639Map;
     116    }
     117   
     118    private Map<String, String> getIso639ToLanguageNameMap() {
     119        if (iso639ToLanguageNameMap == null) {
     120                iso639ToLanguageNameMap = createCodeMap(Configuration.getInstance().getLanguage3LetterCodeComponentUrl());
     121        }
     122       
     123        return iso639ToLanguageNameMap;
     124    }
     125   
    97126    private Map<String, String> createCodeMap(String url) {
    98127        LOG.debug("Creating language code map.");
    99128        try {
    100129            Map<String, String> result = CommonUtils.createCMDIComponentItemMap(url);
     130            return result;
     131        } catch (Exception e) {
     132            throw new RuntimeException("Cannot instantiate postProcessor:", e);
     133        }
     134    }
     135   
     136    private Map<String, String> createReverseCodeMap(String url) {
     137        LOG.debug("Creating language code map.");
     138        try {
     139            Map<String, String> result = CommonUtils.createReverseCMDIComponentItemMap(url);
    101140            return result;
    102141        } catch (Exception e) {
Note: See TracChangeset for help on using the changeset viewer.