Project

General

Profile

1
/**
2
 * 
3
 */
4
package eu.dnetlib.data.collective.transformation.engine.functions;
5

    
6
import org.apache.commons.logging.Log;
7
import org.apache.commons.logging.LogFactory;
8
import org.apache.oro.text.perl.MalformedPerl5PatternException;
9
import org.apache.oro.text.perl.Perl5Util;
10

    
11
/**
12
 * @author jochen
13
 *
14
 */
15
public class RegularExpression extends AbstractTransformationFunction {
16

    
17
	public static final Log log = LogFactory.getLog(RegularExpression.class);
18
	public static final String paramRegularExpr = "regularExpression";
19
	public static final String paramExpr1		= "expr1";
20
	public static final String paramExpr2		= "expr2";
21
	
22
	private Perl5Util util = new Perl5Util();
23

    
24
	/* (non-Javadoc)
25
	 * @see eu.dnetlib.data.collective.transformation.engine.functions.AbstractTransformationFunction#execute()
26
	 */
27
	@Override
28
	String execute() throws ProcessingException {
29
		// TODO Auto-generated method stub
30
		return null;
31
	}
32
	
33
	public String executeSingleValue(String aRegularExpression, String aExpr1, String aExpr2) throws ProcessingException{
34
		String result = "";
35
		if (aRegularExpression.startsWith("m/")){
36
			if (util.match(aRegularExpression, aExpr1))
37
				result = util.group(1);
38
		}else if (!aRegularExpression.startsWith("s/")){ 
39
			// assume match and extract
40
			// throw new ProcessingException("unsupported or invalid regular expression: " + aRegularExpression);
41
			if (util.match(aRegularExpression, aExpr1)){
42
				String funder = util.group(1).toLowerCase();
43
				String projectId = util.group(3);
44
				result = funder + "_" + projectId;
45
			}
46
		}else{
47
			try{
48
				result = util.substitute(aRegularExpression, aExpr1);							
49
			}catch(MalformedPerl5PatternException patternExc){
50
				log.fatal("aRegularExpression: " + aRegularExpression);
51
				log.fatal("aExpr1: " + aExpr1);
52
				log.fatal(patternExc.getMessage());
53
				throw new ProcessingException(patternExc);
54
			}
55
		}
56
		return result;
57
	}
58

    
59
	
60
}
(14-14/17)