1 | package eu.clarin.cmdi.vlo.importer; |
---|
2 | |
---|
3 | import java.util.ArrayList; |
---|
4 | import java.util.HashMap; |
---|
5 | import java.util.List; |
---|
6 | import java.util.Map; |
---|
7 | import java.util.TreeMap; |
---|
8 | |
---|
9 | import javax.xml.bind.annotation.XmlAccessType; |
---|
10 | import javax.xml.bind.annotation.XmlAccessorType; |
---|
11 | import javax.xml.bind.annotation.XmlAttribute; |
---|
12 | import javax.xml.bind.annotation.XmlElement; |
---|
13 | import javax.xml.bind.annotation.XmlRootElement; |
---|
14 | import javax.xml.bind.annotation.XmlValue; |
---|
15 | |
---|
16 | import org.slf4j.Logger; |
---|
17 | import org.slf4j.LoggerFactory; |
---|
18 | |
---|
19 | @XmlAccessorType(XmlAccessType.FIELD) |
---|
20 | @XmlRootElement(name = "mappings") |
---|
21 | public class VariantsMap { |
---|
22 | |
---|
23 | private final static Logger LOG = LoggerFactory.getLogger(VariantsMap.class); |
---|
24 | |
---|
25 | @XmlAttribute |
---|
26 | private String field; |
---|
27 | |
---|
28 | @XmlElement(name = "mapping") |
---|
29 | public List<Mapping> mappings; |
---|
30 | |
---|
31 | public List<Mapping> getMappings() { |
---|
32 | return mappings; |
---|
33 | } |
---|
34 | |
---|
35 | public void setMappings(List<Mapping> mappings) { |
---|
36 | this.mappings = mappings; |
---|
37 | } |
---|
38 | |
---|
39 | public String getField() { |
---|
40 | return field; |
---|
41 | } |
---|
42 | |
---|
43 | public void setField(String field) { |
---|
44 | this.field = field; |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | /** |
---|
49 | * returns inverted map variant-normalizedVal |
---|
50 | * |
---|
51 | */ |
---|
52 | |
---|
53 | public Map<String, String> getInvertedMap(){ |
---|
54 | Map<String, String> invMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); |
---|
55 | for(Mapping m: mappings) |
---|
56 | for(Variant variant: m.getVariants()) |
---|
57 | if(!variant.isRegExp()) |
---|
58 | invMap.put(variant.getValue(), m.getValue()); |
---|
59 | |
---|
60 | return invMap; |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | public Map<String, List<Variant>> getMap(){ |
---|
66 | Map<String, List<Variant>> map = new HashMap<String, List<Variant>>(); |
---|
67 | for(Mapping m: mappings) |
---|
68 | map.put(m.value, m.variants); |
---|
69 | |
---|
70 | return map; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | @XmlAccessorType(XmlAccessType.FIELD) |
---|
75 | @XmlRootElement(name = "mapping") |
---|
76 | public static class Mapping{ |
---|
77 | |
---|
78 | @XmlElement(name = "value") |
---|
79 | private String value; |
---|
80 | |
---|
81 | @XmlElement(name = "variant") |
---|
82 | List<Variant> variants = new ArrayList<Variant>(); |
---|
83 | |
---|
84 | public String getValue() { |
---|
85 | return value; |
---|
86 | } |
---|
87 | |
---|
88 | public void setValue(String value) { |
---|
89 | this.value = value; |
---|
90 | } |
---|
91 | |
---|
92 | public List<Variant> getVariants() { |
---|
93 | return variants; |
---|
94 | } |
---|
95 | |
---|
96 | public void setVariants(List<Variant> variants) { |
---|
97 | this.variants = variants; |
---|
98 | } |
---|
99 | |
---|
100 | } |
---|
101 | |
---|
102 | @XmlAccessorType(XmlAccessType.FIELD) |
---|
103 | @XmlRootElement(name = "variant") |
---|
104 | public static class Variant{ |
---|
105 | |
---|
106 | @XmlValue |
---|
107 | private String value; |
---|
108 | |
---|
109 | @XmlAttribute |
---|
110 | private boolean isRegExp = false; |
---|
111 | |
---|
112 | public boolean isRegExp() { |
---|
113 | return isRegExp; |
---|
114 | } |
---|
115 | |
---|
116 | public void setRegExp(boolean isRegExp) { |
---|
117 | this.isRegExp = isRegExp; |
---|
118 | } |
---|
119 | |
---|
120 | public String getValue() { |
---|
121 | return value; |
---|
122 | } |
---|
123 | |
---|
124 | public void setValue(String value) { |
---|
125 | this.value = value; |
---|
126 | } |
---|
127 | |
---|
128 | } |
---|
129 | |
---|
130 | } |
---|