Repository: Language-Research-Technology/ro-crate-excel
Pull request #30: addRdfsProps populates rdfs:label and rdfs:comment from name and description fields
Author: login: rosanna-smith
Created: 2025-05-06T05:51:55Z | Merged: 2025-05-07T02:40:47Z

Related to https://github.com/Language-Research-Technology/ro-crate-excel/issues/29

- addRdfsProps() added to workbook.js
- related test added to workbook.spec.js


Diff:
diff --git a/README.md b/README.md
index 23a5f6a..c3c30c6 100644
--- a/README.md
+++ b/README.md
@@ -411,6 +411,23 @@ Which on conversion to Excel would look like:
 
 TODO: Make @context entries for additional `Property` items automatically show up in the `@context` if not already defined - and force appropriate IDs (they must be either full http(s) URIs or blank node `@id`s and start with a lowercase letter).
 
+<br>
+
+### Adding Custom Terms to the Spreadsheet
+
+If using a spreadsheet to convert to JSON-LD, custom terms can be defined on a tab in the following format:
+
+| @id             | @type          | name               | description                          | isRef_inDefinedTermSet | sameAs | rdfs:subClassOf |
+| --------------- | -------------- | ------------------ | ------------------------------------ | ---------------------- | ------ | --------------- |
+| #myProp         | rdf:Property   | My Property        | Description of the property.         |                        |
+| #MyDefinedTerm1 | DefinedTerm    | My Defined Term #1 | Description of the defined term.     | #MyPropTerms           |
+| #MyDefinedTerm2 | DefinedTerm    | My Defined Term #2 | Description of the defined term.     | #MyPropTerms           |
+| #MyPropTerms    | DefinedTermSet | My Property Terms  | Description of the defined term set. |
+
+For `rdf:Property` and `rdfs:Class`, the `rdfs:label` and `rdfs:comment` will be autopopulated by rocxl from the `name` and `description` fields respectively.
+
+<br>
+
 # Implementing Workbook to RO-Crate
 
 When converting from a worksheet to a JSON-LD item, the process is to:
diff --git a/lib/workbook.js b/lib/workbook.js
index 89d3e2d..06c9c48 100644
--- a/lib/workbook.js
+++ b/lib/workbook.js
@@ -488,6 +488,7 @@ class Workbook {
 
         this.resolveLinks();
         this.addBackLinks();
+        this.addRdfsProps();
     }
 
     resolveLinks() {
@@ -564,6 +565,20 @@ class Workbook {
         }
     }
 
+    addRdfsProps() {
+        // Add @reverse properties if not there
+        for (let item of this.crate.graph) {
+            if (item['@type'].includes('rdf:Property') || (item['@type'].includes('rdfs:Class'))) {
+                if (!item['rdfs:label']) {
+                    item['rdfs:label'] = item.name[0]
+                }
+                if (!item['rdfs:comment']) {
+                    item['rdfs:comment'] = item.description[0]
+                }
+            }
+        }
+    }
+
     validProp(prop) {
         prop = prop.replace(/^is(.*?)_/, "");
         if (prop && !prop.startsWith("@") && !this.crate.resolveTerm(prop)) {
diff --git a/package-lock.json b/package-lock.json
index 887701c..1ca13e1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -31,7 +31,7 @@
       },
       "devDependencies": {
         "chai": "4.5.0",
-        "mocha": "^10.2.0"
+        "mocha": "^10.8.2"
       },
       "engines": {
         "node": ">=18.0.0",
@@ -1611,10 +1611,11 @@
       }
     },
     "node_modules/mocha": {
-      "version": "10.7.0",
-      "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.7.0.tgz",
-      "integrity": "sha512-v8/rBWr2VO5YkspYINnvu81inSz2y3ODJrhO175/Exzor1RcEZZkizgE2A+w/CAXXoESS8Kys5E62dOHGHzULA==",
+      "version": "10.8.2",
+      "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.8.2.tgz",
+      "integrity": "sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "ansi-colors": "^4.1.3",
         "browser-stdout": "^1.3.1",
diff --git a/package.json b/package.json
index 65874d5..dfe1774 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,7 @@
   },
   "devDependencies": {
     "chai": "4.5.0",
-    "mocha": "^10.2.0"
+    "mocha": "^10.8.2"
   },
   "files": [
     "index.js",
diff --git a/test/workbook.spec.js b/test/workbook.spec.js
index 51bb64b..4aed0c4 100644
--- a/test/workbook.spec.js
+++ b/test/workbook.spec.js
@@ -186,6 +186,20 @@ describe("Create a workbook from a crate", function () {
         console.log(workbook2.crate.toJSON()["@context"])
     });
 
+    it("Correctly adds the rdfs:label and rdfs:comment from name and description from rdf:Property and rdfs:Class for custom terms", async function () {
+        this.timeout(5000);
+        const excelFilePath = "test_data/custom_terms.xlsx";
+        // New empty crate
+        var c = new ROCrate({array: true, link: true});
+
+        const workbook2 = new Workbook({crate: c});
+        await workbook2.loadExcel(excelFilePath, true); // true here means add to crate
+        const testProperty = c.getEntity('#testProperty')
+        assert(testProperty.name[0] === 'Test Property')
+        console.log(testProperty)
+        assert(testProperty.name[0] === testProperty['rdfs:label'][0])
+    });
+
     it("Can resolve double quoted references", async function () {
         var c = new ROCrate({array: true, list: true});
 
diff --git a/test_data/custom_terms.xlsx b/test_data/custom_terms.xlsx
new file mode 100644
index 0000000..02d1bad
Binary files /dev/null and b/test_data/custom_terms.xlsx differ


Reviews:
user: login: ptsefton
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-07T02:14:10Z
user: login: ptsefton
state: COMMENTED
author_association: NONE
submitted_at: 2025-05-07T02:14:49Z
user: login: rosanna-smith
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-07T02:20:42Z
user: login: rosanna-smith
state: COMMENTED
author_association: COLLABORATOR
submitted_at: 2025-05-07T02:20:50Z

Review comments:
diff_hunk: @@ -411,6 +411,23 @@ Which on conversion to Excel would look like:
 
 TODO: Make @context entries for additional `Property` items automatically show up in the `@context` if not already defined - and force appropriate IDs (they must be either full http(s) URIs or blank node `@id`s and start with a lowercase letter).
 
+<br>
+
+### Adding Custom Terms to the Spreadsheet
+
+If using a spreadsheet to convert to JSON-LD, custom terms can be defined on a tab in the following format:
+
+| @id             | @type          | name               | description                          | inDefinedTermSet | sameAs | rdfs:subClassOf |
path: README.md
user: login: ptsefton
body: Should be isRef_inDefinedTermSet

created_at: 2025-05-07T02:14:10Z
author_association: NONE
diff_hunk: @@ -411,6 +411,23 @@ Which on conversion to Excel would look like:
 
 TODO: Make @context entries for additional `Property` items automatically show up in the `@context` if not already defined - and force appropriate IDs (they must be either full http(s) URIs or blank node `@id`s and start with a lowercase letter).
 
+<br>
+
+### Adding Custom Terms to the Spreadsheet
+
+If using a spreadsheet to convert to JSON-LD, custom terms can be defined on a tab in the following format:
+
+| @id             | @type          | name               | description                          | inDefinedTermSet | sameAs | rdfs:subClassOf |
+| --------------- | -------------- | ------------------ | ------------------------------------ | ---------------- | ------ | --------------- |
+| #myProp         | rdf:Property   | My Property        | Description of the property.         |                  |
+| #MyDefinedTerm1 | DefinedTerm    | My Defined Term #1 | Description of the defined term.     | #MyPropTerms     |
+| #MyDefinedTerm2 | DefinedTerm    | My Defined Term #2 | Description of the defined term.     | #MyPropTerms     |
+| #MyPropTerms    | DefinedTermSet | My Property Terms  | Description of the defined term set. |
+
+The `rdfs:label` and `rdfs:comment` will be autopopulated by rocxl from the `name` and `description` fields respectively.
path: README.md
user: login: ptsefton
body: ... for rdf:Property and rdfs:Class 
created_at: 2025-05-07T02:14:49Z
author_association: NONE
diff_hunk: @@ -411,6 +411,23 @@ Which on conversion to Excel would look like:
 
 TODO: Make @context entries for additional `Property` items automatically show up in the `@context` if not already defined - and force appropriate IDs (they must be either full http(s) URIs or blank node `@id`s and start with a lowercase letter).
 
+<br>
+
+### Adding Custom Terms to the Spreadsheet
+
+If using a spreadsheet to convert to JSON-LD, custom terms can be defined on a tab in the following format:
+
+| @id             | @type          | name               | description                          | inDefinedTermSet | sameAs | rdfs:subClassOf |
path: README.md
user: login: rosanna-smith
body: Updated
created_at: 2025-05-07T02:20:42Z
author_association: COLLABORATOR
diff_hunk: @@ -411,6 +411,23 @@ Which on conversion to Excel would look like:
 
 TODO: Make @context entries for additional `Property` items automatically show up in the `@context` if not already defined - and force appropriate IDs (they must be either full http(s) URIs or blank node `@id`s and start with a lowercase letter).
 
+<br>
+
+### Adding Custom Terms to the Spreadsheet
+
+If using a spreadsheet to convert to JSON-LD, custom terms can be defined on a tab in the following format:
+
+| @id             | @type          | name               | description                          | inDefinedTermSet | sameAs | rdfs:subClassOf |
+| --------------- | -------------- | ------------------ | ------------------------------------ | ---------------- | ------ | --------------- |
+| #myProp         | rdf:Property   | My Property        | Description of the property.         |                  |
+| #MyDefinedTerm1 | DefinedTerm    | My Defined Term #1 | Description of the defined term.     | #MyPropTerms     |
+| #MyDefinedTerm2 | DefinedTerm    | My Defined Term #2 | Description of the defined term.     | #MyPropTerms     |
+| #MyPropTerms    | DefinedTermSet | My Property Terms  | Description of the defined term set. |
+
+The `rdfs:label` and `rdfs:comment` will be autopopulated by rocxl from the `name` and `description` fields respectively.
path: README.md
user: login: rosanna-smith
body: Added to start of sentence
created_at: 2025-05-07T02:20:50Z
author_association: COLLABORATOR

PR comments:
user: login: ptsefton
created_at: 2025-05-06T22:02:02Z
body: Can you add to the README as well. I know there is extensively documented elsewhere but this should documented in here, adding to the basic usage info.
author_association: NONE
user: login: rosanna-smith
created_at: 2025-05-07T01:46:59Z
body: @ptsefton Added to readme around custom terms, see if that was what you were after there.
author_association: COLLABORATOR