Search in sources :

Example 6 with SKOSResource

use of skos.SKOSResource 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 7 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class WriteBranchSkosBDD method importBranchAfterGroup.

/**
 * Cette fonction permet d'importer une branche sous un Groupe/domaine donné
 * en intégrant automatiquement les alignements avec la source de la branche
 * @param idThesaurus
 * @param idGroup
 * @param skosDocument
 * @param dateFormat
 * @param useArk
 * @param adressSite
 * @param idUser
 */
public void importBranchAfterGroup(String idGroup, String idThesaurus, SKOSXmlDocument skosDocument, String dateFormat, boolean useArk, String adressSite, int idUser) {
    // SKOSConceptScheme conceptScheme = skosDocument.getConceptScheme();
    // ArrayList<SKOSTopConcept> topConceptsList = conceptScheme.getTopConceptsList();
    boolean isfirst = true;
    ArrayList<SKOSResource> resourcesList = skosDocument.getResourcesList();
    for (SKOSResource resource : resourcesList) {
        // on ajoute les relations BT et NT pour faire la chaine
        if (isfirst) {
            writeFirstConceptAfterGroup(resource, idGroup, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
            isfirst = false;
        // on insère le premier concept sans les BT
        } else {
            writeConceptAfterGroup(resource, idGroup, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
        }
    }
}
Also used : SKOSResource(skos.SKOSResource)

Example 8 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class WriteBranchSkosBDD method importMultiBranchUnderGroup.

/**
 * Cette fonction permet d'importer une branche entière avec plusieurs TT sous un domaine / groupe
 * @param idThesaurus
 * @param idGroup
 * @param skosDocument
 * @param dateFormat
 * @param useArk
 * @param adressSite
 * @param idUser
 */
public void importMultiBranchUnderGroup(String idThesaurus, String idGroup, SKOSXmlDocument skosDocument, String dateFormat, boolean useArk, String adressSite, int idUser) {
    boolean inScheme = false;
    boolean broader = false;
    ArrayList<SKOSResource> resourcesList = skosDocument.getResourcesList();
    // suivant le type, le traitement est différent.
    for (SKOSResource resource : resourcesList) {
        ArrayList<SKOSRelation> relations = resource.getRelationsList();
        for (SKOSRelation relation1 : relations) {
            switch(relation1.getProperty()) {
                case SKOSProperty.broader:
                    broader = true;
                    break;
                case SKOSProperty.inScheme:
                    inScheme = true;
                    break;
                default:
                    break;
            }
        }
        if (!inScheme) {
            // c'est un MT ou group
            // écrire un domaine
            idGroup = writeDomaine(resource, idThesaurus, adressSite, useArk, idUser);
        } else {
            if (!broader) {
                // c'est une TT
                // écrire un TT
                writeFirstConceptAfterGroup(resource, idGroup, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
            } else {
                // écrire un concept
                writeConceptAfterGroup(resource, idGroup, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
            }
        }
        broader = false;
        inScheme = false;
    }
// si c'est le premier Concept, on l'accroche à l'attache au concept père
// on ajoute les relations BT et NT pour faire la chaine
/*   if(isfirst) {
                writeFirstConceptAfterGroup(resource,
                    idGroup,
                    idThesaurus,
                    "fr", dateFormat, adressSite, useArk, idUser);
                isfirst = false;
                // on insère le premier concept sans les BT
            }
            else {
                writeConceptAfterGroup(resource,
                    idGroup,
                    idThesaurus,
                    "fr", dateFormat, adressSite, useArk, idUser);
            }*/
}
Also used : SKOSResource(skos.SKOSResource) SKOSRelation(skos.SKOSRelation)

Example 9 with SKOSResource

use of skos.SKOSResource 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 10 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class SkosToJsonldSchemaOrg method getJsonLdDocumentSchemaOrg.

/**
 *  Cette fonction permet de transformer un document Skos en JsonLd
 * @param skosDocument
 * @return StringBuffer
 */
public StringBuffer getJsonLdDocumentSchemaOrg(SKOSXmlDocument skosDocument) {
    if (skosDocument == null)
        return null;
    jsonLd = new StringBuffer();
    startJson();
    boolean first = true;
    // boucle pour tous les concepts
    for (SKOSResource skosConcept : skosDocument.getResourcesList()) {
        if (!first) {
            endConcept();
        }
        // startConcept();
        // add this concept to Json
        addIdConcept(skosConcept.getUri());
        // add mappings
        if (!skosConcept.getMappings().isEmpty()) {
            addSameAs(skosConcept.getMappings());
        }
        // add documentations
        if (!skosConcept.getDocumentationsList().isEmpty()) {
            addDocumentations(skosConcept.getDocumentationsList());
        }
        // add labels
        if (!skosConcept.getLabelsList().isEmpty()) {
            addLabels(skosConcept.getLabelsList());
        }
        // add relations
        /*    if(!skosConcept.getRelationsList().isEmpty()){
                addRelations(skosConcept.getRelationsList());
            }*/
        // endConcept();
        // endElement();
        first = false;
    }
    endLastConcept();
    endJson();
    return jsonLd;
}
Also used : SKOSResource(skos.SKOSResource)

Aggregations

SKOSResource (skos.SKOSResource)12 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)3 NodeLang (mom.trd.opentheso.bdd.helper.nodes.NodeLang)2 NodeUri (mom.trd.opentheso.bdd.helper.nodes.NodeUri)2 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)2 SKOSConceptScheme (skos.SKOSConceptScheme)2 SKOSLabel (skos.SKOSLabel)2 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 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 ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)1 SAXException (org.xml.sax.SAXException)1 SKOSDocumentation (skos.SKOSDocumentation)1 SKOSRelation (skos.SKOSRelation)1 SKOSTopConcept (skos.SKOSTopConcept)1