Search in sources :

Example 1 with ReadRdf4j

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;
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) IOException(java.io.IOException) SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with ReadRdf4j

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;
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) IOException(java.io.IOException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) SQLException(java.sql.SQLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with ReadRdf4j

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();
        }
    }
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) InputStream(java.io.InputStream) IOException(java.io.IOException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 4 with ReadRdf4j

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();
        }
    }
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) InputStream(java.io.InputStream) IOException(java.io.IOException) SQLException(java.sql.SQLException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 5 with ReadRdf4j

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;
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) IOException(java.io.IOException) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

IOException (java.io.IOException)7 ReadRdf4j (mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j)7 InputStream (java.io.InputStream)6 SQLException (java.sql.SQLException)5 ParseException (java.text.ParseException)4 SKOSXmlDocument (mom.trd.opentheso.skosapi.SKOSXmlDocument)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 DownloadBean (mom.trd.opentheso.SelectedBeans.DownloadBean)2 SKOSDocumentation (mom.trd.opentheso.skosapi.SKOSDocumentation)2 SKOSLabel (mom.trd.opentheso.skosapi.SKOSLabel)2 SKOSResource (mom.trd.opentheso.skosapi.SKOSResource)2 FileNotFoundException (java.io.FileNotFoundException)1 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)1 SelectedResource (mom.trd.opentheso.core.alignment.SelectedResource)1