Search in sources :

Example 1 with SKOSConceptScheme

use of org.semanticweb.skos.SKOSConceptScheme in project opentheso by miledrousset.

the class ImportSkosHelper method addThesaurus.

/**
 * Fonction qui permet d'importer les informations d'un thésaurus
 * @return
 */
public boolean addThesaurus() {
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    idGroupDefault = getNewId();
    for (SKOSConceptScheme scheme : dataSet.getSKOSConceptSchemes()) {
        // récupération du nom de thésaurus
        thesaurus.setTitle(getIdFromUri(scheme.getURI().toString()));
        conceptsCount = dataSet.getSKOSConcepts().size();
        for (SKOSAnnotation anno : scheme.getSKOSAnnotations(dataSet)) {
            if (anno.isAnnotationByConstant()) {
                if (anno.getAnnotationValueAsConstant().isTyped()) {
                    SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                // System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                } else {
                    SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                    if (anno.getURI().toString().contains("title")) {
                        DcElement dcElement = new DcElement();
                        dcElement.setName("title");
                        dcElement.setValue(con.getLiteral());
                        if (con.hasLang()) {
                            dcElement.setLanguage(con.getLang());
                        } else
                            dcElement.setLanguage(langueSource);
                        thesaurus.addDcElement(dcElement);
                    } else {
                        DcElement dcElement = new DcElement();
                        dcElement.setName("title");
                        dcElement.setValue(con.getLiteral());
                        if (con.hasLang()) {
                            dcElement.setLanguage(con.getLang());
                        } else
                            dcElement.setLanguage(langueSource);
                        thesaurus.addDcElement(dcElement);
                    }
                }
            // * created or date;
            // if(anno.getURI().getPath().contains("date") ){
            // getThesaurusAnnotation(anno);
            // }
            // //              * modified;
            // if(anno.getURI().getPath().contains("modified") ){
            // getThesaurusAnnotation(anno);
            // }
            // * @param coverage
            // * @param creator
            // * @param description
            // * @param format
            // * @param id_langue
            // * @param publisher
            // * @param relation
            // * @param rights
            // * @param source
            // * @param subject
            // * @param title
            // * @param type
            } else // la liste des TopConcept
            {
                idTopConcept.add(getIdFromUri(anno.getAnnotationValue().getURI().toString()));
            // System.err.println(anno.getAnnotationValue().getURI().toString());
            }
        }
        if (!addThesaurusToBdd(thesaurusHelper)) {
            return false;
        }
        if (thesaurus.getDcElement().isEmpty()) {
            if (thesaurus.getTitle().isEmpty()) {
                thesaurus.setTitle("theso_" + thesaurus.getId_thesaurus());
            } else {
                thesaurus.setTitle(thesaurus.getTitle());
            }
            thesaurus.setLanguage(langueSource);
            thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
        } else {
            for (DcElement dcElement : thesaurus.getDcElement()) {
                thesaurus.setTitle(dcElement.getValue());
                thesaurus.setLanguage(dcElement.getLanguage());
                thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
            }
        }
        return true;
    }
    return false;
}
Also used : SKOSTypedLiteral(org.semanticweb.skos.SKOSTypedLiteral) DcElement(mom.trd.opentheso.bdd.datas.DcElement) SKOSUntypedLiteral(org.semanticweb.skos.SKOSUntypedLiteral) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) SKOSConceptScheme(org.semanticweb.skos.SKOSConceptScheme) SKOSAnnotation(org.semanticweb.skos.SKOSAnnotation)

Example 2 with SKOSConceptScheme

use of org.semanticweb.skos.SKOSConceptScheme in project opentheso by miledrousset.

the class ImportSkosHelper method readFile.

/**
 * Cette fonction a été modifié pour pouvoir lire un fichier SKOS en passant par un
 * InputStream, l'API standard SKOSAPI n'a pas de constructeur adapté
 * cette fonction permet de lire tout type de fichier SKOS-OWL en s'appuyant
 * sur l'api (OWLAPI-SKOSAPI)
 *
 * @param streamFilename
 * @param fileName
 * @return
 * @throws OWLOntologyCreationException
 * @throws SKOSCreationException
 */
public boolean readFile(InputStream streamFilename, String fileName) throws OWLOntologyCreationException, SKOSCreationException {
    try {
        sKOSManager = new SKOSManager();
        onto = ontologieManager.loadOntologyFromOntologyDocument(streamFilename);
        SKOSDatasetImpl voc = new SKOSDatasetImpl(sKOSManager, onto);
        if (voc.getURI() != null) {
            String theso = "";
            for (SKOSConceptScheme scheme : voc.getSKOSConceptSchemes()) {
                theso = theso + " " + scheme.getURI();
            }
            message = "new ontology loaded: " + theso;
            // voc.getAsOWLOntology().getOntologyID();
            // System.out.println("new ontology loaded: " + voc.getAsOWLOntology().getOntologyID());
            skosVocabularies.put(voc.getURI(), voc);
            dataSet = voc;
            return true;
        }
    } catch (SKOSCreationException ex) {
        Logger.getLogger(ImportSkosHelper.class.getName()).log(Level.SEVERE, null, ex);
        message = ex.getMessage();
    }
    return false;
}
Also used : SKOSDatasetImpl(uk.ac.manchester.cs.skos.SKOSDatasetImpl) SKOSConceptScheme(org.semanticweb.skos.SKOSConceptScheme) SKOSManager(org.semanticweb.skosapibinding.SKOSManager) SKOSCreationException(org.semanticweb.skos.SKOSCreationException)

Aggregations

SKOSConceptScheme (org.semanticweb.skos.SKOSConceptScheme)2 DcElement (mom.trd.opentheso.bdd.datas.DcElement)1 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)1 SKOSAnnotation (org.semanticweb.skos.SKOSAnnotation)1 SKOSCreationException (org.semanticweb.skos.SKOSCreationException)1 SKOSTypedLiteral (org.semanticweb.skos.SKOSTypedLiteral)1 SKOSUntypedLiteral (org.semanticweb.skos.SKOSUntypedLiteral)1 SKOSManager (org.semanticweb.skosapibinding.SKOSManager)1 SKOSDatasetImpl (uk.ac.manchester.cs.skos.SKOSDatasetImpl)1