use of mom.trd.opentheso.skosapi.SKOSXmlDocument 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.skosapi.SKOSXmlDocument in project opentheso by miledrousset.
the class ImportCandidatsTest method readFileSkos.
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
@Test
public void readFileSkos() {
// lecture du fichier tabulé /Users/Miled/
String path = "/Users/Miled/Desktop/Marion LAME/candidates_skos.xml";
SKOSXmlDocument sKOSXmlDocument;
FileInputStream file;
try {
file = new FileInputStream(path);
sKOSXmlDocument = loadSkos(file);
if (sKOSXmlDocument == null) {
return;
}
addCandidates(sKOSXmlDocument);
} catch (FileNotFoundException ex) {
logger.error(ex.toString());
}
}
use of mom.trd.opentheso.skosapi.SKOSXmlDocument 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.skosapi.SKOSXmlDocument 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