1 | package eu.clarin.cmdi.vlo.pojo; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.List; |
---|
5 | import java.util.Map; |
---|
6 | import java.util.TreeMap; |
---|
7 | |
---|
8 | import javax.xml.bind.annotation.XmlAccessType; |
---|
9 | import javax.xml.bind.annotation.XmlAccessorType; |
---|
10 | import javax.xml.bind.annotation.XmlAttribute; |
---|
11 | import javax.xml.bind.annotation.XmlElement; |
---|
12 | import javax.xml.bind.annotation.XmlRootElement; |
---|
13 | |
---|
14 | import eu.clarin.cmdi.vlo.normalization.NormalizationVocabulary; |
---|
15 | import eu.clarin.cmdi.vlo.normalization.VocabularyEntry; |
---|
16 | |
---|
17 | /** |
---|
18 | * @author dostojic |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | |
---|
23 | @XmlAccessorType(XmlAccessType.FIELD) |
---|
24 | @XmlRootElement(name = "mappings") |
---|
25 | public class VariantsMap{ |
---|
26 | |
---|
27 | @XmlAttribute |
---|
28 | private String field; |
---|
29 | |
---|
30 | @XmlElement(name = "mapping") |
---|
31 | private List<Mapping> mappings; |
---|
32 | |
---|
33 | public List<Mapping> getMappings() { |
---|
34 | return mappings; |
---|
35 | } |
---|
36 | |
---|
37 | public void setMappings(List<Mapping> mappings) { |
---|
38 | this.mappings = mappings; |
---|
39 | } |
---|
40 | |
---|
41 | public String getField() { |
---|
42 | return field; |
---|
43 | } |
---|
44 | |
---|
45 | public void setField(String field) { |
---|
46 | this.field = field; |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | /** |
---|
51 | * returns inverted map: variant-normalizedVal |
---|
52 | * |
---|
53 | */ |
---|
54 | |
---|
55 | public Map<String, String> getInvertedMap(){ |
---|
56 | Map<String, String> invMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); |
---|
57 | for(Mapping m: mappings){ |
---|
58 | if(m.getVariants() != null) |
---|
59 | for(Variant variant: m.getVariants()) |
---|
60 | if(!variant.isRegExp()) |
---|
61 | invMap.put(variant.getValue(), m.getValue()); |
---|
62 | } |
---|
63 | |
---|
64 | return invMap; |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | public NormalizationVocabulary getMap(){ |
---|
69 | List<VocabularyEntry> listOfEntries = new ArrayList<VocabularyEntry>(); |
---|
70 | boolean containsRegEx = false; |
---|
71 | |
---|
72 | for(Mapping m: mappings) |
---|
73 | if(m.getVariants() != null) |
---|
74 | for(Variant v: m.getVariants()){ |
---|
75 | listOfEntries.add(new VocabularyEntry(v.getValue().trim(), m.getValue().trim(), v.isRegExp(), v.getCrossMappings())); |
---|
76 | if(v.isRegExp()) |
---|
77 | containsRegEx = true; |
---|
78 | } |
---|
79 | |
---|
80 | return new NormalizationVocabulary(listOfEntries.toArray(new VocabularyEntry[0]), containsRegEx); |
---|
81 | |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|