use of skos.SKOSLabel in project opentheso by miledrousset.
the class WriteSkosBDD method getTraductionConcept.
/*
public String getId(SKOSResource resource) {
String id = "";
if(resource.getSdc() != null){
if(resource.getSdc().getIdentifier()!= null) {
if(!resource.getSdc().getIdentifier().isEmpty()){
id = resource.getSdc().getIdentifier();
}
}
}
if(id.isEmpty()) {
if (resource.getUri().contains("#")) {
id = resource.getUri().substring(resource.getUri().indexOf("#") + 1, resource.getUri().length());
}
else
{
id = resource.getUri().substring(resource.getUri().lastIndexOf("/") + 1, resource.getUri().length());
}
}
return id;
}*/
/* Pour un concept */
public ArrayList<NodeTermTraduction> getTraductionConcept(ArrayList<SKOSLabel> labelsList) {
ArrayList<NodeTermTraduction> nodeTermTraductionList = new ArrayList<>();
for (int i = 0; i < labelsList.size(); i++) {
SKOSLabel label = labelsList.get(i);
switch(label.getProperty()) {
case SKOSProperty.prefLabel:
NodeTermTraduction nodeTermTraduction = new NodeTermTraduction();
nodeTermTraduction.setLexicalValue(label.getLabel());
nodeTermTraduction.setLang(label.getLanguage());
nodeTermTraductionList.add(nodeTermTraduction);
break;
default:
break;
}
}
return nodeTermTraductionList;
}
use of skos.SKOSLabel in project opentheso by miledrousset.
the class WriteSkosBDD method writeThesaurus.
public void writeThesaurus(SKOSXmlDocument skosDocument, String dateFormat, boolean useArk, String adressSite, int idUser, String langueSource) {
SKOSConceptScheme conceptScheme = skosDocument.getConceptScheme();
ArrayList<SKOSTopConcept> topConceptsList = conceptScheme.getTopConceptsList();
ArrayList<SKOSResource> resourcesList = skosDocument.getResourcesList();
/*
* Création du Thésaurus
*/
String descriptionThesaurus = getThesaurusName(conceptScheme.getUri());
// if(!query.thesaurusExistLangue(descriptionThesaurus, id_langueSource)) {
ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
Thesaurus thesaurus = new Thesaurus();
thesaurus.setTitle(descriptionThesaurus);
thesaurus.setLanguage(langueSource);
String idThesaurus = thesaurusHelper.addThesaurus(ds, thesaurus, adressSite, useArk);
if (idThesaurus == null)
return;
thesaurus.setId_thesaurus(idThesaurus);
try {
Connection conn = ds.getConnection();
conn.setAutoCommit(false);
UserHelper userHelper = new UserHelper();
int idRole = userHelper.getRoleOfUser(ds, idUser);
if (!userHelper.addRole(conn, idUser, idRole, idThesaurus, "")) {
conn.rollback();
conn.close();
return;
}
conn.commit();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
}
// Si le Titre du thésaurus n'est pas detecter, on donne un nom par defaut
if (conceptScheme.getSkosLabels().isEmpty()) {
if (thesaurus.getTitle().isEmpty()) {
thesaurus.setTitle("Theso_" + idThesaurus);
thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
}
}
for (SKOSLabel skosLabel : conceptScheme.getSkosLabels()) {
thesaurus.setTitle(skosLabel.getLabel());
thesaurus.setLanguage(skosLabel.getLanguage());
thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
}
idsTopConcept = new ArrayList<>();
for (SKOSResource resource : resourcesList) {
if (resource != null) {
if (!isDescriptor(resource, topConceptsList)) {
// on insère un domaine
writeDomaine(resource, idThesaurus, "fr", adressSite, useArk, idUser);
} else {
// on insère un concept
writeConcept(resource, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
}
}
}
// ici la fin du fichier on controle si le thésaurus a toutes les langues des concepts
// Vérifier l'existence de la langue et l'ajouter si elle n'existe pas déjà
addLangsToThesaurus(ds, idThesaurus);
}
use of skos.SKOSLabel in project opentheso by miledrousset.
the class SkosToJsonld method addLabels.
private void addLabels(ArrayList<SKOSLabel> sKOSLabels) {
ArrayList<SKOSLabel> prefLabel = new ArrayList<>();
ArrayList<SKOSLabel> altLabel = new ArrayList<>();
StringPlus stringPlus = new StringPlus();
for (SKOSLabel sKOSLabel : sKOSLabels) {
switch(sKOSLabel.getProperty()) {
case SKOSProperty.prefLabel:
prefLabel.add(sKOSLabel);
break;
case SKOSProperty.altLabel:
altLabel.add(sKOSLabel);
break;
default:
break;
}
}
// prefLabls
String prefLabelString;
if (!prefLabel.isEmpty()) {
if (prefLabel.size() > 1) {
endElement();
prefLabelString = " \"" + nameSpaceSkosCore + "prefLabel" + "\": [\n";
boolean first = true;
for (SKOSLabel prefLabel1 : prefLabel) {
if (!first)
prefLabelString += ",\n";
prefLabelString += " {\n";
prefLabelString += " \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
prefLabelString += " \"@value\": \"" + stringPlus.normalizeStringForXml(prefLabel1.getLabel()) + "\"\n";
prefLabelString += " }";
first = false;
}
prefLabelString += "\n ]";
} else {
endElement();
prefLabelString = " \"" + nameSpaceSkosCore + "prefLabel" + "\": {\n";
for (SKOSLabel prefLabel1 : prefLabel) {
prefLabelString += " \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
prefLabelString += " \"@value\": \"" + stringPlus.normalizeStringForXml(prefLabel1.getLabel()) + "\"\n";
prefLabelString += " }";
}
}
jsonLd.append(prefLabelString);
}
// altLables
String altLabelString;
if (!altLabel.isEmpty()) {
if (altLabel.size() > 1) {
endElement();
altLabelString = " \"" + nameSpaceSkosCore + "altLabel" + "\": [\n";
boolean first = true;
for (SKOSLabel altLabel1 : altLabel) {
if (!first)
altLabelString += ",\n";
altLabelString += " {\n";
altLabelString += " \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
altLabelString += " \"@value\": \"" + stringPlus.normalizeStringForXml(altLabel1.getLabel()) + "\"\n";
altLabelString += " }";
first = false;
}
altLabelString += "\n ]";
} else {
endElement();
altLabelString = " \"" + nameSpaceSkosCore + "altLabel" + "\": {\n";
for (SKOSLabel altLabel1 : altLabel) {
altLabelString += " \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
altLabelString += " \"@value\": \"" + stringPlus.normalizeStringForXml(altLabel1.getLabel()) + "\"\n";
altLabelString += " }";
}
}
jsonLd.append(altLabelString);
}
}
Aggregations