Revision 28483
Added by Claudio Atzori about 10 years ago
AbstractClusteringFunction.java | ||
---|---|---|
1 |
package eu.dnetlib.pace.clustering; |
|
2 |
|
|
3 |
import java.util.Collection; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
|
|
7 |
import com.google.common.collect.Sets; |
|
8 |
|
|
9 |
import eu.dnetlib.pace.common.AbstractPaceFunctions; |
|
10 |
import eu.dnetlib.pace.model.Field; |
|
11 |
|
|
12 |
/** |
|
13 |
* The Class AbstractClusteringFunction. |
|
14 |
*/ |
|
15 |
public abstract class AbstractClusteringFunction extends AbstractPaceFunctions implements ClusteringFunction { |
|
16 |
|
|
17 |
/** The params. */ |
|
18 |
protected Map<String, Integer> params; |
|
19 |
|
|
20 |
/** |
|
21 |
* Instantiates a new abstract clustering function. |
|
22 |
* |
|
23 |
* @param params |
|
24 |
* the params |
|
25 |
*/ |
|
26 |
public AbstractClusteringFunction(final Map<String, Integer> params) { |
|
27 |
this.params = params; |
|
28 |
} |
|
29 |
|
|
30 |
/** |
|
31 |
* Do apply. |
|
32 |
* |
|
33 |
* @param s |
|
34 |
* the s |
|
35 |
* @return the collection |
|
36 |
*/ |
|
37 |
protected abstract Collection<String> doApply(String s); |
|
38 |
|
|
39 |
/* |
|
40 |
* (non-Javadoc) |
|
41 |
* |
|
42 |
* @see eu.dnetlib.pace.clustering.ClusteringFunction#apply(java.util.List) |
|
43 |
*/ |
|
44 |
@Override |
|
45 |
public Collection<String> apply(final List<Field> fields) { |
|
46 |
Collection<String> c = Sets.newLinkedHashSet(); |
|
47 |
for (Field f : fields) { |
|
48 |
c.addAll(filterBlacklisted(doApply(filterStopWords(normalize(f.stringValue()), stopwords)), ngramBlacklist)); |
|
49 |
} |
|
50 |
return c; |
|
51 |
} |
|
52 |
|
|
53 |
/* |
|
54 |
* (non-Javadoc) |
|
55 |
* |
|
56 |
* @see eu.dnetlib.pace.clustering.ClusteringFunction#getParams() |
|
57 |
*/ |
|
58 |
@Override |
|
59 |
public Map<String, Integer> getParams() { |
|
60 |
return params; |
|
61 |
} |
|
62 |
|
|
63 |
/** |
|
64 |
* Param. |
|
65 |
* |
|
66 |
* @param name |
|
67 |
* the name |
|
68 |
* @return the integer |
|
69 |
*/ |
|
70 |
protected Integer param(final String name) { |
|
71 |
return params.get(name); |
|
72 |
} |
|
73 |
} |
|
0 | 74 |
Also available in: Unified diff
branch 1.2