Skip to content

Commit

Permalink
fix second part of lang renaming to uppercase
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kowalski committed Feb 22, 2024
1 parent c4f234d commit 0049365
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,7 @@ private void runOnFile(RdfToolkitOptions rdfToolkitOptions) throws Exception {
IRI replacedPredicate = st.getPredicate();
//Replaced language serialization
if (modelObject instanceof Literal) {
Optional<String> lang = ((Literal) modelObject).getLanguage();
if (lang.isPresent() && lang.get().contains("-")) {
String langString = lang.get();
String[] langTab = langString.split("-");
if (!"x".equals(langTab[1])) {langTab[1] = langTab[1].toUpperCase();}
langString = String.join("-", langTab);
String label = ((Literal) modelObject).getLabel();
modelObject = valueFactory.createLiteral(label, langString);
}
modelObject = secondPartOfLangToUpperCaseIfNotX(modelObject);
}
// Do any URI replacements
if (isIriPatternAndIriReplacementNotNull) {
Expand Down Expand Up @@ -220,6 +212,20 @@ private void runOnFile(RdfToolkitOptions rdfToolkitOptions) throws Exception {
targetWriter.close();
}

private Value secondPartOfLangToUpperCaseIfNotX(Value modelObject) {
Optional<String> lang = ((Literal) modelObject).getLanguage();
if (lang.isPresent() && lang.get().contains("-")) {
String langString = lang.get();
String[] langTab = langString.split("-");
// Convert the second part of the language string to uppercase, except if the entire second part is 'x'
if (!langTab[1].equals("x")) { langTab[1] = langTab[1].toUpperCase(); }
langString = String.join("-", langTab);
String label = ((Literal) modelObject).getLabel();
modelObject = valueFactory.createLiteral(label, langString);
}
return modelObject;
}

private Model readModel(RdfToolkitOptions rdfToolkitOptions) {
Model sourceModel = null;
try {
Expand Down

0 comments on commit 0049365

Please sign in to comment.