Skip to content

Commit

Permalink
Use jsonld.js to compact generated documents
Browse files Browse the repository at this point in the history
Closes GH-25
  • Loading branch information
hjonin authored Mar 19, 2024
1 parent c1bce7d commit f94dd52
Show file tree
Hide file tree
Showing 14 changed files with 336 additions and 98 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
cypress/screenshots
node_modules
package-lock.json
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ To run them, first install Cypress:

```
sudo apt install npm # or the equivalent on your system
npm install cypress
$(npm bin)/cypress install
npx [email protected] install
```

Then, run the tests:

```
$(npm bin)/cypress run
npx cypress@9.7.0 run
```


Expand Down
8 changes: 4 additions & 4 deletions cypress/integration/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('JSON Generation', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
});
});
Expand All @@ -48,7 +48,7 @@ describe('JSON Generation', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"license": "https://spdx.org/licenses/AGPL-3.0",
"dateCreated": "2019-10-02",
"datePublished": "2020-01-01",
Expand All @@ -74,7 +74,7 @@ describe('JSON Generation', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"license": ["https://spdx.org/licenses/AGPL-3.0", "https://spdx.org/licenses/MIT"],
"dateCreated": "2019-10-02",
"datePublished": "2020-01-01",
Expand All @@ -97,7 +97,7 @@ describe('JSON Generation', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"license": "https://spdx.org/licenses/AGPL-3.0",
"dateCreated": "2019-10-02",
"datePublished": "2020-01-01",
Expand Down
48 changes: 24 additions & 24 deletions cypress/integration/persons.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Zero author', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
});
});
Expand Down Expand Up @@ -90,18 +90,18 @@ describe('One full author', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"@type": "Person",
"@id": "http://example.org/~jdoe",
"type": "Person",
"id": "http://example.org/~jdoe",
"givenName": "Jane",
"familyName": "Doe",
"email": "[email protected]",
"affiliation": {
"@type": "Organization",
"@id": "http://example.org/",
"type": "Organization",
"id": "http://example.org/",
}
}
],
Expand Down Expand Up @@ -157,15 +157,15 @@ describe('Affiliation id', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"@type": "Person",
"type": "Person",
"givenName": "Jane",
"affiliation": {
"@type": "Organization",
"@id": "http://example.org/",
"type": "Organization",
"id": "http://example.org/",
}
}
],
Expand Down Expand Up @@ -217,14 +217,14 @@ describe('Affiliation name', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"@type": "Person",
"type": "Person",
"givenName": "Jane",
"affiliation": {
"@type": "Organization",
"type": "Organization",
"name": "Example Org",
}
}
Expand Down Expand Up @@ -271,12 +271,12 @@ describe('Author order change', function() {
cy.get('#author_1_givenName').type('Jane');
cy.get('#author_1_affiliation').type('Example Org');

cy.get('#author_1_moveToRight').click()
cy.get('#author_1_moveToRight').click();

cy.get('#author_1_givenName').should('have.value', 'Jane');
cy.get('#author_1_affiliation').should('have.value', 'Example Org');

cy.get('#author_1_moveToLeft').click()
cy.get('#author_1_moveToLeft').click();

cy.get('#author_1_givenName').should('have.value', 'Jane');
cy.get('#author_1_affiliation').should('have.value', 'Example Org');
Expand All @@ -294,7 +294,7 @@ describe('Author order change', function() {
cy.get('#author_2_familyName').type('Doe');
cy.get('#author_3_givenName').type('Alex');

cy.get('#author_1_moveToRight').click()
cy.get('#author_1_moveToRight').click();

cy.get('#author_1_givenName').should('have.value', 'John');
cy.get('#author_1_familyName').should('have.value', 'Doe');
Expand Down Expand Up @@ -324,19 +324,19 @@ describe('Author order change', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"@type": "Person",
"type": "Person",
"givenName": "Jane",
"affiliation": {
"@type": "Organization",
"type": "Organization",
"name": "Example Org",
}
},
{
"@type": "Person",
"type": "Person",
"givenName": "John",
"familyName": "Doe",
},
Expand All @@ -348,19 +348,19 @@ describe('Author order change', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"author": [
{
"@type": "Person",
"type": "Person",
"givenName": "John",
"familyName": "Doe",
},
{
"@type": "Person",
"type": "Person",
"givenName": "Jane",
"affiliation": {
"@type": "Organization",
"type": "Organization",
"name": "Example Org",
}
},
Expand Down
10 changes: 5 additions & 5 deletions cypress/integration/special_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe('Funder id', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"funder": {
"@type": "Organization",
"@id": "http://example.org/",
"type": "Organization",
"id": "http://example.org/",
},
});
});
Expand Down Expand Up @@ -61,10 +61,10 @@ describe('Funder name', function() {
cy.get('#codemetaText').then((elem) => JSON.parse(elem.text()))
.should('deep.equal', {
"@context": "https://doi.org/10.5063/schema/codemeta-2.0",
"@type": "SoftwareSourceCode",
"type": "SoftwareSourceCode",
"name": "My Test Software",
"funder": {
"@type": "Organization",
"type": "Organization",
"name": "Example Org",
}
});
Expand Down
80 changes: 80 additions & 0 deletions data/contexts/codemeta-2.0.jsonld
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"@context": {
"type": "@type",
"id": "@id",
"schema":"http://schema.org/",
"codemeta": "https://codemeta.github.io/terms/",
"Organization": {"@id": "schema:Organization"},
"Person": {"@id": "schema:Person"},
"SoftwareSourceCode": {"@id": "schema:SoftwareSourceCode"},
"SoftwareApplication": {"@id": "schema:SoftwareApplication"},
"Text": {"@id": "schema:Text"},
"URL": {"@id": "schema:URL"},
"address": { "@id": "schema:address"},
"affiliation": { "@id": "schema:affiliation"},
"applicationCategory": { "@id": "schema:applicationCategory", "@type": "@id"},
"applicationSubCategory": { "@id": "schema:applicationSubCategory", "@type": "@id"},
"citation": { "@id": "schema:citation"},
"codeRepository": { "@id": "schema:codeRepository", "@type": "@id"},
"contributor": { "@id": "schema:contributor"},
"copyrightHolder": { "@id": "schema:copyrightHolder"},
"copyrightYear": { "@id": "schema:copyrightYear"},
"creator": { "@id": "schema:creator"},
"dateCreated": {"@id": "schema:dateCreated", "@type": "schema:Date" },
"dateModified": {"@id": "schema:dateModified", "@type": "schema:Date" },
"datePublished": {"@id": "schema:datePublished", "@type": "schema:Date" },
"description": { "@id": "schema:description"},
"downloadUrl": { "@id": "schema:downloadUrl", "@type": "@id"},
"email": { "@id": "schema:email"},
"editor": { "@id": "schema:editor"},
"encoding": { "@id": "schema:encoding"},
"familyName": { "@id": "schema:familyName"},
"fileFormat": { "@id": "schema:fileFormat", "@type": "@id"},
"fileSize": { "@id": "schema:fileSize"},
"funder": { "@id": "schema:funder"},
"givenName": { "@id": "schema:givenName"},
"hasPart": { "@id": "schema:hasPart" },
"identifier": { "@id": "schema:identifier", "@type": "@id"},
"installUrl": { "@id": "schema:installUrl", "@type": "@id"},
"isAccessibleForFree": { "@id": "schema:isAccessibleForFree"},
"isPartOf": { "@id": "schema:isPartOf"},
"keywords": { "@id": "schema:keywords"},
"license": { "@id": "schema:license", "@type": "@id"},
"memoryRequirements": { "@id": "schema:memoryRequirements", "@type": "@id"},
"name": { "@id": "schema:name"},
"operatingSystem": { "@id": "schema:operatingSystem"},
"permissions": { "@id": "schema:permissions"},
"position": { "@id": "schema:position"},
"processorRequirements": { "@id": "schema:processorRequirements"},
"producer": { "@id": "schema:producer"},
"programmingLanguage": { "@id": "schema:programmingLanguage"},
"provider": { "@id": "schema:provider"},
"publisher": { "@id": "schema:publisher"},
"relatedLink": { "@id": "schema:relatedLink", "@type": "@id"},
"releaseNotes": { "@id": "schema:releaseNotes", "@type": "@id"},
"runtimePlatform": { "@id": "schema:runtimePlatform"},
"sameAs": { "@id": "schema:sameAs", "@type": "@id"},
"softwareHelp": { "@id": "schema:softwareHelp"},
"softwareRequirements": { "@id": "schema:softwareRequirements", "@type": "@id"},
"softwareVersion": { "@id": "schema:softwareVersion"},
"sponsor": { "@id": "schema:sponsor"},
"storageRequirements": { "@id": "schema:storageRequirements", "@type": "@id"},
"supportingData": { "@id": "schema:supportingData"},
"targetProduct": { "@id": "schema:targetProduct"},
"url": { "@id": "schema:url", "@type": "@id"},
"version": { "@id": "schema:version"},

"author": { "@id": "schema:author", "@container": "@list" },

"softwareSuggestions": { "@id": "codemeta:softwareSuggestions", "@type": "@id"},
"contIntegration": { "@id": "codemeta:contIntegration", "@type": "@id"},
"buildInstructions": { "@id": "codemeta:buildInstructions", "@type": "@id"},
"developmentStatus": { "@id": "codemeta:developmentStatus", "@type": "@id"},
"embargoDate": { "@id":"codemeta:embargoDate", "@type": "schema:Date" },
"funding": { "@id": "codemeta:funding" },
"readme": { "@id":"codemeta:readme", "@type": "@id" },
"issueTracker": { "@id":"codemeta:issueTracker", "@type": "@id" },
"referencePublication": { "@id": "codemeta:referencePublication", "@type": "@id"},
"maintainer": { "@id": "codemeta:maintainer" }
}
}
2 changes: 2 additions & 0 deletions data/contexts/codemeta-2.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Matthew B. Jones, Carl Boettiger, Abby Cabunoc Mayes, Arfon Smith, Peter Slaughter, Kyle Niemeyer, Yolanda Gil, Martin Fenner, Krzysztof Nowak, Mark Hahnel, Luke Coy, Alice Allen, Mercè Crosas, Ashley Sands, Neil Chue Hong, Patricia Cruse, Daniel S. Katz, Carole Goble. 2017. CodeMeta: an exchange schema for software metadata. Version 2.0. KNB Data Repository. doi:10.5063/schema/codemeta-2.0
https://archive.softwareheritage.org/swh:1:cnt:ecba88bee7bac07a81a6f45414f4f57ce5eb2d29;origin=https://github.com/codemeta/codemeta;visit=swh:1:snp:a35573dd8a59795b7d81055234352efd8b08a603;anchor=swh:1:rev:dbc58ffa8b088ae1b09ad335852d9767c402983d;path=/codemeta.jsonld
20 changes: 14 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ <h1>CodeMeta generator</h1>

</form>
<form>
<input type="button" id="generateCodemeta" value="Generate codemeta.json"
<input type="button" id="generateCodemeta" value="Generate codemeta.json" disabled
title="Creates a codemeta.json file below, from the information provided above." />
<input type="button" id="resetForm" value="Reset form"
title="Erases all fields." />
<input type="button" id="validateCodemeta" value="Validate codemeta.json"
<input type="button" id="validateCodemeta" value="Validate codemeta.json" disabled
title="Checks the codemeta.json file below is valid, and displays errors." />
<input type="button" id="importCodemeta" value="Import codemeta.json"
<input type="button" id="importCodemeta" value="Import codemeta.json" disabled
title="Fills the fields above based on the codemeta.json file below." />
</form>

Expand Down Expand Up @@ -350,10 +350,18 @@ <h2 style="text-align:right;">Contributed by</h2>
</p>
</footer>

<script src="./js/libs/jsonld/jsonld.min.js"></script>
<script>
initFieldsData();
initCallbacks();
loadStateFromStorage();
Promise.all([loadSpdxData(), loadContextData()]).then(results => {
const [licenses, contexts] = results;
SPDX_LICENSES = licenses;
SPDX_LICENSE_IDS = licenses.map(license => license['licenseId']);

initJsonldLoader(contexts);
initFields();
initCallbacks();
loadStateFromStorage();
});
</script>
</body>
</html>
Loading

0 comments on commit f94dd52

Please sign in to comment.