Search in sources :

Example 1 with SKOSConceptScheme

use of skos.SKOSConceptScheme in project opentheso by miledrousset.

the class SkosToJsonld method getJsonLdConceptScheme.

/**
 * à compléter plus tard pour produire du JsonLd sous forme de
 * Classe JsonLdDocument
 * @param skosDocument
 * @return
 */
/*    private JsonLdDocument setJsonLdDocument(SKOSXmlDocument skosDocument) {
        JsonLdDocument jsonLdDocument = new JsonLdDocument();
        ArrayList<JsonConcept> jsonConcepts = new ArrayList<>();
        
        // boucle pour tous les concepts
        for (SKOSResource skosConcept : skosDocument.getResourcesList()) {
            startConcept();
            // add this concept to Json
            JsonConcept jsonConcept = new JsonConcept();
            jsonConcept.setId(skosConcept.getUri());
            jsonConcept.setNameSpace(nameSpaceSkosCore + "Concept");
            jsonConcepts.add(jsonConcept);
            

        }
        
        
        
        return jsonLdDocument;
    }*/
/**
 *  Cette fonction permet de transformer un document Skos de type ConceptScheme en JsonLd
 * @param skosDocument
 * @return StringBuffer
 */
public StringBuffer getJsonLdConceptScheme(SKOSXmlDocument skosDocument) {
    if (skosDocument == null)
        return null;
    if (skosDocument.getConceptScheme().getTopConceptsList().isEmpty())
        return emptyJson();
    jsonLd = new StringBuffer();
    startJson();
    startConcept();
    // boucle pour les Groupes (ConceptScheme)
    SKOSConceptScheme sKOSConceptScheme = skosDocument.getConceptScheme();
    if (sKOSConceptScheme == null)
        return null;
    // add this uri to Json
    addIdConcept(sKOSConceptScheme.getUri());
    // add labels
    if (!sKOSConceptScheme.getSkosLabels().isEmpty()) {
        addLabels(sKOSConceptScheme.getSkosLabels());
    }
    if (!sKOSConceptScheme.getTopConceptsList().isEmpty()) {
        addElementInScheme(sKOSConceptScheme.getTopConceptsList(), "hasTopConcept");
    }
    endLastConcept();
    endJson();
    return jsonLd;
}
Also used : SKOSConceptScheme(skos.SKOSConceptScheme)

Example 2 with SKOSConceptScheme

use of skos.SKOSConceptScheme in project opentheso by miledrousset.

the class ReadFileSKOS method printEvent.

private static void printEvent(XMLStreamReader xmlr) {
    int start = -1;
    int length = -1;
    switch(xmlr.getEventType()) {
        case XMLStreamConstants.START_DOCUMENT:
            // System.out.println("START_DOCUMENT : " + localName);
            break;
        /**
         * START_ELEMENT: Le nom de la balise. Exemple:
         * <dcterms:created>2007-02-08</dcterms:created>
         * localName = created
         */
        case XMLStreamConstants.START_ELEMENT:
            String localAttribute = "";
            String attributeValue = "";
            if (xmlr.hasName()) {
                localName = xmlr.getLocalName();
            }
            /**
             * Permet de retrouver les attributs. Exemple:
             * <skos:Concept
             * rdf:about="http://frantiq.mom.fr/PACTOLS/concept#1">
             * ATTRIBUTE: http://frantiq.mom.fr/PACTOLS/concept#1
             */
            for (int i = 0; i < xmlr.getAttributeCount(); i++) {
                localAttribute = xmlr.getAttributeLocalName(i);
                attributeValue = xmlr.getAttributeValue(i);
                if ("RDF".equals(localName)) {
                // System.out.println("START_ELEMENT : " + localName);
                }
                if ("ConceptScheme".equals(localName)) {
                    if ("about".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        conceptScheme = new SKOSConceptScheme(attributeValue);
                        isConceptScheme = true;
                    }
                }
                if ("hasTopConcept".equals(localName)) {
                // System.out.println("START_ELEMENT : " + localName);
                }
                if ("Concept".equals(localName)) {
                    if ("about".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        // MT (hasTopConcept)
                        uri = attributeValue;
                        // autres
                        resource = new SKOSResource(uri);
                    }
                }
                if ("prefLabel".equals(localName)) {
                    if ("lang".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        langPrefLabel = attributeValue;
                    }
                }
                if ("altLabel".equals(localName)) {
                    if ("lang".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        langAltLabel = attributeValue;
                    }
                }
                if ("scopeNote".equals(localName)) {
                    if ("lang".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        langScopeNote = attributeValue;
                    }
                }
                if ("historyNote".equals(localName)) {
                    if ("lang".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        langHistoryNote = attributeValue;
                    }
                }
                if (localName.equalsIgnoreCase("definition")) {
                    if (localAttribute.equalsIgnoreCase("lang")) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        langDefinitionNote = attributeValue;
                    }
                }
                if ("editorialNote".equals(localName)) {
                    if ("lang".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        langEditorialNote = attributeValue;
                    }
                }
                if ("created".equals(localName)) {
                // System.out.println("START_ELEMENT : " + localName);
                }
                if ("modified".equals(localName)) {
                // System.out.println("START_ELEMENT : " + localName);
                }
                if ("inScheme".equals(localName)) {
                    if ("resource".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        uri = attributeValue;
                        resource.addRelation(uri, SKOSProperty.inScheme);
                    }
                }
                if ("broader".equals(localName)) {
                    if ("resource".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        uri = attributeValue;
                        resource.addRelation(uri, SKOSProperty.broader);
                    }
                }
                if ("narrower".equals(localName)) {
                    if ("resource".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        uri = attributeValue;
                        resource.addRelation(uri, SKOSProperty.narrower);
                    }
                }
                if ("related".equals(localName)) {
                    if ("resource".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        uri = attributeValue;
                        resource.addRelation(uri, SKOSProperty.related);
                    }
                }
                if ("closeMatch".equals(localName)) {
                    if ("resource".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        uri = attributeValue;
                        resource.addMapping(uri, SKOSMapping.closeMatch);
                    }
                }
                if ("exactMatch".equals(localName)) {
                    if ("resource".equals(localAttribute)) {
                        // System.out.println("START_ELEMENT : " + localName);
                        // System.out.println("ATTRIBUTE : " + attributeValue);
                        uri = attributeValue;
                        resource.addMapping(uri, SKOSMapping.exactMatch);
                    }
                }
            }
            break;
        /**
         * CHARACTERS: Le contenu de la balise. Exemple:
         * <dcterms:created>2007-02-08</dcterms:created>
         * CHARACTERS: 2007-02-08
         */
        case XMLStreamConstants.CHARACTERS:
            start = xmlr.getTextStart();
            length = xmlr.getTextLength();
            String text = new String(xmlr.getTextCharacters(), start, length);
            if (resource != null) {
                if (text.trim().length() > 0) {
                    if ("prefLabel".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        if (isConceptScheme) {
                            conceptScheme.addLabel(text, langPrefLabel, SKOSProperty.prefLabel);
                        } else
                            resource.addLabel(text, langPrefLabel, SKOSProperty.prefLabel);
                    }
                    if ("altLabel".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addLabel(text, langAltLabel, SKOSProperty.altLabel);
                    }
                    if ("scopeNote".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addDocumentation(text, langScopeNote, SKOSProperty.scopeNote);
                    }
                    if ("historyNote".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addDocumentation(text, langHistoryNote, SKOSProperty.historyNote);
                    }
                    if ("definition".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addDocumentation(text, langDefinitionNote, SKOSProperty.definition);
                    }
                    if ("editorialNote".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addDocumentation(text, langEditorialNote, SKOSProperty.editorialNote);
                    }
                    if ("created".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addDate(text, SKOSProperty.created);
                    }
                    if ("modified".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addDate(text, SKOSProperty.modified);
                    }
                    if ("identifier".equals(localName)) {
                        // System.out.println("CHARACTERS : " + text);
                        resource.addIdentifier(text, SKOSProperty.identifier);
                    }
                }
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            /**
             * localName correspond à la balise en cours Exemple:
             * <skos:prefLabel xml:lang="fr">Oeuvres</skos:prefLabel>
             * localName = prefLabel
             */
            if (xmlr.hasName()) {
                localName = xmlr.getLocalName();
                if ("RDF".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
                if ("ConceptScheme".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    thesaurus.setConceptScheme(conceptScheme);
                    // A la fin du bloc ConceptScheme, vider les ressources du thésaurus
                    thesaurus.clearResourcesList();
                    isConceptScheme = false;
                }
                if ("hasTopConcept".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    conceptScheme.addTopConcept(uri);
                    uri = null;
                }
                if ("Concept".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    thesaurus.addResource(resource);
                    resource = null;
                }
                if ("prefLabel".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    langPrefLabel = null;
                }
                if ("altLabel".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    langAltLabel = null;
                }
                if ("scopeNote".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    langScopeNote = null;
                }
                if ("historyNote".equals(localName)) {
                    // System.out.println("END_ELEMENT : " + localName);
                    langHistoryNote = null;
                }
                if ("created".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
                if ("modified".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
                if ("inScheme".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
                if ("broader".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
                if ("narrower".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
                if ("related".equals(localName)) {
                // System.out.println("END_ELEMENT : " + localName);
                }
            }
            break;
        case XMLStreamConstants.COMMENT:
            // System.out.println("COMMENT : "+ localName);
            break;
        case XMLStreamConstants.END_DOCUMENT:
            // System.out.println("END_DOCUMENT : " + localName);
            break;
        default:
            break;
    }
}
Also used : SKOSResource(skos.SKOSResource) SKOSConceptScheme(skos.SKOSConceptScheme)

Example 3 with SKOSConceptScheme

use of skos.SKOSConceptScheme in project opentheso by miledrousset.

the class WriteSkosBDD method writeThesaurus.

public void writeThesaurus(SKOSXmlDocument skosDocument, String dateFormat, boolean useArk, String adressSite, int idUser, String langueSource) {
    SKOSConceptScheme conceptScheme = skosDocument.getConceptScheme();
    ArrayList<SKOSTopConcept> topConceptsList = conceptScheme.getTopConceptsList();
    ArrayList<SKOSResource> resourcesList = skosDocument.getResourcesList();
    /*
         * Création du Thésaurus
         */
    String descriptionThesaurus = getThesaurusName(conceptScheme.getUri());
    // if(!query.thesaurusExistLangue(descriptionThesaurus, id_langueSource)) {
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    Thesaurus thesaurus = new Thesaurus();
    thesaurus.setTitle(descriptionThesaurus);
    thesaurus.setLanguage(langueSource);
    String idThesaurus = thesaurusHelper.addThesaurus(ds, thesaurus, adressSite, useArk);
    if (idThesaurus == null)
        return;
    thesaurus.setId_thesaurus(idThesaurus);
    try {
        Connection conn = ds.getConnection();
        conn.setAutoCommit(false);
        UserHelper userHelper = new UserHelper();
        int idRole = userHelper.getRoleOfUser(ds, idUser);
        if (!userHelper.addRole(conn, idUser, idRole, idThesaurus, "")) {
            conn.rollback();
            conn.close();
            return;
        }
        conn.commit();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
    }
    // Si le Titre du thésaurus n'est pas detecter, on donne un nom par defaut
    if (conceptScheme.getSkosLabels().isEmpty()) {
        if (thesaurus.getTitle().isEmpty()) {
            thesaurus.setTitle("Theso_" + idThesaurus);
            thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
        }
    }
    for (SKOSLabel skosLabel : conceptScheme.getSkosLabels()) {
        thesaurus.setTitle(skosLabel.getLabel());
        thesaurus.setLanguage(skosLabel.getLanguage());
        thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
    }
    idsTopConcept = new ArrayList<>();
    for (SKOSResource resource : resourcesList) {
        if (resource != null) {
            if (!isDescriptor(resource, topConceptsList)) {
                // on insère un domaine
                writeDomaine(resource, idThesaurus, "fr", adressSite, useArk, idUser);
            } else {
                // on insère un concept
                writeConcept(resource, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
            }
        }
    }
    // ici la fin du fichier on controle si le thésaurus a toutes les langues des concepts
    // Vérifier l'existence de la langue et l'ajouter si elle n'existe pas déjà
    addLangsToThesaurus(ds, idThesaurus);
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SKOSLabel(skos.SKOSLabel) SKOSResource(skos.SKOSResource) Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) SKOSConceptScheme(skos.SKOSConceptScheme) SKOSTopConcept(skos.SKOSTopConcept)

Example 4 with SKOSConceptScheme

use of skos.SKOSConceptScheme in project opentheso by miledrousset.

the class SkosToJsonldSchemaOrg method getJsonLdConceptScheme.

/**
 *  Cette fonction permet de transformer un document Skos de type ConceptScheme en JsonLd
 * @param skosDocument
 * @return StringBuffer
 */
public StringBuffer getJsonLdConceptScheme(SKOSXmlDocument skosDocument) {
    if (skosDocument == null)
        return null;
    jsonLd = new StringBuffer();
    startJson();
    // startConcept();
    // boucle pour les Groupes (ConceptScheme)
    SKOSConceptScheme sKOSConceptScheme = skosDocument.getConceptScheme();
    if (sKOSConceptScheme == null)
        return null;
    else {
    }
    // add this uri to Json
    addIdConcept(sKOSConceptScheme.getUri());
    // add labels
    if (!sKOSConceptScheme.getSkosLabels().isEmpty()) {
        addLabels(sKOSConceptScheme.getSkosLabels());
    }
    if (!sKOSConceptScheme.getTopConceptsList().isEmpty()) {
        addElementInScheme(sKOSConceptScheme.getTopConceptsList(), "hasTopConcept");
    }
    endLastConcept();
    endJson();
    return jsonLd;
}
Also used : SKOSConceptScheme(skos.SKOSConceptScheme)

Aggregations

SKOSConceptScheme (skos.SKOSConceptScheme)4 SKOSResource (skos.SKOSResource)2 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)1 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)1 UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)1 SKOSLabel (skos.SKOSLabel)1 SKOSTopConcept (skos.SKOSTopConcept)1