Search in sources :

Example 1 with SKOSXmlDocument

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;
}
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 2 with 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());
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) FileInputStream(java.io.FileInputStream) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Example 3 with SKOSXmlDocument

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;
}
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 4 with SKOSXmlDocument

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;
}
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

SKOSXmlDocument (mom.trd.opentheso.skosapi.SKOSXmlDocument)4 IOException (java.io.IOException)3 ReadRdf4j (mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)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 ConnexionTest (connexion.ConnexionTest)1 FileInputStream (java.io.FileInputStream)1 SQLException (java.sql.SQLException)1 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)1 SelectedResource (mom.trd.opentheso.core.alignment.SelectedResource)1 Test (org.junit.Test)1