diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/description/SampleImage.java b/src/main/java/io/bioimage/modelrunner/bioimageio/description/SampleImage.java index d97750ec..0761a1fb 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/description/SampleImage.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/description/SampleImage.java @@ -27,6 +27,8 @@ import java.util.Arrays; import java.util.List; +import io.bioimage.modelrunner.utils.Constants; + /** * Define each of the sample inputs spedified in the yaml file * @author Carlos Garcia Lopez de Haro @@ -92,6 +94,8 @@ public String getFileExtension() { return null; if (string.lastIndexOf(".") == -1) return null; + if (string.startsWith(Constants.ZENODO_DOMAIN) && string.endsWith(Constants.ZENODO_ANNOYING_SUFFIX)) + return string.substring(string.lastIndexOf("."), string.length() - Constants.ZENODO_ANNOYING_SUFFIX.length()); return string.substring(string.lastIndexOf(".")); } diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/description/TestArtifact.java b/src/main/java/io/bioimage/modelrunner/bioimageio/description/TestArtifact.java index db48f777..4567de44 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/description/TestArtifact.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/description/TestArtifact.java @@ -27,6 +27,8 @@ import java.util.Arrays; import java.util.List; +import io.bioimage.modelrunner.utils.Constants; + /** * Define each of the test inputs and outputs defined in the rdf.yaml file * @author Carlos Garcia Lopez de Haro @@ -92,6 +94,8 @@ public String getFileExtension() { return null; if (string.lastIndexOf(".") == -1) return null; + if (string.startsWith(Constants.ZENODO_DOMAIN) && string.endsWith(Constants.ZENODO_ANNOYING_SUFFIX)) + return string.substring(string.lastIndexOf("."), string.length() - Constants.ZENODO_ANNOYING_SUFFIX.length()); return string.substring(string.lastIndexOf(".")); } diff --git a/src/main/java/io/bioimage/modelrunner/bioimageio/download/DownloadModel.java b/src/main/java/io/bioimage/modelrunner/bioimageio/download/DownloadModel.java index c0a30f9e..aa781b62 100644 --- a/src/main/java/io/bioimage/modelrunner/bioimageio/download/DownloadModel.java +++ b/src/main/java/io/bioimage/modelrunner/bioimageio/download/DownloadModel.java @@ -48,6 +48,7 @@ import io.bioimage.modelrunner.bioimageio.description.weights.WeightFormat; import io.bioimage.modelrunner.engine.EngineInfo; import io.bioimage.modelrunner.engine.installation.FileDownloader; +import io.bioimage.modelrunner.utils.Constants; import io.bioimage.modelrunner.utils.ZipUtils; /** @@ -512,8 +513,8 @@ private void unzipTfWeights() throws IOException { * @throws MalformedURLException if the String does not correspond to an URL */ public static String getFileNameFromURLString(String str) throws MalformedURLException { - if (str.startsWith("https://zenodo.org/")) - str = str.substring(0, str.length() - "/content".length()); + if (str.startsWith(Constants.ZENODO_DOMAIN)) + str = str.substring(0, str.length() - Constants.ZENODO_ANNOYING_SUFFIX.length()); URL url = new URL(str); return new File(url.getPath()).getName(); } diff --git a/src/main/java/io/bioimage/modelrunner/utils/Constants.java b/src/main/java/io/bioimage/modelrunner/utils/Constants.java index 4c20d8d5..3dad591e 100644 --- a/src/main/java/io/bioimage/modelrunner/utils/Constants.java +++ b/src/main/java/io/bioimage/modelrunner/utils/Constants.java @@ -35,4 +35,12 @@ public class Constants { * File name of the resource description file inside the model folder */ public static final String RDF_FNAME = "rdf.yaml"; + /** + * Last part of files stored in zenodo + */ + public static final String ZENODO_ANNOYING_SUFFIX = "/content"; + /** + * Zenodo domain + */ + public static final String ZENODO_DOMAIN = "https://zenodo.org/"; }