use of java.util.AbstractMap.SimpleEntry in project aerosolve by airbnb.
the class MinKernelDenseFeatureDictionary method getKNearestNeighbors.
/**
/**
* Calculates the Min Kernel distance to each dictionary element.
* Returns the top K elements as a new sparse feature.
*/
@Override
public FeatureVector getKNearestNeighbors(KNearestNeighborsOptions options, FeatureVector featureVector) {
FeatureVector result = new FeatureVector();
Map<String, List<Double>> denseFeatures = featureVector.getDenseFeatures();
if (denseFeatures == null) {
return result;
}
PriorityQueue<SimpleEntry<String, Double>> pq = new PriorityQueue<>(options.getNumNearest() + 1, new EntryComparator());
String idKey = options.getIdKey();
Map<String, Map<String, Double>> floatFeatures = new HashMap<>();
String myId = featureVector.getStringFeatures().get(idKey).iterator().next();
for (FeatureVector supportVector : dictionaryList) {
Double minKernel = FeatureVectorUtil.featureVectorMinKernel(featureVector, supportVector);
Set<String> idSet = supportVector.getStringFeatures().get(idKey);
String id = idSet.iterator().next();
if (id == myId)
continue;
SimpleEntry<String, Double> entry = new SimpleEntry<String, Double>(id, minKernel);
pq.add(entry);
if (pq.size() > options.getNumNearest()) {
pq.poll();
}
}
HashMap<String, Double> newFeature = new HashMap<>();
while (pq.peek() != null) {
SimpleEntry<String, Double> entry = pq.poll();
newFeature.put(entry.getKey(), entry.getValue());
}
floatFeatures.put(options.getOutputKey(), newFeature);
result.setFloatFeatures(floatFeatures);
return result;
}
use of java.util.AbstractMap.SimpleEntry in project stash-codesearch-plugin by palantir.
the class SearchUpdateJobImpl method doUpdate.
@Override
public void doUpdate(Client client, GitScm gitScm, GlobalSettings globalSettings) {
if (!globalSettings.getIndexingEnabled()) {
return;
}
GitCommandBuilderFactory builderFactory = gitScm.getCommandBuilderFactory();
// List of bulk requests to execute sequentially at the end of the method
RequestBuffer requestBuffer = new RequestBuffer(client);
// Unique identifier for ref
String refDesc = toString();
// Hash of latest indexed commit
String prevHash = getLatestIndexedHash(client);
// Hash of latest commit on ref
String newHash = getLatestHash(builderFactory);
if (newHash == null) {
log.error("Aborting since hash is invalid");
return;
}
// Diff for files & process changes
Set<SimpleEntry<String, String>> filesToAdd = new LinkedHashSet<SimpleEntry<String, String>>();
try {
// Get diff --raw -z tokens
String[] diffToks = builderFactory.builder(repository).command("diff").argument("--raw").argument("--abbrev=40").argument("-z").argument(prevHash).argument(newHash).build(new StringOutputHandler(plf)).call().split("