Skip to content

Commit

Permalink
Merge pull request #65 from edmcouncil/github_60
Browse files Browse the repository at this point in the history
Add fix to to allow private language tags
  • Loading branch information
mereolog authored Feb 22, 2024
2 parents 586d02d + 0049365 commit 2603921
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("-");
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 2603921

Please sign in to comment.