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.regex.Matcher; |
---|
8 | import java.util.regex.Pattern; |
---|
9 | |
---|
10 | public class LicensePostProcessor implements PostProcessor { |
---|
11 | |
---|
12 | private static final Map<Pattern, String> licenseMap; |
---|
13 | private static final Integer MAX_LENGTH = 20; |
---|
14 | private static final String OTHER_VALUE = "Other"; |
---|
15 | |
---|
16 | static { |
---|
17 | licenseMap = new HashMap<Pattern, String>(); |
---|
18 | licenseMap.put(Pattern.compile(".*sldr.org.*licence_v1.*"), "SLDR v1"); |
---|
19 | licenseMap.put(Pattern.compile("The Conditions of Use for the IPROSLA data set specify.*"), "IPROSLA"); |
---|
20 | } |
---|
21 | |
---|
22 | @Override |
---|
23 | public List<String> process(final String value) { |
---|
24 | String result = value; |
---|
25 | List<String> resultList = new ArrayList<String>(); |
---|
26 | |
---|
27 | // first letter should be upper case |
---|
28 | if(result.length() > 1) { |
---|
29 | result = result.substring(0, 1).toUpperCase().concat(result.substring(1, result.length())); |
---|
30 | } |
---|
31 | |
---|
32 | for (Pattern pattern : licenseMap.keySet()) { |
---|
33 | Matcher licenseMatcher = pattern.matcher(result.trim()); |
---|
34 | if (licenseMatcher.matches()) { |
---|
35 | resultList.add(licenseMap.get(pattern)); |
---|
36 | break; |
---|
37 | } |
---|
38 | } |
---|
39 | |
---|
40 | if (resultList.isEmpty()) { |
---|
41 | if (result.length() > MAX_LENGTH) { |
---|
42 | resultList.add(OTHER_VALUE); |
---|
43 | } else { |
---|
44 | resultList.add(result.trim()); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | return resultList; |
---|
49 | } |
---|
50 | } |
---|