Changeset 6311


Ignore:
Timestamp:
06/19/15 13:58:05 (9 years ago)
Author:
Twan Goosen
Message:

added support for derived value facets
refs #770

Location:
vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/CMDIParserVTDXML.java

    r6310 r6311  
    268268        setNameSpace(ap);
    269269        ap.selectXPath(pattern);
    270        
     270
    271271        boolean matchedPattern = false;
    272272        int index = ap.evalXPath();
     
    287287            }
    288288
    289             final List<String> valueList = postProcess(config.getName(), value);
    290             insertFacetValues(config.getName(), valueList, cmdiData, languageCode, allowMultipleValues, config.isCaseInsensitive());
     289            final List<String> values = postProcess(config.getName(), value);
     290            insertFacetValues(config.getName(), values, cmdiData, languageCode, allowMultipleValues, config.isCaseInsensitive());
     291
     292            // insert post-processed values into derived facet(s) if configured
     293            for (String derivedFacet : config.getDerivedFacets()) {
     294                final List<String> derivedValues = new ArrayList<String>();
     295                for (String postProcessedValue : values) {
     296                    derivedValues.addAll(postProcess(derivedFacet, postProcessedValue));
     297                }
     298                insertFacetValues(derivedFacet, derivedValues, cmdiData, languageCode, allowMultipleValues, config.isCaseInsensitive());
     299            }
     300
    291301            index = ap.evalXPath();
    292302
  • vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/FacetConceptMapping.java

    r6201 r6311  
    1515import javax.xml.bind.annotation.XmlRootElement;
    1616
    17 
    1817/**
    1918 * Corresponds to the facet concepts file.
    20  *
    21  * This class holds the mapping of facet name -> facetConcepts/patterns
    22  * A facetConcept is a ISOcat conceptLink e.g.: http://www.isocat.org/datcat/DC-2544
    23  * the conceptLink will be analysed and translated into a valid Xpath expression to extract data out of the metadata.
    24  * Valid xpath expression e.g. /c:CMD/c:Header/c:MdSelfLink/text(), the 'c' namespace will be mapped to http://www.clarin.eu/cmd/ in the parser.
    25  * A pattern is an xpath expression used directly on the metadata. Use patterns only when a conceptLink does not suffice.
     19 *
     20 * This class holds the mapping of facet name -> facetConcepts/patterns A
     21 * facetConcept is a ISOcat conceptLink e.g.:
     22 * http://www.isocat.org/datcat/DC-2544 the conceptLink will be analysed and
     23 * translated into a valid Xpath expression to extract data out of the metadata.
     24 * Valid xpath expression e.g. /c:CMD/c:Header/c:MdSelfLink/text(), the 'c'
     25 * namespace will be mapped to http://www.clarin.eu/cmd/ in the parser. A
     26 * pattern is an xpath expression used directly on the metadata. Use patterns
     27 * only when a conceptLink does not suffice.
    2628 *
    2729 */
     
    4244        this.facetConcepts = facetConcepts;
    4345    }
    44    
     46
    4547    public Map<String, FacetConcept> getFacetConceptMap() {
    46         Map<String, FacetConcept> facetConceptMap = new HashMap<String, FacetConcept>();
    47         for(FacetConcept facet : getFacetConcepts())
    48                 facetConceptMap.put(facet.getName(), facet);
    49        
    50         return facetConceptMap;
    51     }
    52    
     48        Map<String, FacetConcept> facetConceptMap = new HashMap<String, FacetConcept>();
     49        for (FacetConcept facet : getFacetConcepts()) {
     50            facetConceptMap.put(facet.getName(), facet);
     51        }
     52
     53        return facetConceptMap;
     54    }
     55
    5356    public void check() {
    5457        for (FacetConcept facetConcept : getFacetConcepts()) {
     
    5659                AcceptableContext acceptableContext = facetConcept.getAcceptableContext();
    5760                RejectableContext rejectableContext = facetConcept.getRejectableContext();
    58                 if (acceptableContext.includeAny() && rejectableContext.includeAny())
    59                     LOG.error("Error: any context is both acceptable and rejectable for facet '"+facetConcept.getName()+"'");
    60                 if (acceptableContext.includeEmpty() && rejectableContext.includeEmpty())
    61                     LOG.error("Error: empty context is both acceptable and rejectable for facet '"+facetConcept.getName()+"'");
     61                if (acceptableContext.includeAny() && rejectableContext.includeAny()) {
     62                    LOG.error("Error: any context is both acceptable and rejectable for facet '" + facetConcept.getName() + "'");
     63                }
     64                if (acceptableContext.includeEmpty() && rejectableContext.includeEmpty()) {
     65                    LOG.error("Error: empty context is both acceptable and rejectable for facet '" + facetConcept.getName() + "'");
     66                }
    6267            }
    6368        }
     
    6772    @XmlRootElement(name = "facetConcept")
    6873    public static class FacetConcept {
     74
    6975        @XmlAttribute
    7076        private String name;
    7177
    7278        /**
    73          * Values will be stored lowercase by default, set isCaseInsensitive to true if you want to keep the case of the value
     79         * Values will be stored lowercase by default, set isCaseInsensitive to
     80         * true if you want to keep the case of the value
    7481         */
    7582        @XmlAttribute
     
    7784
    7885        /**
    79          * By default multiple values that are found for a matching pattern will be stored. For some facets this leads to too much values
    80          * with little value for instance for "subject". Set allowMultipleValues to false will only store the first found value.
     86         * By default multiple values that are found for a matching pattern will
     87         * be stored. For some facets this leads to too much values with little
     88         * value for instance for "subject". Set allowMultipleValues to false
     89         * will only store the first found value.
    8190         */
    8291        @XmlAttribute
    8392        private boolean allowMultipleValues = true;
    84        
     93
    8594        @XmlAttribute
    8695        private String description = "";
    87        
     96
    8897        @XmlAttribute
    8998        private String definition = "";
     
    100109        @XmlElement(name = "pattern")
    101110        private List<String> patterns = new ArrayList<String>();
    102        
     111
    103112        @XmlElement(name = "blacklistPattern")
    104113        private List<String> blacklistPatterns = new ArrayList<String>();
    105        
     114
     115        @XmlElement(name = "derivedFacet")
     116        private List<String> derivedFacets = new ArrayList<String>();
     117
    106118        public void setConcepts(List<String> concepts) {
    107119            this.concepts = concepts;
     
    119131            return acceptableContext;
    120132        }
    121        
     133
    122134        public boolean hasAcceptableContext() {
    123             return (acceptableContext!=null);
     135            return (acceptableContext != null);
    124136        }
    125137
     
    131143            return rejectableContext;
    132144        }
    133        
     145
    134146        public boolean hasRejectableContext() {
    135             return (rejectableContext!=null);
    136         }
    137        
     147            return (rejectableContext != null);
     148        }
     149
    138150        public boolean hasContext() {
    139151            return (hasAcceptableContext() || hasRejectableContext());
     
    163175            return allowMultipleValues;
    164176        }
    165        
     177
    166178        public void setDescription(String description) {
    167                 this.description = description;
    168         }
    169        
     179            this.description = description;
     180        }
     181
    170182        public String getDescription() {
    171                 return this.description;
    172         }
    173        
     183            return this.description;
     184        }
     185
    174186        public void setDefinition(String definition) {
    175                 this.definition = definition;
    176         }
    177        
     187            this.definition = definition;
     188        }
     189
    178190        public String getDefinition() {
    179                 return this.definition;
     191            return this.definition;
    180192        }
    181193
     
    187199            return patterns;
    188200        }
    189        
     201
    190202        public void setBlacklistPatterns(List<String> blacklistPatterns) {
    191203            this.blacklistPatterns = blacklistPatterns;
     
    194206        public List<String> getBlacklistPatterns() {
    195207            return blacklistPatterns;
     208        }
     209
     210        public List<String> getDerivedFacets() {
     211            return derivedFacets;
     212        }
     213
     214        public void setDerivedFacets(List<String> derivedFacets) {
     215            this.derivedFacets = derivedFacets;
    196216        }
    197217
     
    202222
    203223    }
    204    
     224
    205225    @XmlAccessorType(XmlAccessType.FIELD)
    206226    @XmlRootElement(name = "acceptableContext")
     
    239259            return includeEmpty;
    240260        }
    241        
     261
    242262    }
    243263
     
    278298            return includeEmpty;
    279299        }
    280        
     300
    281301    }
    282302
  • vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/FacetConfiguration.java

    r6201 r6311  
    66
    77/**
    8  * Once created contains the information about the facets and such.
    9  * Just a container for some information, doesn't do processing.
     8 * Once created contains the information about the facets and such. Just a
     9 * container for some information, doesn't do processing.
    1010 */
    11 
    1211public class FacetConfiguration {
    1312
    1413    private String name;
    15     private boolean caseInsensitive= false;
     14    private boolean caseInsensitive = false;
    1615    private List<String> patterns = new ArrayList<String>();
    1716    private List<String> fallbackPatterns = new ArrayList<String>();
     17    private List<String> derivedFacets = new ArrayList<String>();
    1818    private boolean allowMultipleValues = true;
    1919
     
    2929        this.patterns = patterns;
    3030    }
    31    
     31
    3232    public void setFallbackPatterns(List<String> fallbackPatterns) {
    3333        this.fallbackPatterns = fallbackPatterns;
     
    3737        this.patterns = Collections.singletonList(pattern);
    3838    }
    39    
     39
    4040    public void setFallbackPattern(String fallbackPattern) {
    4141        this.fallbackPatterns = Collections.singletonList(fallbackPattern);
     
    4848        return patterns;
    4949    }
    50    
     50
    5151    public List<String> getFallbackPatterns() {
    5252        return fallbackPatterns;
     
    6363    @Override
    6464    public String toString() {
    65         return "name="+name+", pattern="+patterns;
     65        return "name=" + name + ", pattern=" + patterns;
    6666    }
    6767
     
    7373        this.allowMultipleValues = allowMultipleValues;
    7474    }
     75
     76    public List<String> getDerivedFacets() {
     77        return derivedFacets;
     78    }
     79
     80    public void setDerivedFacets(List<String> derivedFacets) {
     81        this.derivedFacets = derivedFacets;
     82    }
     83
    7584}
  • vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/FacetMappingFactory.java

    r6216 r6311  
    179179                config.setPatterns(new ArrayList<String>(linkedHashSet));
    180180                config.setFallbackPatterns(facetConcept.getPatterns());
     181                config.setDerivedFacets(facetConcept.getDerivedFacets());
    181182
    182183                if (!config.getPatterns().isEmpty() || !config.getFallbackPatterns().isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.