forked from D-Net/dnet-hadoop
optimized classpath resolvers
This commit is contained in:
parent
ff4956def9
commit
15d7b584f3
|
@ -23,9 +23,11 @@ public class PaceConfig implements Serializable {
|
|||
private List<ClusteringDef> clustering;
|
||||
private Map<String, List<String>> blacklists;
|
||||
|
||||
@JsonIgnore
|
||||
private Map<String, FieldDef> modelMap;
|
||||
|
||||
// public PaceResolver paceResolver;
|
||||
@JsonIgnore
|
||||
public static PaceResolver resolver = new PaceResolver();
|
||||
|
||||
public PaceConfig() {}
|
||||
|
||||
|
@ -34,8 +36,6 @@ public class PaceConfig implements Serializable {
|
|||
for(FieldDef fd : getModel()) {
|
||||
modelMap.put(fd.getName(), fd);
|
||||
}
|
||||
|
||||
// paceResolver = new PaceResolver();
|
||||
}
|
||||
|
||||
public List<FieldDef> getModel() {
|
||||
|
|
|
@ -23,8 +23,6 @@ public class ClusteringDef implements Serializable {
|
|||
|
||||
private Map<String, Integer> params;
|
||||
|
||||
PaceResolver paceResolver = new PaceResolver();
|
||||
|
||||
public ClusteringDef() {}
|
||||
|
||||
public String getName() {
|
||||
|
@ -36,12 +34,7 @@ public class ClusteringDef implements Serializable {
|
|||
}
|
||||
|
||||
public ClusteringFunction clusteringFunction() {
|
||||
try {
|
||||
return paceResolver.getClusteringFunction(getName(), params);
|
||||
} catch (PaceException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return PaceConfig.resolver.getClusteringFunction(getName(), params);
|
||||
}
|
||||
|
||||
public List<String> getFields() {
|
||||
|
|
|
@ -16,12 +16,10 @@ public class CondDef implements Serializable {
|
|||
|
||||
private List<String> fields;
|
||||
|
||||
PaceResolver paceResolver = new PaceResolver();
|
||||
|
||||
public CondDef() {}
|
||||
|
||||
public ConditionAlgo conditionAlgo(final List<FieldDef> fields){
|
||||
return paceResolver.getConditionAlgo(getName(), fields);
|
||||
public ConditionAlgo conditionAlgo(final List<FieldDef> fields) {
|
||||
return PaceConfig.resolver.getConditionAlgo(getName(), fields);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -34,8 +34,6 @@ public class FieldDef implements Serializable {
|
|||
|
||||
private double weight;
|
||||
|
||||
PaceResolver paceResolver = new PaceResolver();
|
||||
|
||||
/**
|
||||
* 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<>();
|
||||
}
|
||||
|
||||
//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());
|
||||
return paceResolver.getDistanceAlgo(getAlgo(), params);
|
||||
return PaceConfig.resolver.getDistanceAlgo(getAlgo(), params);
|
||||
}
|
||||
|
||||
public boolean isIgnoreMissing() {
|
||||
|
|
|
@ -17,21 +17,25 @@ import java.util.stream.Collectors;
|
|||
|
||||
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<ConditionAlgo>> conditionAlgos;
|
||||
private final Map<String, Class<DistanceAlgo>> distanceAlgos;
|
||||
|
||||
public PaceResolver() {
|
||||
|
||||
this.clusteringFunctions = new Reflections("eu.dnetlib").getTypesAnnotatedWith(ClusteringClass.class).stream()
|
||||
this.clusteringFunctions = CLUSTERING_RESOLVER.getTypesAnnotatedWith(ClusteringClass.class).stream()
|
||||
.filter(ClusteringFunction.class::isAssignableFrom)
|
||||
.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)
|
||||
.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)
|
||||
.collect(Collectors.toMap(cl -> cl.getAnnotation(DistanceClass.class).value(), cl -> (Class<DistanceAlgo>)cl));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue