Project

General

Profile

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
	private String DELIM;
14
	private String ENCLOSING;
15

    
16
	public FundingParser(String DELIM, String ENCLOSING) {
17
		this.DELIM = DELIM;
18
		this.ENCLOSING = ENCLOSING;
19
	}
20

    
21
	public String getFundingLevel(String funding_level, int level) {
22

    
23
		if (funding_level.isEmpty()) {
24
			return ENCLOSING + " " + ENCLOSING + DELIM;
25
		}
26

    
27
		if (!funding_level.contains("<funding_level_" + level + ">")) {
28
			return ENCLOSING + " " + ENCLOSING + DELIM;
29
		}
30

    
31
		String[] split = funding_level.split("<funding_level_" + level + ">");
32

    
33
		funding_level = split[1];
34

    
35
		split = funding_level.split("<name>");
36
		funding_level = split[1];
37

    
38
		funding_level = funding_level.substring(0, funding_level.indexOf("</name>"));
39
		funding_level = funding_level.replaceAll("\"", "");
40
		funding_level = funding_level.replaceAll("/>", "");
41
		funding_level = funding_level.replaceAll("<", "");
42
		funding_level = funding_level.replaceAll("&amp;", "");
43

    
44
		if (level == 1) {
45
			if (funding_level.equalsIgnoreCase("SP1")) {
46
				funding_level = "SP1-Cooperation";
47
			} else if (funding_level.equalsIgnoreCase("SP2")) {
48
				funding_level = "SP2-Ideas";
49
			}
50

    
51
			if (funding_level.equalsIgnoreCase("SP3")) {
52
				funding_level = "SP3-People";
53
			} else if (funding_level.equalsIgnoreCase("SP4")) {
54
				funding_level = "SP4-Capacities";
55
			} else if (funding_level.equalsIgnoreCase("SP5")) {
56
				funding_level = "SP5-Euratom";
57
			}
58
		}
59

    
60
		funding_level = funding_level.replaceAll(">", "");
61
		funding_level = funding_level.replaceAll("</", "");
62
		funding_level = funding_level.replace(DELIM, " ");
63
		funding_level = funding_level.replace(ENCLOSING, " ");
64

    
65
		return ENCLOSING + funding_level + ENCLOSING + DELIM;
66
	}
67

    
68
	public String getFundingInfo(String buff) {
69
		return getFunder(buff) + getFundingLevel(buff, 0) + (getFundingLevel(buff, 1) + getFundingLevel(buff, 2)
70
				+ getFundingLevel(buff, 3));
71
	}
72

    
73
	public String getFunder(String buff) {
74

    
75
		if (buff.isEmpty()) {
76
			return ENCLOSING + " " + ENCLOSING + DELIM;
77

    
78
		}
79
		if (!buff.contains("<funder>")) {
80
			return ENCLOSING + " " + ENCLOSING + DELIM;
81
		}
82

    
83
		String[] split = buff.split("<funder>");
84
		String funder = split[1];
85
		split = funder.split("<name>");
86

    
87
		funder = split[1];
88
		funder = funder.substring(0, funder.indexOf("</name>"));
89
		funder = funder.replaceAll(">", "");
90
		funder = funder.replaceAll("</", "");
91
		funder = funder.replaceAll("\"", "");
92
		funder = funder.replaceAll("&amp;", "");
93
		funder = funder.replace(ENCLOSING, " ");
94

    
95
		return ENCLOSING + funder + ENCLOSING + DELIM;
96
	}
97
}
98

    
(2-2/3)