Skip to content

Commit

Permalink
change string by path
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Oct 2, 2024
1 parent c4cf6b5 commit 18b7e26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class BioimageioRepo {
*/
private static List<String> modelIDs;

private static LinkedHashMap<Path, ModelDescriptor> models;
private static LinkedHashMap<String, ModelDescriptor> models;

/**
* Structure of the map:
Expand Down Expand Up @@ -174,12 +174,12 @@ public void refresh() {
* @return an object containing the URL location of the model as key and the {@link ModelDescriptor}
* with the yaml file information in the value
*/
public Map<Path, ModelDescriptor> listAllModels(boolean verbose) {
public Map<String, ModelDescriptor> listAllModels(boolean verbose) {
if (models != null && models.entrySet().size() > 0)
return models;
if (verbose)
Log.addProgressAndShowInTerminal(consumer, "BioImage.io: Accessing the BioImage.io API to retrieve available models", true);
models = new LinkedHashMap<Path, ModelDescriptor>();
models = new LinkedHashMap<String, ModelDescriptor>();
if (collections == null) {
if (verbose)
Log.addProgressAndShowInTerminal(consumer, MODELS_NOT_FOUND_MSG, true);
Expand All @@ -200,7 +200,7 @@ public Map<Path, ModelDescriptor> listAllModels(boolean verbose) {
continue;
String stringRDF = getJSONFromUrl(url);
ModelDescriptor descriptor = ModelDescriptorFactory.readFromYamlTextString(stringRDF);
models.put(Paths.get(url), descriptor);
models.put(url, descriptor);
} catch (Exception ex) {
// TODO Maybe add some error message? This should be responsibility of the BioImage.io user
// Only display error message if there was an error creating
Expand Down Expand Up @@ -407,7 +407,7 @@ public static boolean isModelOnTheBioengineById(String id) throws IOException {
*/
public ModelDescriptor selectByID(String modelID) {
Objects.requireNonNull(modelID, "Argument 'modelID' cannot be null.");
Entry<Path, ModelDescriptor> modelEntry = this.listAllModels(false).entrySet().stream()
Entry<String, ModelDescriptor> modelEntry = this.listAllModels(false).entrySet().stream()
.filter(ee -> {
String id = ee.getValue().getModelID();
if (id.length() - id.replace("/", "").length() == 2) {
Expand All @@ -432,7 +432,7 @@ public ModelDescriptor selectByID(String modelID) {
*/
public ModelDescriptor selectByName(String name) {
Objects.requireNonNull(name, "Argument 'name' cannot be null.");
Entry<Path, ModelDescriptor> modelEntry = this.listAllModels(false).entrySet().stream()
Entry<String, ModelDescriptor> modelEntry = this.listAllModels(false).entrySet().stream()
.filter(ee -> ee.getValue().getName().equals(name)).findFirst().orElse(null);
if (modelEntry != null)
return modelEntry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -88,10 +87,10 @@ public static void main(String[] args) {
installAllValidEngines();

BioimageioRepo br = BioimageioRepo.connect();
Map<Path, ModelDescriptor> bmzModelList = br.listAllModels(false);
Map<String, ModelDescriptor> bmzModelList = br.listAllModels(false);
int successModelCount = 0;

for (Entry<Path, ModelDescriptor> modelEntry : bmzModelList.entrySet()) {
for (Entry<String, ModelDescriptor> modelEntry : bmzModelList.entrySet()) {
try {
checkModelCompatibleWithEngines(modelEntry.getValue());
String modelFolder = br.downloadByName(modelEntry.getValue().getName(), MODELS_DIR);
Expand Down

0 comments on commit 18b7e26

Please sign in to comment.