Skip to content

Commit

Permalink
Add JSON-LD with HTML output
Browse files Browse the repository at this point in the history
  • Loading branch information
lszeremeta committed Aug 10, 2019
1 parent f1fa13c commit ca83a68
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ You can specify the output format using `-f,--format`. Available output formats:
* `ntriples` - [N-Triples](https://www.w3.org/TR/n-triples/) (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
* `rdfxml` - [RDF/XML](https://www.w3.org/TR/rdf-syntax-grammar/) (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
* `rdfthrift` - [RDF Binary encoding using Thrift](https://afs.github.io/rdf-thrift/rdf-binary-thrift.html) (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
* `jsonldhtml` - [JSON-LD](https://json-ld.org/) with HTML (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
* `jsonld` - [JSON-LD](https://json-ld.org/) (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
* `rdfa` - Simple HTML with [RDFa](http://rdfa.info/) (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
* `microdata` - Simple HTML with [Microdata](https://www.w3.org/TR/microdata/) (based on [MolecularEntitly](https://bioschemas.org/types/MolecularEntity/) type)
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/pl/edu/uwb/ii/sdfeater/File.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* The MIT License
*
* Copyright 2017-2019 Łukasz Szeremeta.
Expand Down Expand Up @@ -48,7 +48,6 @@ class File {
* File class constructor
*
* @param filename filename of input file
*
*/
File(String filename) {
this.filename = filename;
Expand All @@ -59,12 +58,11 @@ class File {
* appropriate program structures
*
* @param molecule Molecule object to which values from the file will be entered
* @param format Output format: c - Cypher, r - cvme, s - smiles, n - inchi
* @param urls Try to generate full database URLs instead of IDs
* (true/false)
* @param format Output format: c - Cypher, r - cvme, s - smiles, n - inchi
* @param urls Try to generate full database URLs instead of IDs
* (true/false)
* @param periodic Map with additional atoms data from periodic table for
* cypher format (true/false)
*
* cypher format (true/false)
*/
void parse(Molecule molecule, char format, boolean urls, boolean periodic) {
try {
Expand All @@ -77,6 +75,14 @@ void parse(Molecule molecule, char format, boolean urls, boolean periodic) {

/* Do something BEFORE file reading */
switch (format) {
// JSON-LD with HTML
case 'd':
System.out.println("<!DOCTYPE html>\n" +
"<html lang=\"en\">\n" +
" <head>\n" +
" <title>Example Document</title>\n" +
" <script type=\"application/ld+json\">");
break;
// RDFa
case 'a':
System.out.println("<!DOCTYPE html>");
Expand Down Expand Up @@ -147,6 +153,7 @@ void parse(Molecule molecule, char format, boolean urls, boolean periodic) {
case 't':
case 'n':
case 'j':
case 'd':
case 'x':
case 'h':
molecule.addToJenaModel();
Expand Down Expand Up @@ -287,6 +294,13 @@ void parse(Molecule molecule, char format, boolean urls, boolean periodic) {
case 'j':
jenaModel.write(System.out, "JSONLD");
break;
// JSON-LD with HTML
case 'd':
jenaModel.write(System.out, "JSONLD");
System.out.println(" </script>\n" +
" </head>\n" +
"</html>");
break;
case 'x':
jenaModel.write(System.out, "RDF/XML");
break;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/pl/edu/uwb/ii/sdfeater/SDFEater.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ public static void main(String[] args) {
} else if (format.equalsIgnoreCase("ntriples")) {
initializeJenaModel();
file.parse(molecule, 'n', false, false);
} else if (format.equalsIgnoreCase("jsonldhtml")) {
initializeJenaModel();
file.parse(molecule, 'd', false, false);
} else if (format.equalsIgnoreCase("jsonld")) {
initializeJenaModel();
file.parse(molecule, 'j', false, false);
Expand Down

0 comments on commit ca83a68

Please sign in to comment.