Skip to content

Commit

Permalink
Add Dataset schema, JSON-LD rewrite, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lszeremeta committed Apr 5, 2021
1 parent 5a0253b commit 505d424
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 19 deletions.
203 changes: 197 additions & 6 deletions src/main/java/pl/edu/uwb/ii/sdfeater/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.time.Year;

import static pl.edu.uwb.ii.sdfeater.SDFEater.jenaModel;

Expand Down Expand Up @@ -78,7 +79,68 @@ void parse(Molecule molecule, SDFEater.Format format, SDFEater.Subject subject)
"<html lang=\"en\">\n" +
" <head>\n" +
" <title>Example Document</title>\n" +
" <script type=\"application/ld+json\">");
" <script type=\"application/ld+json\">" +
"{\n" +
" \"@graph\" : [\n" +
" {\n" +
" \"@id\": \"https://github.com/lszeremeta/SDFEater\",\n" +
" \"@type\": \"http://schema.org/Organization\",\n" +
" \"http://schema.org/name\": \"SDFEater\"\n" +
" },\n" +
" {\n" +
" \"@id\": \"#\",\n" +
" \"@type\": \"http://schema.org/Dataset\",\n" +
" \"http://schema.org/about\": {\n" +
" \"@id\": \"https://github.com/lszeremeta/SDFEater\"\n" +
" },\n" +
" \"http://schema.org/description\": \"This is a dataset of molecules generated by SDFEater.\",\n" +
" \"http://schema.org/keywords\": [\n" +
" \"molecules\",\n" +
" \"cheminformatics\",\n" +
" \"chemical compounds\"\n" +
" ],\n" +
" \"http://schema.org/license\": {\n" +
" \"@id\": \"http://opendatacommons.org/licenses/pddl/1.0/\"\n" +
" },\n" +
" \"http://schema.org/name\": \"Molecules\",\n" +
" \"http://schema.org/creator\": {\n" +
" \"@id\": \"https://github.com/lszeremeta/SDFEater\"\n" +
" },\n" +
" \"http://schema.org/temporal\": " + Year.now().toString() + ",\n" +
" \"http://schema.org/url\": \"https://github.com/lszeremeta/SDFEater\"\n" +
" },");
break;
case jsonld:
System.out.println(
"{\n" +
" \"@graph\" : [\n" +
" {\n" +
" \"@id\": \"https://github.com/lszeremeta/SDFEater\",\n" +
" \"@type\": \"http://schema.org/Organization\",\n" +
" \"http://schema.org/name\": \"SDFEater\"\n" +
" },\n" +
" {\n" +
" \"@id\": \"#\",\n" +
" \"@type\": \"http://schema.org/Dataset\",\n" +
" \"http://schema.org/about\": {\n" +
" \"@id\": \"https://github.com/lszeremeta/SDFEater\"\n" +
" },\n" +
" \"http://schema.org/description\": \"This is a dataset of molecules generated by SDFEater.\",\n" +
" \"http://schema.org/keywords\": [\n" +
" \"molecules\",\n" +
" \"cheminformatics\",\n" +
" \"chemical compounds\"\n" +
" ],\n" +
" \"http://schema.org/license\": {\n" +
" \"@id\": \"http://opendatacommons.org/licenses/pddl/1.0/\"\n" +
" },\n" +
" \"http://schema.org/name\": \"Molecules\",\n" +
" \"http://schema.org/creator\": {\n" +
" \"@id\": \"https://github.com/lszeremeta/SDFEater\"\n" +
" },\n" +
" \"http://schema.org/temporal\": " + Year.now().toString() + ",\n" +
" \"http://schema.org/url\": \"https://github.com/lszeremeta/SDFEater\"\n" +
" },");
break;
// RDFa
case rdfa:
Expand All @@ -88,6 +150,22 @@ void parse(Molecule molecule, SDFEater.Format format, SDFEater.Subject subject)
System.out.println(" <title>Example Document</title>");
System.out.println(" </head>");
System.out.println(" <body vocab='http://schema.org/'>");
System.out.println(" <div typeof='schema:Dataset'>\n" +
" <div rel='schema:creator'>\n" +
" <div typeof='schema:Organization' about='https://github.com/lszeremeta/SDFEater'>\n" +
" <div property='schema:name' content='SDFEater'></div>\n" +
" </div>\n" +
" </div>\n" +
" <div property='schema:keywords' content='cheminformatics'></div>\n" +
" <div property='schema:keywords' content='molecules'></div>\n" +
" <div property='schema:keywords' content='chemical compounds'></div>\n" +
" <div property='schema:temporal' content='" + Year.now().toString() + "'></div>\n" +
" <div property='schema:name' content='Molecules'></div>\n" +
" <div rel='schema:license' resource='http://opendatacommons.org/licenses/pddl/1.0/'></div>\n" +
" <div property='schema:description' content='This is a dataset of molecules generated by SDFEater.'></div>\n" +
" <div rel='schema:about' resource='https://github.com/lszeremeta/SDFEater'></div>\n" +
" <div property='schema:url' content='https://github.com/lszeremeta/SDFEater'></div>\n" +
" </div>");
break;
// Microdata
case microdata:
Expand All @@ -97,6 +175,19 @@ void parse(Molecule molecule, SDFEater.Format format, SDFEater.Subject subject)
System.out.println(" <title>Example Document</title>");
System.out.println(" </head>");
System.out.println(" <body>");
System.out.println(" <div itemscope itemtype='https://schema.org/Dataset'>\n" +
" <div itemprop='name' content='Molecules'></div>\n" +
" <div itemprop='keywords' content='cheminformatics'></div>\n" +
" <div itemprop='keywords' content='molecules'></div>\n" +
" <div itemprop='keywords' content='chemical compounds'></div>\n" +
" <div itemprop='temporal' content='" + Year.now().toString() + "'></div>\n" +
" <div itemprop='url' content='https://github.com/lszeremeta/SDFEater'></div>\n" +
" <div itemprop='description' content='This is a dataset of molecules generated by SDFEater.'></div>\n" +
" <div itemprop='creator' itemscope itemtype='https://schema.org/Organization'>\n" +
" <div itemprop='name' content='SDFEater'></div>\n" +
" </div>\n" +
" <div itemprop='license' content='http://opendatacommons.org/licenses/pddl/1.0/'></div>\n" +
" </div>");
break;
default:
break;
Expand Down Expand Up @@ -153,12 +244,14 @@ void parse(Molecule molecule, SDFEater.Format format, SDFEater.Subject subject)
break;
case turtle:
case ntriples:
case jsonld:
case jsonldhtml:
case rdfxml:
case rdfthrift:
molecule.addToJenaModel(subject);
break;
case jsonldhtml:
case jsonld:
molecule.printJSONLDMolecule(subject);
break;
case rdfa:
molecule.printRDFaMolecule(subject);
break;
Expand Down Expand Up @@ -294,12 +387,110 @@ void parse(Molecule molecule, SDFEater.Format format, SDFEater.Subject subject)
jenaModel.write(System.out, "NTRIPLES");
break;
case jsonld:
jenaModel.write(System.out, "JSONLD");
System.out.println(" ],\n" +
" \"@context\" : {\n" +
" \"identifier\" : {\n" +
" \"@id\" : \"https://schema.org/identifier\"\n" +
" },\n" +
" \"name\" : {\n" +
" \"@id\" : \"https://schema.org/name\"\n" +
" },\n" +
" \"inChIKey\" : {\n" +
" \"@id\" : \"https://schema.org/inChIKey\"\n" +
" },\n" +
" \"inChI\" : {\n" +
" \"@id\" : \"https://schema.org/inChI\"\n" +
" },\n" +
" \"smiles\" : {\n" +
" \"@id\" : \"https://schema.org/smiles\"\n" +
" },\n" +
" \"url\" : {\n" +
" \"@id\" : \"https://schema.org/url\"\n" +
" },\n" +
" \"iupacName\" : {\n" +
" \"@id\" : \"https://schema.org/iupacName\"\n" +
" },\n" +
" \"molecularFormula\" : {\n" +
" \"@id\" : \"https://schema.org/molecularFormula\"\n" +
" },\n" +
" \"molecularWeight\" : {\n" +
" \"@id\" : \"https://schema.org/molecularWeight\"\n" +
" },\n" +
" \"monoisotopicMolecularWeight\" : {\n" +
" \"@id\" : \"https://schema.org/monoisotopicMolecularWeight\"\n" +
" },\n" +
" \"description\" : {\n" +
" \"@id\" : \"https://schema.org/description\"\n" +
" },\n" +
" \"disambiguatingDescription\" : {\n" +
" \"@id\" : \"https://schema.org/disambiguatingDescription\"\n" +
" },\n" +
" \"image\" : {\n" +
" \"@id\" : \"https://schema.org/image\"\n" +
" },\n" +
" \"alternateName\" : {\n" +
" \"@id\" : \"https://schema.org/alternateName\"\n" +
" },\n" +
" \"sameAs\" : {\n" +
" \"@id\" : \"https://schema.org/sameAs\"\n" +
" },\n" +
" \"schema\" : \"https://schema.org/\"\n" +
" }\n" +
"}");
break;
// JSON-LD with HTML
case jsonldhtml:
jenaModel.write(System.out, "JSONLD");
System.out.println(" </script>\n" +
System.out.println(" ],\n" +
" \"@context\" : {\n" +
" \"identifier\" : {\n" +
" \"@id\" : \"https://schema.org/identifier\"\n" +
" },\n" +
" \"name\" : {\n" +
" \"@id\" : \"https://schema.org/name\"\n" +
" },\n" +
" \"inChIKey\" : {\n" +
" \"@id\" : \"https://schema.org/inChIKey\"\n" +
" },\n" +
" \"inChI\" : {\n" +
" \"@id\" : \"https://schema.org/inChI\"\n" +
" },\n" +
" \"smiles\" : {\n" +
" \"@id\" : \"https://schema.org/smiles\"\n" +
" },\n" +
" \"url\" : {\n" +
" \"@id\" : \"https://schema.org/url\"\n" +
" },\n" +
" \"iupacName\" : {\n" +
" \"@id\" : \"https://schema.org/iupacName\"\n" +
" },\n" +
" \"molecularFormula\" : {\n" +
" \"@id\" : \"https://schema.org/molecularFormula\"\n" +
" },\n" +
" \"molecularWeight\" : {\n" +
" \"@id\" : \"https://schema.org/molecularWeight\"\n" +
" },\n" +
" \"monoisotopicMolecularWeight\" : {\n" +
" \"@id\" : \"https://schema.org/monoisotopicMolecularWeight\"\n" +
" },\n" +
" \"description\" : {\n" +
" \"@id\" : \"https://schema.org/description\"\n" +
" },\n" +
" \"disambiguatingDescription\" : {\n" +
" \"@id\" : \"https://schema.org/disambiguatingDescription\"\n" +
" },\n" +
" \"image\" : {\n" +
" \"@id\" : \"https://schema.org/image\"\n" +
" },\n" +
" \"alternateName\" : {\n" +
" \"@id\" : \"https://schema.org/alternateName\"\n" +
" },\n" +
" \"sameAs\" : {\n" +
" \"@id\" : \"https://schema.org/sameAs\"\n" +
" },\n" +
" \"schema\" : \"https://schema.org/\"\n" +
" }\n" +
"}" +
" </script>\n" +
" </head>\n" +
"</html>");
break;
Expand Down
Loading

0 comments on commit 505d424

Please sign in to comment.