From 00ed6fb40301a0e50c78a3e154089421301e42ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Szeremeta?= Date: Sat, 3 Apr 2021 22:20:52 +0200 Subject: [PATCH] Add subject type option --- README.md | 1 + .../java/pl/edu/uwb/ii/sdfeater/File.java | 11 +- .../java/pl/edu/uwb/ii/sdfeater/Molecule.java | 43 ++- .../java/pl/edu/uwb/ii/sdfeater/SDFEater.java | 50 ++- .../pl/edu/uwb/ii/sdfeater/OutputTest.java | 325 ++++++++++++++++-- 5 files changed, 365 insertions(+), 65 deletions(-) diff --git a/README.md b/README.md index 82dd2a8..7405bd8 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) * `-p,--periodic` - add additional atoms data from [periodic table](https://github.com/lszeremeta/SDFEater/blob/master/src/main/resources/pl/edu/uwb/ii/sdfeater/periodic_table.json) (for `cypher` output format) +* `-s,--subject ` - subject type (`iri`, `uuid`, `bnode`; `iri` by default; for all formats excluding cypher, cvme, smiles, inchi) * `-u,--urls` - try to generate full database URLs instead of IDs (for `cypher` output format, always enabled in `cvme`) 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/File.java b/src/main/java/pl/edu/uwb/ii/sdfeater/File.java index 7ab1e64..d097577 100644 --- a/src/main/java/pl/edu/uwb/ii/sdfeater/File.java +++ b/src/main/java/pl/edu/uwb/ii/sdfeater/File.java @@ -58,9 +58,10 @@ class File { * appropriate program structures * * @param molecule Molecule object to which values from the file will be entered - * @param format Output format from Format enum + * @param format Output format + * @param subject Subject type */ - void parse(Molecule molecule, SDFEater.Format format) { + void parse(Molecule molecule, SDFEater.Format format, SDFEater.Subject subject) { try { FileInputStream fstream = new FileInputStream(filename); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); @@ -156,13 +157,13 @@ void parse(Molecule molecule, SDFEater.Format format) { case jsonldhtml: case rdfxml: case rdfthrift: - molecule.addToJenaModel(); + molecule.addToJenaModel(subject); break; case rdfa: - molecule.printRDFaMolecule(); + molecule.printRDFaMolecule(subject); break; case microdata: - molecule.printMicrodataMolecule(); + molecule.printMicrodataMolecule(subject); break; default: break; 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 f55e3eb..bfb04f8 100644 --- a/src/main/java/pl/edu/uwb/ii/sdfeater/Molecule.java +++ b/src/main/java/pl/edu/uwb/ii/sdfeater/Molecule.java @@ -324,9 +324,20 @@ void printChemSKOSMolecule() { /** * Add main molecule data to Jena model + * + * @param subject subject type */ - void addToJenaModel() { - Resource me = ResourceFactory.createResource("http://example.com/molecule#entity" + createID()); + void addToJenaModel(SDFEater.Subject subject) { + Resource me = ResourceFactory.createResource(); + + if (subject == SDFEater.Subject.iri) { + me = ResourceFactory.createResource("http://example.com/molecule#entity" + createID()); + } else if (subject == SDFEater.Subject.uuid) { + me = ResourceFactory.createResource("urn:uuid:" + uuid); + } else if (subject == SDFEater.Subject.bnode) { + me = ResourceFactory.createResource(); + } + for (Map.Entry> entry : properties.entrySet()) { String key = entry.getKey(); @@ -381,7 +392,7 @@ void addToJenaModel() { /** * Print main molecule data in RDFa */ - void printRDFaMolecule() { + void printRDFaMolecule(SDFEater.Subject subject) { StringBuilder output_str = new StringBuilder(); for (Map.Entry> entry : properties.entrySet()) { String key = entry.getKey(); @@ -421,8 +432,15 @@ void printRDFaMolecule() { } if (output_str.length() > 0) { - String mID = createID(); - System.out.println("
"); + if (subject == SDFEater.Subject.iri) { + String mID = createID(); + System.out.println("
"); + } else if (subject == SDFEater.Subject.uuid) { + System.out.println("
"); + } else if (subject == SDFEater.Subject.bnode) { + System.out.println("
"); + } + System.out.print(output_str); System.out.println("
"); } @@ -431,8 +449,10 @@ void printRDFaMolecule() { /** * Print main molecule data in Microdata + * + * @param subject subject type */ - void printMicrodataMolecule() { + void printMicrodataMolecule(SDFEater.Subject subject) { StringBuilder output_str = new StringBuilder(); for (Map.Entry> entry : properties.entrySet()) { String key = entry.getKey(); @@ -472,8 +492,15 @@ void printMicrodataMolecule() { } if (output_str.length() > 0) { - String mID = createID(); - System.out.println("
"); + if (subject == SDFEater.Subject.iri) { + String mID = createID(); + System.out.println("
"); + } else if (subject == SDFEater.Subject.uuid) { + System.out.println("
"); + } else if (subject == SDFEater.Subject.bnode) { + System.out.println("
"); + } + System.out.print(output_str); System.out.println("
"); } 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 b2ffc1e..9073335 100644 --- a/src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java +++ b/src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java @@ -87,6 +87,9 @@ public static void main(String[] args) { Option formatarg = new Option("f", "format", true, "output format (cypher, cvme, smiles, inchi, turtle, ntriples, rdfxml, rdfthrift, jsonldhtml, jsonld, rdfa, microdata)"); formatarg.setRequired(true); options.addOption(formatarg); + 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 urls = new Option("u", "urls", false, "try to generate full database URLs instead of IDs (for cypher output format, always enabled in cvme)"); urls.setRequired(false); options.addOption(urls); @@ -103,51 +106,57 @@ public static void main(String[] args) { if (cmd.hasOption("format")) { String format = cmd.getOptionValue("format"); if (format.equalsIgnoreCase("cypher") && !cmd.hasOption("urls") && !cmd.hasOption("periodic")) { - file.parse(molecule, Format.cypher); + file.parse(molecule, Format.cypher, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("cypher") && cmd.hasOption("urls") && !cmd.hasOption("periodic")) { - file.parse(molecule, Format.cypheru); + file.parse(molecule, Format.cypheru, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("cypher") && cmd.hasOption("periodic") && !cmd.hasOption("urls")) { loadPeriodicTableData(); - file.parse(molecule, Format.cypherp); + file.parse(molecule, Format.cypherp, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("cypher") && cmd.hasOption("urls") && cmd.hasOption("periodic")) { loadPeriodicTableData(); - file.parse(molecule, Format.cypherup); + file.parse(molecule, Format.cypherup, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("cvme")) { - file.parse(molecule, Format.cvme); + file.parse(molecule, Format.cvme, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("smiles")) { - file.parse(molecule, Format.smiles); + file.parse(molecule, Format.smiles, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("inchi")) { - file.parse(molecule, Format.inchi); + file.parse(molecule, Format.inchi, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("turtle")) { initializeJenaModel(); - file.parse(molecule, Format.turtle); + file.parse(molecule, Format.turtle, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("ntriples")) { initializeJenaModel(); - file.parse(molecule, Format.ntriples); + file.parse(molecule, Format.ntriples, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("jsonldhtml")) { initializeJenaModel(); - file.parse(molecule, Format.jsonldhtml); + file.parse(molecule, Format.jsonldhtml, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("jsonld")) { initializeJenaModel(); - file.parse(molecule, Format.jsonld); + file.parse(molecule, Format.jsonld, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("rdfxml")) { initializeJenaModel(); - file.parse(molecule, Format.rdfxml); + file.parse(molecule, Format.rdfxml, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("rdfthrift")) { initializeJenaModel(); - file.parse(molecule, Format.rdfthrift); + file.parse(molecule, Format.rdfthrift, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("rdfa")) { - file.parse(molecule, Format.rdfa); + file.parse(molecule, Format.rdfa, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else if (format.equalsIgnoreCase("microdata")) { - file.parse(molecule, Format.microdata); + file.parse(molecule, Format.microdata, Subject.valueOf(cmd.getOptionValue("subject", Subject.iri.toString()))); } else { System.err.println("The selected format is not supported"); formatter.printHelp("SDFEater.jar", options); } } + } catch (IllegalArgumentException e) { + System.err.println("Incorrect option selected"); + formatter.printHelp("SDFEater.jar", options); } catch (ParseException e) { - System.err.println(e.getMessage()); + System.err.println("Parse error: " + e.getMessage()); + formatter.printHelp("SDFEater.jar", options); + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); formatter.printHelp("SDFEater.jar", options); } } @@ -172,4 +181,13 @@ public enum Format { rdfa, microdata } + + /** + * Subject type + */ + public enum Subject { + iri, + uuid, + bnode + } } diff --git a/src/test/java/pl/edu/uwb/ii/sdfeater/OutputTest.java b/src/test/java/pl/edu/uwb/ii/sdfeater/OutputTest.java index a44045f..b5f4cb5 100644 --- a/src/test/java/pl/edu/uwb/ii/sdfeater/OutputTest.java +++ b/src/test/java/pl/edu/uwb/ii/sdfeater/OutputTest.java @@ -7,6 +7,7 @@ import java.io.PrintStream; import java.nio.file.Paths; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static pl.edu.uwb.ii.sdfeater.SDFEater.initializeJenaModel; import static pl.edu.uwb.ii.sdfeater.SDFEater.loadPeriodicTableData; @@ -53,7 +54,7 @@ void setUp() { */ @Test void cypherRawContainsRequiredStrings() { - file.parse(molecule, SDFEater.Format.cypher); + file.parse(molecule, SDFEater.Format.cypher, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"CREATE (", "{", "}", ",", ")", ":", "[", "]", "'", ":", "->", ")-[:", "]->(", "symbol:", "C", "x:", "y:", "z:"}; assertTrue(stringContainsAllValues(out, required)); @@ -64,7 +65,7 @@ void cypherRawContainsRequiredStrings() { */ @Test void cypherRawContainsAllMoleculeData() { - file.parse(molecule, SDFEater.Format.cypher); + file.parse(molecule, SDFEater.Format.cypher, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } @@ -76,7 +77,7 @@ void cypherRawContainsAllMoleculeData() { */ @Test void cypherURLContainsRequiredStrings() { - file.parse(molecule, SDFEater.Format.cypheru); + file.parse(molecule, SDFEater.Format.cypheru, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"CREATE (", "{", "}", ",", ")", ":", "'", ":", ")-[:", "]->(", "symbol:", "C", "x:", "y:", "z:", "http", "//", "/"}; assertTrue(stringContainsAllValues(out, required)); @@ -87,7 +88,7 @@ void cypherURLContainsRequiredStrings() { */ @Test void cypherURLContainsAllMoleculeData() { - file.parse(molecule, SDFEater.Format.cypheru); + file.parse(molecule, SDFEater.Format.cypheru, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } @@ -100,7 +101,7 @@ void cypherURLContainsAllMoleculeData() { @Test void cypherPeriodicContainsRequiredStrings() { loadPeriodicTableData(); - file.parse(molecule, SDFEater.Format.cypherp); + file.parse(molecule, SDFEater.Format.cypherp, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"CREATE (", "{", "}", ",", ")", ":", "'", ":", ")-[:", "]->(", "symbol:", "C", "x:", "y:", "z:", "atomicNumber:", "name:", "Carbon", "atomicMass:", "bondingType:"}; assertTrue(stringContainsAllValues(out, required)); @@ -112,7 +113,7 @@ void cypherPeriodicContainsRequiredStrings() { @Test void cypherPeriodicContainsAllMoleculeData() { loadPeriodicTableData(); - file.parse(molecule, SDFEater.Format.cypherp); + file.parse(molecule, SDFEater.Format.cypherp, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } @@ -125,7 +126,7 @@ void cypherPeriodicContainsAllMoleculeData() { @Test void cypherAllContainsRequiredStrings() { loadPeriodicTableData(); - file.parse(molecule, SDFEater.Format.cypherup); + file.parse(molecule, SDFEater.Format.cypherup, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"CREATE (", "{", "}", ",", ")", ":", "'", ":", ")-[:", "]->(", "symbol:", "C", "x:", "y:", "z:", "http", "//", "/", "atomicNumber:", "name:", "Carbon", "atomicMass:", "bondingType:"}; assertTrue(stringContainsAllValues(out, required)); @@ -137,7 +138,7 @@ void cypherAllContainsRequiredStrings() { @Test void cypherAllContainsAllMoleculeData() { loadPeriodicTableData(); - file.parse(molecule, SDFEater.Format.cypherup); + file.parse(molecule, SDFEater.Format.cypherup, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } @@ -149,7 +150,7 @@ void cypherAllContainsAllMoleculeData() { */ @Test void cvmeContainsRequiredStrings() { - file.parse(molecule, SDFEater.Format.cvme); + file.parse(molecule, SDFEater.Format.cvme, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"skos:altLabel", "skos:definition", "skos:notation", "skos:prefLabel", "rdfs:seeAlso", "dbo:inchi", "dbp:inchikey", "dbo:casNumber", "skos:hiddenLabel", "skos:example", "urn:uuid:", "^^", "@", "chemskos:SMILES", ".", "<", ">", "http", ":", "//", "\"\"\"", "END", "C"}; assertTrue(stringContainsAllValues(out, required)); @@ -160,7 +161,7 @@ void cvmeContainsRequiredStrings() { */ @Test void cvmeContainsAllMoleculeData() { - file.parse(molecule, SDFEater.Format.cvme); + file.parse(molecule, SDFEater.Format.cvme, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } @@ -172,7 +173,7 @@ void cvmeContainsAllMoleculeData() { */ @Test void smilesContainsSMILES() { - file.parse(molecule, SDFEater.Format.smiles); + file.parse(molecule, SDFEater.Format.smiles, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"[H][C@@]1(Oc2cc(O)cc(O)c2C[C@H]1O)c1ccc(O)c(O)c1", "CC1(C)[C@@H]2CC[C@@](C)(C2)C1=O"}; assertTrue(stringContainsAllValues(out, required)); @@ -185,7 +186,7 @@ void smilesContainsSMILES() { */ @Test void inchiContainsInChI() { - file.parse(molecule, SDFEater.Format.inchi); + file.parse(molecule, SDFEater.Format.inchi, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"InChI=1S/C15H14O6/c16-8-4-11(18)9-6-13(20)15(21-14(9)5-8)7-1-2-10(17)12(19)3-7/h1-5,13,15-20H,6H2/t13-,15-/m1/s1", "InChI=1S/C10H16O/c1-9(2)7-4-5-10(3,6-7)8(9)11/h7H,4-6H2,1-3H3/t7-,10+/m1/s1"}; assertTrue(stringContainsAllValues(out, required)); @@ -199,7 +200,7 @@ void inchiContainsInChI() { @Test void turtleContainsRequiredStrings() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.turtle); + file.parse(molecule, SDFEater.Format.turtle, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"@prefix", "schema.org", "rdf", "MolecularEntity", "[", ";", "]", ".", "<", ">", "http", "//", ":", "\""}; assertTrue(stringContainsAllValues(out, required)); @@ -211,7 +212,7 @@ void turtleContainsRequiredStrings() { @Test void turtleContainsAllMoleculeDataFields() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.turtle); + file.parse(molecule, SDFEater.Format.turtle, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeDataFields)); } @@ -222,11 +223,47 @@ void turtleContainsAllMoleculeDataFields() { @Test void turtleContainsAllMoleculeData() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.turtle); + file.parse(molecule, SDFEater.Format.turtle, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } + /** + * Test if Turtle output have IRI subject + */ + @Test + void turtleHaveIRISubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.turtle, SDFEater.Subject.iri); + String out = outputStreamCaptor.toString(); + String[] required = {"http", "example.com", "molecule", "#", "entity"}; + assertTrue(stringContainsAllValues(out, required)); + } + + /** + * Test if Turtle output have uuid subject + */ + @Test + void turtleHaveUUIDSubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.turtle, SDFEater.Subject.uuid); + String out = outputStreamCaptor.toString(); + String[] required = {"urn:uuid:"}; + assertTrue(stringContainsAllValues(out, required)); + } + + /** + * Test if Turtle output have bNode subject + */ + @Test + void turtleHaveBNodeSubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.turtle, SDFEater.Subject.bnode); + String out = outputStreamCaptor.toString(); + String[] required = {"[", "]"}; + assertTrue(stringContainsAllValues(out, required)); + } + // N-Triples /** @@ -235,7 +272,7 @@ void turtleContainsAllMoleculeData() { @Test void nTriplesContainsRequiredStrings() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.ntriples); + file.parse(molecule, SDFEater.Format.ntriples, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"schema.org", "rdf", "MolecularEntity", ".", "<", ">", "http", "//", ":", "\""}; assertTrue(stringContainsAllValues(out, required)); @@ -247,7 +284,7 @@ void nTriplesContainsRequiredStrings() { @Test void nTriplesContainsAllMoleculeDataFields() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.ntriples); + file.parse(molecule, SDFEater.Format.ntriples, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeDataFields)); } @@ -258,11 +295,47 @@ void nTriplesContainsAllMoleculeDataFields() { @Test void nTriplesContainsAllMoleculeData() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.ntriples); + file.parse(molecule, SDFEater.Format.ntriples, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } + /** + * Test if N-Triples output have IRI subject + */ + @Test + void nTriplesHaveIRISubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.ntriples, SDFEater.Subject.iri); + String out = outputStreamCaptor.toString(); + String[] required = {"http", "example.com", "molecule", "#", "entity"}; + assertTrue(stringContainsAllValues(out, required)); + } + + /** + * Test if N-Triples output have uuid subject + */ + @Test + void nTriplesHaveUUIDSubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.ntriples, SDFEater.Subject.uuid); + String out = outputStreamCaptor.toString(); + String[] required = {"urn:uuid:"}; + assertTrue(stringContainsAllValues(out, required)); + } + + /** + * Test if N-Triples output have bNode subject + */ + @Test + void nTriplesHaveBNodeSubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.ntriples, SDFEater.Subject.bnode); + String out = outputStreamCaptor.toString(); + String[] required = {"_:"}; + assertTrue(stringContainsAllValues(out, required)); + } + // RDF/XML /** @@ -271,7 +344,7 @@ void nTriplesContainsAllMoleculeData() { @Test void rdfXMLContainsRequiredStrings() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.rdfxml); + file.parse(molecule, SDFEater.Format.rdfxml, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"<", ">", "rdf:RDF", "xmlns:", "", "", "@id", "{", "}", ",", "MolecularEntity"}; assertTrue(stringContainsAllValues(out, required)); @@ -355,7 +500,7 @@ void jsonldHtmlContainsRequiredStrings() { @Test void jsonldHtmlContainsAllMoleculeDataFields() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.jsonldhtml); + file.parse(molecule, SDFEater.Format.jsonldhtml, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeDataFields)); } @@ -366,7 +511,7 @@ void jsonldHtmlContainsAllMoleculeDataFields() { @Test void jsonldHtmlContainsAllMoleculeData() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.jsonldhtml); + file.parse(molecule, SDFEater.Format.jsonldhtml, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } @@ -379,7 +524,7 @@ void jsonldHtmlContainsAllMoleculeData() { @Test void jsonldContainsRequiredStrings() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.jsonld); + file.parse(molecule, SDFEater.Format.jsonld, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"@id", "{", "}", ",", "MolecularEntity"}; assertTrue(stringContainsAllValues(out, required)); @@ -391,7 +536,7 @@ void jsonldContainsRequiredStrings() { @Test void jsonldContainsAllMoleculeDataFields() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.jsonld); + file.parse(molecule, SDFEater.Format.jsonld, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeDataFields)); } @@ -402,11 +547,47 @@ void jsonldContainsAllMoleculeDataFields() { @Test void jsonldContainsAllMoleculeData() { initializeJenaModel(); - file.parse(molecule, SDFEater.Format.jsonld); + file.parse(molecule, SDFEater.Format.jsonld, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); assertTrue(stringContainsAllValues(out, testMoleculeData)); } + /** + * Test if JSON-LD output have IRI subject + */ + @Test + void jsonldHaveIRISubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.jsonld, SDFEater.Subject.iri); + String out = outputStreamCaptor.toString(); + String[] required = {"http", "example.com", "molecule", "#", "entity"}; + assertTrue(stringContainsAllValues(out, required)); + } + + /** + * Test if JSON-LD output have uuid subject + */ + @Test + void jsonldHaveUUIDSubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.jsonld, SDFEater.Subject.uuid); + String out = outputStreamCaptor.toString(); + String[] required = {"urn:uuid:"}; + assertTrue(stringContainsAllValues(out, required)); + } + + /** + * Test if JSON-LD output have bNode subject + */ + @Test + void jsonldHaveBNodeSubject() { + initializeJenaModel(); + file.parse(molecule, SDFEater.Format.jsonld, SDFEater.Subject.bnode); + String out = outputStreamCaptor.toString(); + String[] required = {"_:b0"}; + assertTrue(stringContainsAllValues(out, required)); + } + // RDFa /** @@ -414,7 +595,7 @@ void jsonldContainsAllMoleculeData() { */ @Test void rdfaContainsRequiredStrings() { - file.parse(molecule, SDFEater.Format.rdfa); + file.parse(molecule, SDFEater.Format.rdfa, SDFEater.Subject.iri); String out = outputStreamCaptor.toString(); String[] required = {"<", ">", "", "