use of skos.SKOSLabel in project opentheso by miledrousset.
the class WriteBranchSkosBDD method writeLabelsList.
public ArrayList<NodeEM> writeLabelsList(HikariDataSource ds, ArrayList<SKOSLabel> labelsList) {
ArrayList<NodeEM> nodeEMList = new ArrayList<>();
for (int i = 0; i < labelsList.size(); i++) {
SKOSLabel label = labelsList.get(i);
switch(label.getProperty()) {
case SKOSProperty.altLabel:
NodeEM nodeEM = new NodeEM();
nodeEM.setLexical_value(label.getLabel());
nodeEM.setLang(label.getLanguage());
nodeEM.setSource("");
nodeEM.setStatus("USE");
nodeEM.setHiden(false);
nodeEMList.add(nodeEM);
break;
default:
break;
}
}
return nodeEMList;
}
use of skos.SKOSLabel in project opentheso by miledrousset.
the class AlignmentQuery method queryOpentheso.
/**
* Cette fonction permet de récupérer les alignements présents sur Opentheso
* pour un concept passé en paramètre et un thésaurus donné
*
* @param idC
* @param idTheso
* @param lexicalValue
* @param lang
* @param requete
* @param source
* @return
*/
public ArrayList<NodeAlignment> queryOpentheso(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
if (requete.trim().equals("")) {
return null;
}
if (lexicalValue.trim().equals("")) {
return null;
}
listeAlign = new ArrayList<>();
// construction de la requête de type (webservices Opentheso)
lexicalValue = lexicalValue.replaceAll(" ", "%20");
requete = requete.replace("##lang##", lang);
requete = requete.replace("##value##", lexicalValue);
try {
URL url = new URL(requete);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
String xmlRecord = "";
while ((output = br.readLine()) != null) {
xmlRecord += output;
}
byte[] bytes = xmlRecord.getBytes();
xmlRecord = new String(bytes, Charset.forName("UTF-8"));
conn.disconnect();
StringBuffer sb = new StringBuffer(xmlRecord);
try {
SKOSXmlDocument sxd = new ReadFileSKOS().readStringBuffer(sb);
for (SKOSResource resource : sxd.getResourcesList()) {
NodeAlignment na = new NodeAlignment();
na.setInternal_id_concept(idC);
na.setInternal_id_thesaurus(idTheso);
// "Pactols");
na.setThesaurus_target(source);
na.setUri_target(resource.getUri());
for (SKOSLabel label : resource.getLabelsList()) {
switch(label.getProperty()) {
case SKOSProperty.prefLabel:
if (label.getLanguage().equals(lang)) {
na.setConcept_target(label.getLabel());
}
break;
case SKOSProperty.altLabel:
if (label.getLanguage().equals(lang)) {
if (na.getConcept_target_alt().isEmpty()) {
na.setConcept_target_alt(label.getLabel());
} else {
na.setConcept_target_alt(na.getConcept_target_alt() + ";" + label.getLabel());
}
}
break;
default:
break;
}
}
for (SKOSDocumentation sd : resource.getDocumentationsList()) {
if (sd.getProperty() == SKOSProperty.definition && sd.getLanguage().equals(lang)) {
na.setDef_target(sd.getText());
}
}
listeAlign.add(na);
}
} catch (Exception ex) {
Logger.getLogger(AlignmentQuery.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return listeAlign;
}
use of skos.SKOSLabel in project opentheso by miledrousset.
the class SkosToJsonldSchemaOrg method addLabels.
private void addLabels(ArrayList<SKOSLabel> sKOSLabels) {
ArrayList<SKOSLabel> prefLabel = new ArrayList<>();
ArrayList<SKOSLabel> altLabel = new ArrayList<>();
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()) {
endElement();
prefLabelString = " \"name" + "\": [\n";
boolean first = true;
for (SKOSLabel prefLabel1 : prefLabel) {
if (!first)
prefLabelString += ",\n";
prefLabelString += " {\n";
prefLabelString += " \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
prefLabelString += " \"@value\": \"" + prefLabel1.getLabel() + "\"\n";
prefLabelString += " }";
first = false;
}
prefLabelString += "\n ]";
jsonLd.append(prefLabelString);
}
// altLables
String altLabelString;
if (!altLabel.isEmpty()) {
endElement();
altLabelString = " \"alternateName" + "\": [\n";
boolean first = true;
for (SKOSLabel altLabel1 : altLabel) {
if (!first)
altLabelString += ",\n";
altLabelString += " {\n";
altLabelString += " \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
altLabelString += " \"@value\": \"" + altLabel1.getLabel() + "\"\n";
altLabelString += " }";
first = false;
}
altLabelString += "\n ]";
jsonLd.append(altLabelString);
}
}
use of skos.SKOSLabel in project opentheso by miledrousset.
the class WriteBranchSkosBDD method getTraductionConcept.
/* public String getId(String uri) {
if (uri.contains("#")) {
uri = uri.substring(uri.indexOf("#") + 1, uri.length());
}
else
{
uri = uri.substring(uri.lastIndexOf("/") + 1, uri.length());
}
return uri;
}
*/
/* 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 writeLabelsList.
public ArrayList<NodeEM> writeLabelsList(HikariDataSource ds, ArrayList<SKOSLabel> labelsList) {
ArrayList<NodeEM> nodeEMList = new ArrayList<>();
for (int i = 0; i < labelsList.size(); i++) {
SKOSLabel label = labelsList.get(i);
switch(label.getProperty()) {
case SKOSProperty.altLabel:
NodeEM nodeEM = new NodeEM();
nodeEM.setLexical_value(label.getLabel());
nodeEM.setLang(label.getLanguage());
nodeEM.setSource("");
nodeEM.setStatus("USE");
nodeEM.setHiden(false);
nodeEMList.add(nodeEM);
break;
default:
break;
}
}
return nodeEMList;
}
Aggregations