Changeset 6379
- Timestamp:
- 07/09/15 10:31:55 (9 years ago)
- Location:
- vlo/branches/vlo-3.3-oeaw/vlo-importer/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/AvailabilityPostProcessor.java
r6366 r6379 3 3 import java.util.ArrayList; 4 4 import java.util.List; 5 import java.util.Map; 5 6 6 7 /** … … 10 11 public class AvailabilityPostProcessor extends PostProcessorsWithVocabularyMap { 11 12 12 private static final Integer MAX_LENGTH = 20; 13 private static Map<String, String> availabilityMap; 14 15 private static final Integer MAX_LENGTH = 20; 13 16 private static final String OTHER_VALUE = "Other"; 17 14 18 15 19 @Override … … 31 35 } 32 36 33 @Override 34 protected String getMappingFileUrl() { 35 return MetadataImporter.config.getLicenseAvailabilityMapUrl(); 37 public Map<String, String> getVocabularyMap(){ 38 if(availabilityMap == null){ 39 availabilityMap = createControlledVocabularyMap(MetadataImporter.config.getLicenseAvailabilityMapUrl()); 40 } 41 42 return availabilityMap; 36 43 } 37 44 } -
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/LanguageCodePostProcessor.java
r6366 r6379 3 3 import java.util.ArrayList; 4 4 import java.util.List; 5 import java.util.Map; 5 6 import java.util.regex.Matcher; 6 7 import java.util.regex.Pattern; … … 14 15 15 16 private final static Logger LOG = LoggerFactory.getLogger(LanguageCodePostProcessor.class); 17 private static Map<String, String> languageNameVariantsMap = null; 16 18 17 19 protected static final String CODE_PREFIX = "code:"; … … 42 44 43 45 @Override 44 protected String getMappingFileUrl() { 45 return MetadataImporter.config.getLanguageNameVariantsUrl(); 46 } 46 protected Map<String, String> getVocabularyMap() { 47 if(languageNameVariantsMap == null){ 48 languageNameVariantsMap = createControlledVocabularyMap(MetadataImporter.config.getLanguageNameVariantsUrl()); 49 } 50 return languageNameVariantsMap; 51 } 47 52 48 53 -
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/NationalProjectPostProcessor.java
r6369 r6379 1 1 package eu.clarin.cmdi.vlo.importer; 2 2 3 import java.io.InputStream;4 3 import java.util.ArrayList; 5 4 import java.util.HashMap; … … 27 26 private final static Logger LOG = LoggerFactory.getLogger(NationalProjectPostProcessor.class); 28 27 28 private static Map<String, String> nationalProjectMap = null; 29 29 private static Map<Pattern, String> nationalProjectRegExpMap = null; 30 30 … … 58 58 } 59 59 60 @Override 61 protected Map<String, String> getVocabularyMap() { 62 if(nationalProjectMap == null){ 63 createControlledVocabularyMap(getMappingFileUrl()); 64 } 65 66 return nationalProjectMap; 67 } 68 60 69 private Map<Pattern, String> getRegExpMapping() { 61 70 if (nationalProjectRegExpMap == null) { 62 createControlledVocabularyMap( );71 createControlledVocabularyMap(getMappingFileUrl()); 63 72 } 64 73 return nationalProjectRegExpMap; 65 74 } 66 75 67 @Override76 68 77 protected String getMappingFileUrl() { 69 78 String projectsMappingFile = MetadataImporter.config.getNationalProjectMapping(); … … 76 85 return projectsMappingFile; 77 86 } 78 79 80 protected void createControlledVocabularyMap() {81 if(variantsMap == null){82 variantsMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);87 88 @Override 89 protected Map<String, String> createControlledVocabularyMap(String mapUrl) { 90 if(nationalProjectMap == null){ 91 nationalProjectMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); 83 92 } 84 93 … … 87 96 } 88 97 89 try { 90 // load records from file 91 // in the future this should be loaded from CLAVAS directly and the file only used as fallback 92 InputStream is = PostProcessorsWithVocabularyMap.class.getResourceAsStream(getMappingFileUrl()); 93 VariantsMap map = (VariantsMap) VLOMarshaller.unmarshal(is, VariantsMap.class); 98 VariantsMap map = getMappingFromFile(mapUrl); 94 99 95 for(Entry<String, List<Variant>> entry: map.getMap().entrySet()){ 96 for(Variant variant: entry.getValue()){ 97 if(variant.isRegExp()){ 98 nationalProjectRegExpMap.put(Pattern.compile(variant.getValue()), entry.getKey()); 99 }else{ 100 variantsMap.put(variant.getValue(), entry.getKey()); 101 } 102 } 103 } 104 } catch (Exception e) { 105 throw new RuntimeException("Cannot instantiate postProcessor:", e); 100 for(Entry<String, List<Variant>> entry: map.getMap().entrySet()){ 101 for(Variant variant: entry.getValue()){ 102 if(variant.isRegExp()){ 103 nationalProjectRegExpMap.put(Pattern.compile(variant.getValue()), entry.getKey()); 104 }else{ 105 nationalProjectMap.put(variant.getValue(), entry.getKey()); 106 } 107 } 106 108 } 107 } 108 109 110 return nationalProjectMap; 111 } 112 109 113 } -
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/OrganisationPostProcessor.java
r6366 r6379 3 3 import java.util.Arrays; 4 4 import java.util.List; 5 import java.util.Map; 5 6 6 7 public class OrganisationPostProcessor extends PostProcessorsWithVocabularyMap{ 7 8 8 9 10 private static Map<String, String> organisationNamesMap = null; 11 9 12 /** 10 13 * Splits values for organisation facet at delimiter ';' and replaces … … 30 33 31 34 @Override 32 protected String getMappingFileUrl() { 33 return MetadataImporter.config.getOrganisationNamesUrl(); 34 } 35 protected Map<String, String> getVocabularyMap() { 36 if(organisationNamesMap == null){ 37 organisationNamesMap = createControlledVocabularyMap(MetadataImporter.config.getOrganisationNamesUrl()); 38 } 39 return organisationNamesMap; 40 } 35 41 36 42 private String normalizeInputString(String value) { … … 41 47 return key.toLowerCase().replaceAll("-", " "); 42 48 } 49 50 43 51 44 52 -
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/PostProcessorsWithVocabularyMap.java
r6378 r6379 20 20 21 21 private final static Logger LOG = LoggerFactory.getLogger(PostProcessorsWithVocabularyMap.class); 22 23 protected static Map<String, String> variantsMap = null; 22 24 23 25 24 /* 26 * returns url of mappingFile25 * returns specific static map and should call createControlledVocabularyMap 27 26 */ 28 protected abstract String getMappingFileUrl();27 protected abstract Map<String, String> getVocabularyMap(); 29 28 30 @Override 31 public abstract List<String> process(String value); 29 30 protected Map<String, String> createControlledVocabularyMap(String mapUrl) { 31 VariantsMap map = getMappingFromFile(mapUrl); 32 return map.getInvertedMap(); 33 } 32 34 33 public Map<String, String> getVocabularyMap(){ 34 if(variantsMap == null){ 35 createControlledVocabularyMap(); 36 } 37 38 return variantsMap; 35 protected VariantsMap getMappingFromFile(String mapUrl){ 36 try { 37 38 LOG.info("Reading configuration file from: {}", mapUrl); 39 // load records from file 40 // in the future this should be loaded from CLAVAS directly and the file only used as fallback 41 InputStream is = PostProcessorsWithVocabularyMap.class.getResourceAsStream(mapUrl); 42 return (VariantsMap) VLOMarshaller.unmarshal(is, VariantsMap.class); 43 } catch (Exception e) { 44 throw new RuntimeException("Cannot instantiate postProcessor:", e); 45 } 39 46 } 40 41 protected void createControlledVocabularyMap() {42 try {43 44 LOG.info("Reading configuration file from: {}", getMappingFileUrl());45 // load records from file46 // in the future this should be loaded from CLAVAS directly and the file only used as fallback47 InputStream is = PostProcessorsWithVocabularyMap.class.getResourceAsStream(getMappingFileUrl());48 VariantsMap map = (VariantsMap) VLOMarshaller.unmarshal(is, VariantsMap.class);49 variantsMap = map.getInvertedMap();50 } catch (Exception e) {51 throw new RuntimeException("Cannot instantiate postProcessor:", e);52 }53 }54 47 55 48 // for debug purposes -
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/test/java/eu/clarin/cmdi/vlo/importer/AvailabilityPostProcessorTest.java
r6377 r6379 10 10 @Test 11 11 public void testLanguageCode() { 12 PostProcessor processor = new AvailabilityPostProcessor(); 13 ((AvailabilityPostProcessor)processor).printMap(); 12 PostProcessor processor = new AvailabilityPostProcessor(); 14 13 assertEquals("Free", processor.process("Apache Licence 2.0").get(0)); 15 14 assertEquals("Free", processor.process("Open Access").get(0));
Note: See TracChangeset
for help on using the changeset viewer.