1
|
package eu.dnetlib.data.mapreduce.hbase.statsExport.utils;
|
2
|
|
3
|
import org.apache.log4j.Logger;
|
4
|
|
5
|
/**
|
6
|
* Created by envy17 j110ea on 4/5/2015.
|
7
|
*/
|
8
|
|
9
|
//Extract funder info for projects
|
10
|
|
11
|
public class FundingParser {
|
12
|
|
13
|
|
14
|
public static String getFundingLevel(String funding_level, int level, String DELIM, String ENCLOSING) {
|
15
|
|
16
|
if (funding_level.isEmpty()) {
|
17
|
return ENCLOSING + " " + ENCLOSING + DELIM;
|
18
|
}
|
19
|
|
20
|
if (!funding_level.contains("<funding_level_" + level + ">")) {
|
21
|
return ENCLOSING + " " + ENCLOSING + DELIM;
|
22
|
}
|
23
|
|
24
|
String[] split = funding_level.split("<funding_level_" + level + ">");
|
25
|
|
26
|
funding_level = split[1];
|
27
|
|
28
|
split = funding_level.split("<name>");
|
29
|
funding_level = split[1];
|
30
|
|
31
|
funding_level = funding_level.substring(0, funding_level.indexOf("</name>"));
|
32
|
funding_level = funding_level.replaceAll("\"", "");
|
33
|
funding_level = funding_level.replaceAll("/>", "");
|
34
|
funding_level = funding_level.replaceAll("<", "");
|
35
|
funding_level = funding_level.replaceAll("&", "");
|
36
|
|
37
|
if (level == 1) {
|
38
|
if (funding_level.equalsIgnoreCase("SP1")) {
|
39
|
funding_level = "SP1-Cooperation";
|
40
|
} else if (funding_level.equalsIgnoreCase("SP2")) {
|
41
|
funding_level = "SP2-Ideas";
|
42
|
}
|
43
|
if (funding_level.equalsIgnoreCase("SP3")) {
|
44
|
funding_level = "SP3-People";
|
45
|
} else if (funding_level.equalsIgnoreCase("SP4")) {
|
46
|
funding_level = "SP4-Capacities";
|
47
|
|
48
|
} else if (funding_level.equalsIgnoreCase("SP5")) {
|
49
|
funding_level = "SP5-Euratom";
|
50
|
}
|
51
|
}
|
52
|
|
53
|
|
54
|
funding_level = funding_level.replaceAll(">", "");
|
55
|
|
56
|
funding_level = funding_level.replaceAll("</", "");
|
57
|
funding_level = funding_level.replace(DELIM, " ");
|
58
|
funding_level = funding_level.replace(ENCLOSING, " ");
|
59
|
|
60
|
return ENCLOSING + funding_level + ENCLOSING + DELIM;
|
61
|
}
|
62
|
|
63
|
public static String getFundingInfo(String buff, String DELIM, String ENCLOSING) {
|
64
|
return getFunder(buff, DELIM, ENCLOSING) +
|
65
|
getFundingLevel(buff, 0, DELIM, ENCLOSING) + (getFundingLevel(buff, 1, DELIM, ENCLOSING) + getFundingLevel(buff, 2, DELIM, ENCLOSING)
|
66
|
+ getFundingLevel(buff, 3, DELIM, ENCLOSING));
|
67
|
}
|
68
|
|
69
|
public static String getFunder(String buff, String DELIM, String ENCLOSING) {
|
70
|
|
71
|
if (buff.isEmpty()) {
|
72
|
return ENCLOSING + " " + ENCLOSING + DELIM;
|
73
|
|
74
|
}
|
75
|
if (!buff.contains("<funder>")) {
|
76
|
return ENCLOSING + " " + ENCLOSING + DELIM;
|
77
|
}
|
78
|
|
79
|
String[] split = buff.split("<funder>");
|
80
|
String funder = split[1];
|
81
|
split = funder.split("<name>");
|
82
|
|
83
|
funder = split[1];
|
84
|
|
85
|
funder = funder.substring(0, funder.indexOf("</name>"));
|
86
|
|
87
|
funder = funder.replaceAll(">", "");
|
88
|
|
89
|
funder = funder.replaceAll("</", "");
|
90
|
|
91
|
funder = funder.replaceAll("\"", "");
|
92
|
funder = funder.replaceAll("&", "");
|
93
|
funder = funder.replace(ENCLOSING, " ");
|
94
|
|
95
|
return ENCLOSING + funder + ENCLOSING + DELIM;
|
96
|
}
|
97
|
|
98
|
}
|
99
|
|