1
0
Fork 0

optimized classpath resolvers

This commit is contained in:
Claudio Atzori 2019-06-19 10:01:35 +02:00
parent ff4956def9
commit 15d7b584f3
5 changed files with 14 additions and 26 deletions

View File

@ -23,9 +23,11 @@ public class PaceConfig implements Serializable {
private List<ClusteringDef> clustering; private List<ClusteringDef> clustering;
private Map<String, List<String>> blacklists; private Map<String, List<String>> blacklists;
@JsonIgnore
private Map<String, FieldDef> modelMap; private Map<String, FieldDef> modelMap;
// public PaceResolver paceResolver; @JsonIgnore
public static PaceResolver resolver = new PaceResolver();
public PaceConfig() {} public PaceConfig() {}
@ -34,8 +36,6 @@ public class PaceConfig implements Serializable {
for(FieldDef fd : getModel()) { for(FieldDef fd : getModel()) {
modelMap.put(fd.getName(), fd); modelMap.put(fd.getName(), fd);
} }
// paceResolver = new PaceResolver();
} }
public List<FieldDef> getModel() { public List<FieldDef> getModel() {

View File

@ -23,8 +23,6 @@ public class ClusteringDef implements Serializable {
private Map<String, Integer> params; private Map<String, Integer> params;
PaceResolver paceResolver = new PaceResolver();
public ClusteringDef() {} public ClusteringDef() {}
public String getName() { public String getName() {
@ -36,12 +34,7 @@ public class ClusteringDef implements Serializable {
} }
public ClusteringFunction clusteringFunction() { public ClusteringFunction clusteringFunction() {
try { return PaceConfig.resolver.getClusteringFunction(getName(), params);
return paceResolver.getClusteringFunction(getName(), params);
} catch (PaceException e) {
e.printStackTrace();
return null;
}
} }
public List<String> getFields() { public List<String> getFields() {

View File

@ -16,12 +16,10 @@ public class CondDef implements Serializable {
private List<String> fields; private List<String> fields;
PaceResolver paceResolver = new PaceResolver();
public CondDef() {} public CondDef() {}
public ConditionAlgo conditionAlgo(final List<FieldDef> fields){ public ConditionAlgo conditionAlgo(final List<FieldDef> fields) {
return paceResolver.getConditionAlgo(getName(), fields); return PaceConfig.resolver.getConditionAlgo(getName(), fields);
} }
public String getName() { public String getName() {

View File

@ -34,8 +34,6 @@ public class FieldDef implements Serializable {
private double weight; private double weight;
PaceResolver paceResolver = new PaceResolver();
/** /**
* Sets maximum size for the repeatable fields in the model. -1 for unbounded size. * Sets maximum size for the repeatable fields in the model. -1 for unbounded size.
*/ */
@ -82,13 +80,8 @@ public class FieldDef implements Serializable {
params = new HashMap<>(); params = new HashMap<>();
} }
//TODO verify that the init signatures for the distance algos are all the same!
/*
params.put("size", getSize());
params.put("length", getLength());
*/
params.put("weight", getWeight()); params.put("weight", getWeight());
return paceResolver.getDistanceAlgo(getAlgo(), params); return PaceConfig.resolver.getDistanceAlgo(getAlgo(), params);
} }
public boolean isIgnoreMissing() { public boolean isIgnoreMissing() {

View File

@ -17,21 +17,25 @@ import java.util.stream.Collectors;
public class PaceResolver implements Serializable { public class PaceResolver implements Serializable {
public static final Reflections CLUSTERING_RESOLVER = new Reflections("eu.dnetlib.pace.clustering");
public static final Reflections CONDITION_RESOLVER = new Reflections("eu.dnetlib.pace.condition");
public static final Reflections DISTANCE_RESOLVER = new Reflections("eu.dnetlib.pace.distance.algo");
private final Map<String, Class<ClusteringFunction>> clusteringFunctions; private final Map<String, Class<ClusteringFunction>> clusteringFunctions;
private final Map<String, Class<ConditionAlgo>> conditionAlgos; private final Map<String, Class<ConditionAlgo>> conditionAlgos;
private final Map<String, Class<DistanceAlgo>> distanceAlgos; private final Map<String, Class<DistanceAlgo>> distanceAlgos;
public PaceResolver() { public PaceResolver() {
this.clusteringFunctions = new Reflections("eu.dnetlib").getTypesAnnotatedWith(ClusteringClass.class).stream() this.clusteringFunctions = CLUSTERING_RESOLVER.getTypesAnnotatedWith(ClusteringClass.class).stream()
.filter(ClusteringFunction.class::isAssignableFrom) .filter(ClusteringFunction.class::isAssignableFrom)
.collect(Collectors.toMap(cl -> cl.getAnnotation(ClusteringClass.class).value(), cl -> (Class<ClusteringFunction>)cl)); .collect(Collectors.toMap(cl -> cl.getAnnotation(ClusteringClass.class).value(), cl -> (Class<ClusteringFunction>)cl));
this.conditionAlgos = new Reflections("eu.dnetlib").getTypesAnnotatedWith(ConditionClass.class).stream() this.conditionAlgos = CONDITION_RESOLVER.getTypesAnnotatedWith(ConditionClass.class).stream()
.filter(ConditionAlgo.class::isAssignableFrom) .filter(ConditionAlgo.class::isAssignableFrom)
.collect(Collectors.toMap(cl -> cl.getAnnotation(ConditionClass.class).value(), cl -> (Class<ConditionAlgo>)cl)); .collect(Collectors.toMap(cl -> cl.getAnnotation(ConditionClass.class).value(), cl -> (Class<ConditionAlgo>)cl));
this.distanceAlgos = new Reflections("eu.dnetlib").getTypesAnnotatedWith(DistanceClass.class).stream() this.distanceAlgos = DISTANCE_RESOLVER.getTypesAnnotatedWith(DistanceClass.class).stream()
.filter(DistanceAlgo.class::isAssignableFrom) .filter(DistanceAlgo.class::isAssignableFrom)
.collect(Collectors.toMap(cl -> cl.getAnnotation(DistanceClass.class).value(), cl -> (Class<DistanceAlgo>)cl)); .collect(Collectors.toMap(cl -> cl.getAnnotation(DistanceClass.class).value(), cl -> (Class<DistanceAlgo>)cl));
} }