use of mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j in project opentheso by miledrousset.
the class AgrovocHelper method getTraductions.
/**
* récupération des traductions
*
* @param jsonDatas
* @param entity
* @param languages
* @return
*/
private ArrayList<SelectedResource> getTraductions(String xmlDatas, ArrayList<String> languages) {
ArrayList<SelectedResource> traductions = new ArrayList<>();
ArrayList<SelectedResource> descriptions = new ArrayList<>();
String lang;
String value;
InputStream inputStream;
SKOSXmlDocument sxd;
try {
inputStream = new ByteArrayInputStream(xmlDatas.getBytes("UTF-8"));
// / read XML SKOS
ReadRdf4j readRdf4j = new ReadRdf4j(inputStream, 0);
sxd = readRdf4j.getsKOSXmlDocument();
for (SKOSResource resource : sxd.getConceptList()) {
for (SKOSLabel label : resource.getLabelsList()) {
switch(label.getProperty()) {
case SKOSProperty.prefLabel:
lang = label.getLanguage();
value = label.getLabel();
if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
continue;
if (languages.contains(lang)) {
SelectedResource selectedResource = new SelectedResource();
selectedResource.setIdLang(lang);
selectedResource.setGettedValue(value);
traductions.add(selectedResource);
}
break;
default:
break;
}
}
for (SKOSDocumentation sd : resource.getDocumentationsList()) {
if (sd.getProperty() == SKOSProperty.definition) {
value = sd.getText();
lang = sd.getLanguage();
if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
continue;
if (languages.contains(lang)) {
SelectedResource selectedResource = new SelectedResource();
selectedResource.setIdLang(lang);
selectedResource.setGettedValue(value);
descriptions.add(selectedResource);
}
}
}
}
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(OpenthesoHelper.class.getName()).log(Level.SEVERE, null, ex);
}
resourceDefinitions = descriptions;
return traductions;
}
use of mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j in project opentheso by miledrousset.
the class ImportCandidatsTest method loadSkos.
private SKOSXmlDocument loadSkos(InputStream path) {
ReadRdf4j readRdf4j = null;
try {
readRdf4j = new ReadRdf4j(path, 0);
} catch (IOException ex) {
message = ex.getMessage();
} catch (Exception ex) {
message = ex.toString();
}
if (readRdf4j == null) {
message = "Erreur de format RDF !!!";
return null;
}
SKOSXmlDocument sKOSXmlDocument = readRdf4j.getsKOSXmlDocument();
int total = sKOSXmlDocument.getConceptList().size() + sKOSXmlDocument.getGroupList().size();
String uri = sKOSXmlDocument.getTitle();
return sKOSXmlDocument;
}
use of mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j in project opentheso by miledrousset.
the class rdf4jFileBean method chargeSkos.
public void chargeSkos(FileUploadEvent event) {
progress = 0;
if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
} else {
InputStream is = null;
try {
try {
is = event.getFile().getInputstream();
} catch (IOException ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
} catch (Exception ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
}
ReadRdf4j readRdf4j = null;
try {
readRdf4j = new ReadRdf4j(is, 0);
} catch (IOException ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
} catch (Exception ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.toString());
}
if (readRdf4j == null) {
error.append(System.getProperty("line.separator"));
error.append("Erreur de format RDF !!!");
showError();
return;
}
warning = readRdf4j.getMessage();
progress = 100;
sKOSXmlDocument = readRdf4j.getsKOSXmlDocument();
total = sKOSXmlDocument.getConceptList().size() + sKOSXmlDocument.getGroupList().size() + 1;
uri = sKOSXmlDocument.getTitle();
uploadEnable = false;
BDDinsertEnable = true;
info = "File correctly loaded";
} catch (Exception e) {
System.out.println("erreur :" + e.getMessage());
error.append(System.getProperty("line.separator"));
error.append(e.toString());
} finally {
showError();
}
}
}
use of mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j in project opentheso by miledrousset.
the class rdf4jFileBean method chargeTurtle.
/**
* @param event
*/
public void chargeTurtle(FileUploadEvent event) {
progress = 0;
if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
} else {
InputStream is = null;
try {
try {
is = event.getFile().getInputstream();
} catch (IOException ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
} catch (Exception ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
}
ReadRdf4j readRdf4j;
try {
readRdf4j = new ReadRdf4j(is, 2);
warning = readRdf4j.getMessage();
progress = 100;
sKOSXmlDocument = readRdf4j.getsKOSXmlDocument();
total = sKOSXmlDocument.getConceptList().size() + sKOSXmlDocument.getGroupList().size() + 1;
uri = sKOSXmlDocument.getTitle();
uploadEnable = false;
BDDinsertEnable = true;
info = "File correctly loaded";
} catch (IOException ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
} catch (Exception ex) {
error.append(System.getProperty("line.separator"));
error.append(ex.getMessage());
}
} catch (Exception e) {
error.append(System.getProperty("line.separator"));
error.append(e.toString());
} finally {
showError();
}
}
}
use of mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j in project opentheso by miledrousset.
the class OpenthesoHelper method getValues.
private ArrayList<NodeAlignment> getValues(String xmlDatas, String idC, String idLang, String idTheso, String source) {
ArrayList<NodeAlignment> listAlignValues = new ArrayList<>();
// StringBuffer sb = new StringBuffer(xmlDatas);
InputStream inputStream;
SKOSXmlDocument sxd;
try {
inputStream = new ByteArrayInputStream(xmlDatas.getBytes("UTF-8"));
// / read XML SKOS
ReadRdf4j readRdf4j = new ReadRdf4j(inputStream, 0);
sxd = readRdf4j.getsKOSXmlDocument();
for (SKOSResource resource : sxd.getConceptList()) {
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(idLang)) {
na.setConcept_target(label.getLabel());
}
break;
case SKOSProperty.altLabel:
if (label.getLanguage().equals(idLang)) {
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(idLang)) {
na.setDef_target(sd.getText());
}
}
listAlignValues.add(na);
}
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(OpenthesoHelper.class.getName()).log(Level.SEVERE, null, ex);
}
return listAlignValues;
}
Aggregations