From cf992cf99d5fc282b04e6ed2efea40fd0d5fe672 Mon Sep 17 00:00:00 2001 From: Pasquale Lisena Date: Mon, 3 Sep 2018 17:47:58 +0200 Subject: [PATCH] fix --- build.gradle | 2 +- .../doremus/string2vocabulary/SKOSVocabulary.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 6763783..c2c2c4b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'org.doremus' -version '0.3' +version '0.4' apply plugin: 'java' apply plugin: 'application' diff --git a/src/main/java/org/doremus/string2vocabulary/SKOSVocabulary.java b/src/main/java/org/doremus/string2vocabulary/SKOSVocabulary.java index 0ad7aeb..bd6e567 100644 --- a/src/main/java/org/doremus/string2vocabulary/SKOSVocabulary.java +++ b/src/main/java/org/doremus/string2vocabulary/SKOSVocabulary.java @@ -1,8 +1,8 @@ package org.doremus.string2vocabulary; +import org.apache.jena.rdf.model.*; import org.apache.jena.vocabulary.RDF; import org.apache.jena.vocabulary.SKOS; -import org.apache.jena.rdf.model.*; import java.util.ArrayList; import java.util.HashMap; @@ -22,7 +22,7 @@ public SKOSVocabulary(String name, Model model) { // for each concept StmtIterator conceptIter = - vocabulary.listStatements(new SimpleSelector(null, RDF.type, SKOS.Concept)); + vocabulary.listStatements(new SimpleSelector(null, RDF.type, SKOS.Concept)); if (!conceptIter.hasNext()) { System.out.println("SKOSVocabulary constructor | Warning: No concepts in the reference rdf at " + name); @@ -35,7 +35,11 @@ public SKOSVocabulary(String name, Model model) { StmtIterator labelIterator = resource.listProperties(SKOS.prefLabel); //for each label while (labelIterator.hasNext()) { - String value = norm(labelIterator.nextStatement().getObject().toString()); + Literal nx = labelIterator.nextStatement().getLiteral(); + String value = norm(nx.getLexicalForm()); + String lang = nx.getLanguage(); + if (lang != null && !lang.isEmpty()) value += "@" + nx.getLanguage(); + // get the list or create a new one List ls = substitutionMap.computeIfAbsent(value, k -> new ArrayList<>()); // add it to the list @@ -45,7 +49,10 @@ public SKOSVocabulary(String name, Model model) { labelIterator = resource.listProperties(SKOS.altLabel); //for each label while (labelIterator.hasNext()) { - String value = norm(labelIterator.nextStatement().getObject().toString()); + Literal nx = labelIterator.nextStatement().getLiteral(); + String value = norm(nx.getLexicalForm()); + String lang = nx.getLanguage(); + if (lang != null && !lang.isEmpty()) value += "@" + nx.getLanguage(); // get the list or create a new one List ls = substitutionMap.computeIfAbsent(value, k -> new ArrayList<>());