Skip to content

Commit

Permalink
fix: unlocode md files generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kshychko committed Jun 2, 2024
1 parent a586d0d commit a67468d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion jsonld-utility/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.unece.uncefact</groupId>
<artifactId>vocab-jsonld-utility</artifactId>
<version>1.5.2</version>
<version>1.5.3</version>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void main(String[] args) throws ParseException, IOException {
Option prettyPrintOption = new Option("p", "pretty-print",false, "an output file to be created as a result of transformation. Default value: output.jsonld.");
Option workindDirOption = new Option("d", "directory",true, "Working directory for files to be merged or for md generation. Default value for merge - \"vocab/\", for md - \"\"");
Option inputFilesOption = new Option("i", "input-file",true, "Input file name to be merged or for md generation. Default value for md generation - \"merged.jsonld/\"");
Option outputFileNameOption = new Option("o", "input-file",true, "Input file name to be merged or for md generation. Default value for md generation - \"merged.jsonld/\"");
Option outputFileNameOption = new Option("o", "output-file",true, "Input file name to be merged or for md generation. Default value for md generation - \"merged.jsonld/\"");
Option versionOption = new Option("?", "version", false, "display this help.");

options.addOption(runningModeOption);
Expand Down Expand Up @@ -73,6 +73,8 @@ public static void main(String[] args) throws ParseException, IOException {
case "merge":
workingDir = "vocab/";
break;
case "md-locode":
workingDir = ".";
case "md":
case "minify":
case "pretty-print":
Expand Down Expand Up @@ -113,6 +115,12 @@ public static void main(String[] args) throws ParseException, IOException {
DomainsToMD.generate(workingDir, inputFileNames);
break;

case "md-locode":
UNLCDToMD.generate(workingDir);
UNLCDCountriesToMD.generate(workingDir);
UNLCDFunctionsToMD.generate(workingDir);
UNLCDSubdivisionsToMD.generate(workingDir);
break;
case "minify":
JsonLDMerge.format(workingDir, inputFileNames, false, outputFileName);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,11 @@ else if (comment instanceof JsonArray){
for (JsonObject jsonObject:codeProperties.get(codeListId).values()) {
JsonObjectBuilder mdCodeListValue = Json.createObjectBuilder();
mdCodeListValue.add("uri",jsonObject.getString(Constants.ID));
mdCodeListValue.add("comment",jsonObject.getString(Constants.RDFS_COMMENT));
if(jsonObject.containsKey(Constants.RDFS_COMMENT)){
mdCodeListValue.add("comment",jsonObject.getString(Constants.RDFS_COMMENT));
} else{
mdCodeListValue.add("comment","");
}
mdCodeListValue.add("value",jsonObject.getString(Constants.RDF_VALUE));
valuesMap.put(jsonObject.getString(Constants.RDF_VALUE), mdCodeListValue.build());

Expand All @@ -706,7 +710,11 @@ else if (comment instanceof JsonArray){
batchObject.add("id", dataSet.concat("_").concat(jsonObject.getString(Constants.ID)));
batchFieldsObject = Json.createObjectBuilder();
batchFieldsObject.add("label", StringUtils.substringAfter(jsonObject.getString(Constants.ID), ":"));
batchFieldsObject.add("comment", jsonObject.getString(Constants.RDFS_COMMENT));
if(jsonObject.containsKey(Constants.RDFS_COMMENT)){
batchFieldsObject.add("comment", jsonObject.getString(Constants.RDFS_COMMENT));
} else{
batchFieldsObject.add("comment", "");
}
batchFieldsObject.add("type", "Code List Value");
batchFieldsObject.add("dataset", dataSet);
batchObject.add("fields", batchFieldsObject.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void generate(String workingDir) throws IOException {
mdContent = mdContent.concat(String.format("permalink: %s", "unlocode-countries")).concat("\n");
mdContent = mdContent.concat(String.format("jsonid: %s", "unlocode-countries")).concat("\n");
mdContent = mdContent.concat(String.format("label: %s", "UN/LOCODE Countries")).concat("\n");
mdContent = mdContent.concat(String.format("comment: %s", "desc")).concat("\n");
// mdContent = mdContent.concat(String.format("comment: %s", "desc")).concat("\n");
mdContent = mdContent.concat("columns:\n");
mdContent = mdContent.concat(" - \n");
mdContent = mdContent.concat(" title: Label\n");
Expand All @@ -62,7 +62,7 @@ public static void generate(String workingDir) throws IOException {
mdContent = mdContent.concat(" title: UN/LOCODEs\n");
mdContent = mdContent.concat(String.format(" type: %s\n", "unlocode-link"));
mdContent = mdContent.concat("---\n");
new FileGenerator().generateTextFile(mdContent,workingDir+"/_code-lists/unlocode-countries.md");
new FileGenerator().generateTextFile(mdContent,workingDir+"/_unlocode-lists/unlocode-countries.md");
fis.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void generate(String workingDir) throws IOException {
JsonObject jsonObject = iterator.next().asJsonObject();
csvContent = csvContent.concat(String.format("\"%s\",", jsonObject.getString(Constants.ID)));
csvContent = csvContent.concat(String.format("\"%s\",", jsonObject.getString(Constants.RDFS_LABEL)));
csvContent = csvContent.concat(String.format("\"%s\",", jsonObject.getString(Constants.RDFS_COMMENT)));
csvContent = csvContent.concat(String.format("\"%s\",", jsonObject.getString(Constants.RDFS_COMMENT).replaceAll("\"", "'")));
csvContent = csvContent.concat(String.format("\"%s\"\n", jsonObject.getString(Constants.RDF_VALUE)));
}
new FileGenerator().generateTextFile(csvContent,workingDir+"/_data/unlocode-functions.csv");
Expand All @@ -52,7 +52,7 @@ public static void generate(String workingDir) throws IOException {
mdContent = mdContent.concat(String.format("permalink: %s", "unlocode-functions")).concat("\n");
mdContent = mdContent.concat(String.format("jsonid: %s", "unlocode-functions")).concat("\n");
mdContent = mdContent.concat(String.format("label: %s", "UN/LOCODE Functions")).concat("\n");
mdContent = mdContent.concat(String.format("comment: %s", "desc")).concat("\n");
// mdContent = mdContent.concat(String.format("comment: %s", "desc")).concat("\n");
mdContent = mdContent.concat("columns:\n");
mdContent = mdContent.concat(" - \n");
mdContent = mdContent.concat(" title: Label\n");
Expand All @@ -64,7 +64,7 @@ public static void generate(String workingDir) throws IOException {
mdContent = mdContent.concat(" title: Value\n");
mdContent = mdContent.concat(String.format(" code: %s\n", "value"));
mdContent = mdContent.concat("---\n");
new FileGenerator().generateTextFile(mdContent,workingDir+"/_code-lists/unlocode-functions.md");
new FileGenerator().generateTextFile(mdContent,workingDir+"/_unlocode-lists/unlocode-functions.md");
fis.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static void generate(String workingDir) throws IOException {
mdContent = mdContent.concat(String.format("permalink: %s", "unlocode-subdivisions")).concat("\n");
mdContent = mdContent.concat(String.format("jsonid: %s", "unlocode-subdivisions")).concat("\n");
mdContent = mdContent.concat(String.format("label: %s", "UN/LOCODE Country Subdivisions")).concat("\n");
mdContent = mdContent.concat(String.format("comment: %s", "desc")).concat("\n");
// mdContent = mdContent.concat(String.format("comment: %s", "desc")).concat("\n");
mdContent = mdContent.concat("columns:\n");
mdContent = mdContent.concat(" - \n");
mdContent = mdContent.concat(" title: Label\n");
Expand All @@ -71,7 +71,7 @@ public static void generate(String workingDir) throws IOException {
mdContent = mdContent.concat(" title: Value\n");
mdContent = mdContent.concat(String.format(" code: %s\n", "value"));
mdContent = mdContent.concat("---\n");
new FileGenerator().generateTextFile(mdContent,workingDir+"/_code-lists/unlocode-subdivisions.md");
new FileGenerator().generateTextFile(mdContent,workingDir+"/_unlocode-lists/unlocode-subdivisions.md");
fis.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static void generate(String workingDir) throws IOException {
mdContent += String.format("permalink: %s%s\n", "unlocode", countryCode);
mdContent += String.format("jsonid: %s%s\n", "unlocode", countryCode);
mdContent += String.format("label: %s\n", "UN/LOCODE");
mdContent += String.format("comment: %s\n", "desc");
// mdContent += String.format("comment: %s\n", "desc");
mdContent += "excludeFromList: true\n";
mdContent += "columns:\n";
mdContent += " - \n";
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void generate(String workingDir) throws IOException {
mdContent += " title: Longitude\n";
mdContent += String.format(" code: %s\n", UNLOCODEConstants.GEO_NS+":long");
mdContent += "---\n";
new FileGenerator().generateTextFile(mdContent, String.format(workingDir+"/_code-lists/unlocode%s.md", countryCode));
new FileGenerator().generateTextFile(mdContent, String.format(workingDir+"/_unlocode-lists/unlocode%s.md", countryCode));
}
countryCode = currentCountryCode;
csvContent += String.format("\"%s\",", jsonObject.getString(Constants.ID));
Expand Down Expand Up @@ -174,7 +174,7 @@ public static void generate(String workingDir) throws IOException {
mdContent += String.format("permalink: %s%s\n", "unlocode", countryCode);
mdContent += String.format("jsonid: %s%s\n", "unlocode", countryCode);
mdContent += String.format("label: %s\n", "UN/LOCODE");
mdContent += String.format("comment: %s\n", "desc");
// mdContent += String.format("comment: %s\n", "desc");
mdContent += "excludeFromList: true\n";
mdContent += "columns:\n";
mdContent += " - \n";
Expand Down Expand Up @@ -202,7 +202,7 @@ public static void generate(String workingDir) throws IOException {
mdContent += " title: Longitude\n";
mdContent += String.format(" code: %s\n", UNLOCODEConstants.GEO_NS+":long");
mdContent += "---\n";
new FileGenerator().generateTextFile(mdContent, String.format(workingDir+"/_code-lists/unlocode%s.md", countryCode));
new FileGenerator().generateTextFile(mdContent, String.format(workingDir+"/_unlocode-lists/unlocode%s.md", countryCode));
fis.close();
}
}

0 comments on commit a67468d

Please sign in to comment.