Changeset 6729


Ignore:
Timestamp:
11/02/15 15:22:55 (9 years ago)
Author:
davor.ostojic@oeaw.ac.at
Message:

PostProcessorWithVocabulary? implements NormalizaitonService?

Location:
vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIData.java

    r6400 r6729  
    4242   
    4343    private String profileId;
    44     private String profileName;
    4544    private String originalResourceType;
    4645
     
    162161                return profileId;               
    163162        }
    164 
    165         public String getProfileName() {
    166                 return profileName;
    167         }
    168 
    169         public void setProfileName(String profileName) {
    170                 this.profileName = profileName;
    171         }
    172163       
    173164        public String getOriginalResourceType() {
     
    179170        }
    180171       
    181        
    182172}
  • vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIParserVTDXML.java

    r6723 r6729  
    6060            LOG.error("Problems mapping facets for file: {}", file.getAbsolutePath());
    6161        }
    62 
    63         List<String> profileName = (postProcessors.get(FacetConstants.FIELD_CLARIN_PROFILE)).process(profileId);
    64         cmdiData.setProfileName(profileName.get(0));
     62       
    6563        nav.toElement(VTDNav.ROOT);
    6664        processResources(cmdiData, nav);
  • vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/MetadataImporter.java

    r6715 r6729  
    8989        POST_PROCESSORS.put(FacetConstants.FIELD_CLARIN_PROFILE, new CMDIComponentProfileNamePostProcessor());
    9090        POST_PROCESSORS.put(FacetConstants.FIELD_RESOURCE_CLASS, new ResourceClassPostProcessor());
    91         POST_PROCESSORS.put(FacetConstants.FIELD_PROFILE, new ProfileNamePostProcessor());
    9291    }
    9392
     
    435434       
    436435       
    437         //Add profileId & profileName & original resource type
    438         solrDocument.addField("profileName", cmdiData.getProfileName());
    439         solrDocument.addField("profileId", cmdiData.getProfileId());
     436        //Add profileId & original resource type
     437        solrDocument.addField("_componentProfileId", cmdiData.getProfileId());
    440438        solrDocument.addField("resourceClassOrig", cmdiData.getOriginalResourceType());
    441439       
  • vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/NationalProjectPostProcessor.java

    r6715 r6729  
    22
    33import java.util.ArrayList;
    4 import java.util.HashMap;
    54import java.util.List;
    6 import java.util.Map;
    7 import java.util.Map.Entry;
    8 import java.util.TreeMap;
    9 import java.util.regex.Matcher;
    10 import java.util.regex.Pattern;
    115
    126import org.slf4j.Logger;
    137import org.slf4j.LoggerFactory;
    14 
    15 import eu.clarin.cmdi.vlo.pojo.Variant;
    16 import eu.clarin.cmdi.vlo.pojo.VariantsMap;
    178
    189/**
  • vlo/branches/vlo-3.3-oeaw/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/PostProcessorsWithVocabularyMap.java

    r6725 r6729  
    44import java.io.FileInputStream;
    55import java.io.InputStream;
    6 import java.util.List;
    76import java.util.Map;
    8 import java.util.Map.Entry;
    97
    108import org.slf4j.Logger;
    119import org.slf4j.LoggerFactory;
    1210
     11import eu.clarin.cmdi.vlo.normalization.NormalizationService;
     12import eu.clarin.cmdi.vlo.normalization.NormalizationVocabulary;
     13import eu.clarin.cmdi.vlo.normalization.VocabularyEntry;
    1314import eu.clarin.cmdi.vlo.pojo.VariantsMap;
    14 import eu.clarin.cmdi.vlo.pojo.VocabularyEntry;
    1515import eu.clarin.cmdi.vlo.transformers.VariantsMapMarshaller;
    1616
     
    2525 */
    2626
    27 public abstract class PostProcessorsWithVocabularyMap implements PostProcessor{
    28        
    29          private final static Logger _logger = LoggerFactory.getLogger(PostProcessorsWithVocabularyMap.class);
    30          
    31          private List<VocabularyEntry> map = null;
    32                  
    33        
    34          /*
    35           * This method is used for normalization of facet values based on normalization maps.
    36           * In case that value is not in the map, the input value is returned.
    37           *
    38           * @param value - original value from record
    39           * @return normalized value if there is a match otherwise original value
    40           *
    41           */
    42          public String normalize(String value){
    43                  return normalize(value, value);
    44          }
    45          
    46          
    47          /*
    48           * This method is used for normalization of facet values based on normalization maps.
    49           * With second parameter user can specify what to return in case when value is not in normalization map (special case for NationalProject facet).
    50           * 
    51           * @param value - original value from record
    52           * @param fallBackValue - value to be returned in case of no match
    53           * @return normalized value if there is a match otherwise returns what is specified with 2nd parameter
    54           *
    55           */
    56          public String normalize(String value, String fallBackValue){
    57                  //init
    58                  if(map == null)
    59                          createMap();
    60                  
    61                  int ind = map.indexOf(value);
    62                  return (ind != -1)? map.get(ind).getNormalizedValue() : fallBackValue;
    63          }
    64          
    65          public  Map<String, String> getCrossMappings(String value){
    66                  
    67                  //init
    68                  if(map == null)
    69                          createMap();
    70                  
    71                  int ind = map.indexOf(value);
    72                  return (ind != -1)? map.get(ind).getCrossMap() : null;
    73          }
    74          
    75          public abstract String getNormalizationMapURL();
    76          
    77          private void createMap(){
    78                  VariantsMap varinatsRawMap = getMappingFromFile(getNormalizationMapURL());
    79                  map = varinatsRawMap.getMap();
    80                  
    81                  printMap();
    82          }
    83          
    84          protected VariantsMap getMappingFromFile(String mapUrl){
    85                  try {
    86                        
    87                         _logger.info("Reading vocabulary file from: {}", mapUrl);
    88                     // load records from file
    89                         // in the future this should be loaded from CLAVAS directly and the file only used as fallback
    90                        
    91                         //InputStream is = PostProcessorsWithVocabularyMap.class.getClassLoader().getResourceAsStream(mapUrl);
    92                         InputStream is = new FileInputStream(new File(mapUrl));
     27public abstract class PostProcessorsWithVocabularyMap implements PostProcessor, NormalizationService {
    9328
    94                        
    95                         return VariantsMapMarshaller.unmarshal(is);                     
    96              } catch (Exception e) {
    97             throw new RuntimeException("Cannot instantiate postProcessor:", e);
    98          }
    99          }
    100          
    101          
    102          // for debug
    103          public void printMap(){
    104                  _logger.info("map contains {} entries", map.size());
    105                  for(VocabularyEntry entry: map)
    106                          _logger.info(entry.toString());
    107                
    108          }
     29        private final static Logger _logger = LoggerFactory.getLogger(PostProcessorsWithVocabularyMap.class);
     30
     31        private NormalizationVocabulary vocabulary;
     32
     33        public String normalize(String value) {
     34                return normalize(value, value);
     35        }
     36
     37        public String normalize(String value, String fallBackValue) {
     38                if (vocabulary == null)
     39                        initVocabulary();
     40
     41                return vocabulary.normalize(value, fallBackValue);
     42        }
     43
     44        public Map<String, String> getCrossMappings(String value) {
     45                if (vocabulary == null)
     46                        initVocabulary();
     47
     48                return vocabulary.getCrossMappings(value);
     49        }
     50
     51        public abstract String getNormalizationMapURL();
     52
     53        private void initVocabulary() {
     54                VariantsMap varinatsRawMap = getMappingFromFile(getNormalizationMapURL());
     55                vocabulary = varinatsRawMap.getMap();
     56
     57                printMap();
     58        }
     59
     60        protected VariantsMap getMappingFromFile(String mapUrl) {
     61                try {
     62
     63                        _logger.info("Reading vocabulary file from: {}", mapUrl);
     64                        // load records from file
     65                        // in the future this should be loaded from CLAVAS directly and the
     66                        // file only used as fallback
     67
     68                        // InputStream is =
     69                        // PostProcessorsWithVocabularyMap.class.getClassLoader().getResourceAsStream(mapUrl);
     70                        InputStream is = new FileInputStream(new File(mapUrl));
     71
     72                        return VariantsMapMarshaller.unmarshal(is);
     73                } catch (Exception e) {
     74                        throw new RuntimeException("Cannot instantiate postProcessor:", e);
     75                }
     76        }
     77
     78        // for debug
     79        public void printMap() {
     80                _logger.info("map contains {} entries", vocabulary.getEntries().length);
     81                for(int i = 0; i < vocabulary.getEntries().length; i++)
     82                        _logger.info(vocabulary.getEntries()[i].toString());
     83                       
     84
     85        }
    10986}
Note: See TracChangeset for help on using the changeset viewer.