1
|
package eu.dnetlib.data.collective.transformation.engine.functions;
|
2
|
|
3
|
import java.util.LinkedList;
|
4
|
import java.util.List;
|
5
|
|
6
|
import javax.annotation.Resource;
|
7
|
|
8
|
import eu.dnetlib.data.collective.transformation.VocabularyRegistry;
|
9
|
|
10
|
/**
|
11
|
* @author jochen
|
12
|
*
|
13
|
*/
|
14
|
public class Convert extends AbstractTransformationFunction {
|
15
|
|
16
|
public static final String paramVocabularyName = "vocabularyName";
|
17
|
public static final String paramFieldValue = "fieldValue";
|
18
|
public static final String paramDefaultPattern = "defaultPattern";
|
19
|
public static final String paramFunction = "function";
|
20
|
|
21
|
@Resource
|
22
|
private VocabularyRegistry vocabularyRegistry;
|
23
|
|
24
|
|
25
|
/**
|
26
|
* not implemented
|
27
|
* @see eu.dnetlib.data.collective.transformation.engine.functions.AbstractTransformationFunction#execute()
|
28
|
*/
|
29
|
public String execute() throws ProcessingException {
|
30
|
return null;
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* extracts and returns the encoded value as used in the vocabulary
|
35
|
* @param vocabularyName the name of the vocabulary to be used
|
36
|
* @param fieldValues the list of values to normalize
|
37
|
* @return encoded value
|
38
|
* @throws ProcessingException
|
39
|
*/
|
40
|
public String executeSingleValue(String vocabularyName, List<String> fieldValues)throws ProcessingException{
|
41
|
if (!vocabularyRegistry.getVocabularies().containsKey(vocabularyName)){
|
42
|
throw new ProcessingException("unknown vocabulary: " + vocabularyName);
|
43
|
}
|
44
|
String returnValue = vocabularyRegistry.getVocabulary(vocabularyName).encoding(fieldValues);
|
45
|
return returnValue;
|
46
|
}
|
47
|
|
48
|
public List<String> executeAllValues(String vocabularyName, List<String> fieldValues) throws ProcessingException{
|
49
|
if (!vocabularyRegistry.getVocabularies().containsKey(vocabularyName)){
|
50
|
throw new ProcessingException("unknown vocabulary: " + vocabularyName);
|
51
|
}
|
52
|
List<String> computedValues = new LinkedList<String>();
|
53
|
int numOfComputedValues = fieldValues.size();
|
54
|
if (numOfComputedValues == 0) numOfComputedValues = 1; // return at least 1 value
|
55
|
String returnValue = vocabularyRegistry.getVocabulary(vocabularyName).encoding(fieldValues);
|
56
|
for (int i = 0; i < numOfComputedValues; i++){
|
57
|
computedValues.add(returnValue);
|
58
|
}
|
59
|
return computedValues;
|
60
|
}
|
61
|
|
62
|
public List<String> executeFilterByParams(String vocabName, List<String> fieldValues, String defaultPattern, String filterFunction) throws ProcessingException{
|
63
|
return vocabularyRegistry.getVocabulary(vocabName).encoding(fieldValues, defaultPattern, filterFunction);
|
64
|
}
|
65
|
|
66
|
public VocabularyRegistry getVocabularyRegistry() {
|
67
|
return vocabularyRegistry;
|
68
|
}
|
69
|
|
70
|
public void setVocabularyRegistry(VocabularyRegistry vocabularyRegistry) {
|
71
|
this.vocabularyRegistry = vocabularyRegistry;
|
72
|
}
|
73
|
|
74
|
}
|