Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fix to to allow private language tags #65

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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