From e572ebb13f8faecb1f51bbf34befbe006a631e92 Mon Sep 17 00:00:00 2001
From: Christopher Weedall <5010253+cweedall@users.noreply.github.com>
Date: Thu, 9 May 2024 12:52:34 -0500
Subject: [PATCH] Proper pluralization for paths (#179)
* add jibx-tools for pluralization
* pluralize words correctly, not just adding "s"; TODO notes about it
* bump version and update dependencies versions
---
pom.xml | 23 +++++++++++++++--------
src/main/java/edu/isi/oba/Mapper.java | 13 ++++++++++---
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/pom.xml b/pom.xml
index d050342..ac30d59 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
jar
edu.isi.oba
oba
- 3.9.0
+ 3.9.1
core
https://github.com/KnowledgeCaptureAndDiscovery/OBA
@@ -16,7 +16,7 @@
11
11
- 3.5.2
+ 3.5.3
@@ -39,7 +39,7 @@
io.swagger
swagger-compat-spec-parser
- 1.0.70
+ 1.0.71
@@ -51,20 +51,20 @@
io.swagger.parser.v3
swagger-parser
- 2.1.21
+ 2.1.22
io.swagger.parser.v3
swagger-parser-core
- 2.1.21
+ 2.1.22
org.openapitools
openapi-generator
- 7.4.0
+ 7.5.0
@@ -97,7 +97,7 @@
commons-cli
commons-cli
- 1.6.0
+ 1.7.0
@@ -105,7 +105,14 @@
com.fasterxml.jackson.core
jackson-core
- 2.17.0
+ 2.17.1
+
+
+
+
+ org.jibx
+ jibx-tools
+ 1.4.2
diff --git a/src/main/java/edu/isi/oba/Mapper.java b/src/main/java/edu/isi/oba/Mapper.java
index a80f515..e7bb3c0 100644
--- a/src/main/java/edu/isi/oba/Mapper.java
+++ b/src/main/java/edu/isi/oba/Mapper.java
@@ -17,6 +17,8 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;
+import org.jibx.schema.codegen.extend.DefaultNameConverter;
+import org.jibx.schema.codegen.extend.NameConverter;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.FileDocumentSource;
import org.semanticweb.owlapi.model.*;
@@ -249,13 +251,18 @@ private void setSchemaDrescriptions(Set classes, OWLOntology ontology)
}
private void add_path(PathGenerator pathGenerator, MapperSchema mapperSchema) {
- String singular_name = "/" + mapperSchema.name.toLowerCase() + "s/{id}";
- String plural_name = "/" + mapperSchema.name.toLowerCase() + "s";
+ // Pluralizing currently only works for English. Non-English words will be treated as though they are English.
+ // TODO: Java support for singularization/pluralization and locale/international support supoort for the process does not have many good options that we could find so far.
+ // TODO: If such an option exists or becomes available, this should be updated to support pluralization in other languages.
+ // TODO: The language/locale would need to be set as a configuration value and passed into this class somehow.
+ NameConverter nameTools = new DefaultNameConverter();
+ String plural_name = "/" + nameTools.pluralize(mapperSchema.name.toLowerCase());
+
//Create the plural paths: for example: /models/
this.paths.addPathItem(plural_name, pathGenerator.generate_plural(mapperSchema.name,
mapperSchema.getCls().getIRI().getIRIString()));
//Create the plural paths: for example: /models/id
- this.paths.addPathItem(singular_name, pathGenerator.generate_singular(mapperSchema.name,
+ this.paths.addPathItem(plural_name + "/{id}", pathGenerator.generate_singular(mapperSchema.name,
mapperSchema.getCls().getIRI().getIRIString()));
}