From f62b083d623ba5acc20411fbbba2b5c600550ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Szeremeta?= Date: Thu, 8 Apr 2021 20:12:43 +0200 Subject: [PATCH] Add --base option --- README.md | 1 + .../java/pl/edu/uwb/ii/sdfeater/Molecule.java | 27 ++++++++++++++++--- .../java/pl/edu/uwb/ii/sdfeater/SDFEater.java | 9 +++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c9c1dca..4fa081e 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ Running SDFEater without parameters displays help. * `-i,--input ` - input SDF file path (required) * `-f,--format ` - output format (e.g. `cypher`, `jsonld`, `cvme`, `smiles`, `inchi`) (required; full list below) * `-s,--subject ` - subject type (`iri`, `uuid`, `bnode`; `iri` by default; for all formats excluding cypher, cvme, smiles, inchi) +* `-b,--base ` - molecule subject base for 'iri' subject type ('https://example.com/molecule#entity' by default) Remember about the appropriate file path when using Docker image. Suppose you mounted your local directory `/home/user/input` under `/app/input` and the path to the SDF file you want to use in SDFEater is `/home/user/input/file.sdf`. In this case, enter the path `/app/input/file.sdf` or `input/file.sdf` as the value of the `-i` argument. diff --git a/src/main/java/pl/edu/uwb/ii/sdfeater/Molecule.java b/src/main/java/pl/edu/uwb/ii/sdfeater/Molecule.java index 7738cb9..764a610 100644 --- a/src/main/java/pl/edu/uwb/ii/sdfeater/Molecule.java +++ b/src/main/java/pl/edu/uwb/ii/sdfeater/Molecule.java @@ -71,6 +71,12 @@ class Molecule { * Stores all properties of the chemical molecule */ private final Map> properties = new HashMap<>(); + + /** + * Subject base of molecule + */ + String subjectBase = "https://example.com/molecule#entity"; + private UUID uuid; Molecule() { @@ -332,7 +338,7 @@ void addToJenaModel(SDFEater.Subject subject) { Resource me = ResourceFactory.createResource(); if (subject == SDFEater.Subject.iri) { - me = ResourceFactory.createResource("https://example.com/molecule#entity" + createID()); + me = ResourceFactory.createResource(subjectBase + createID()); } else if (subject == SDFEater.Subject.uuid) { me = ResourceFactory.createResource("urn:uuid:" + uuid); } else if (subject == SDFEater.Subject.bnode) { @@ -401,7 +407,7 @@ StringBuilder constructJSONLDMolecule(SDFEater.Subject subject) { output_str.append(" {\n"); if (subject == SDFEater.Subject.iri) { - output_str.append(" \"@id\" : \"https://example.com/molecule#entity" + createID() + "\",\n"); + output_str.append(" \"@id\" : \"" + subjectBase + createID() + "\",\n"); } else if (subject == SDFEater.Subject.uuid) { output_str.append(" \"@id\" : \"urn:uuid:" + uuid + "\",\n"); } else if (subject == SDFEater.Subject.bnode) { @@ -499,7 +505,14 @@ void printRDFaMolecule(SDFEater.Subject subject) { if (output_str.length() > 0) { if (subject == SDFEater.Subject.iri) { String mID = createID(); - System.out.println("
"); + System.out.print("
\n"); + } else if (subject == SDFEater.Subject.uuid) { System.out.println("
"); } else if (subject == SDFEater.Subject.bnode) { @@ -559,7 +572,13 @@ void printMicrodataMolecule(SDFEater.Subject subject) { if (output_str.length() > 0) { if (subject == SDFEater.Subject.iri) { String mID = createID(); - System.out.println("
"); + System.out.print("
\n"); } else if (subject == SDFEater.Subject.uuid) { System.out.println("
"); } else if (subject == SDFEater.Subject.bnode) { diff --git a/src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java b/src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java index 50c9d5f..9a07143 100644 --- a/src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java +++ b/src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java @@ -90,6 +90,9 @@ public static void main(String[] args) { Option subject = new Option("s", "subject", true, "subject type (iri, uuid, bnode; iri by default); for all formats excluding cypher, cvme, smiles, inchi"); subject.setRequired(false); options.addOption(subject); + Option base = new Option("b", "base", true, "molecule subject base for 'iri' subject type ('" + molecule.subjectBase + "' by default)"); + base.setRequired(false); + options.addOption(base); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; @@ -111,6 +114,12 @@ public static void main(String[] args) { initializeJenaModel(); break; } + + // replace default base molecule IRI + if (cmd.getOptionValue("subject", Subject.iri.toString()).equals(Subject.iri.toString())) { + molecule.subjectBase = cmd.getOptionValue("base", molecule.subjectBase); + } + file.parse(molecule, Format.valueOf(cmd.getOptionValue("format")), Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } catch (IllegalArgumentException e) { System.err.println("Incorrect option selected");