Search in sources :

Example 6 with SKOSRelation

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

use of skos.SKOSRelation in project opentheso by miledrousset.

the class WriteSkosBDD method writeRelationsListTopConcept.

public void writeRelationsListTopConcept(ArrayList<SKOSRelation> relationsList, String idConcept, String idThesaurus, int idUser) {
    ConceptHelper conceptHelper = new ConceptHelper();
    HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
    for (int i = 0; i < relationsList.size(); i++) {
        SKOSRelation relation = relationsList.get(i);
        switch(relation.getProperty()) {
            case SKOSProperty.narrower:
                hierarchicalRelationship.setIdConcept1(idConcept);
                hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
                hierarchicalRelationship.setIdThesaurus(idThesaurus);
                hierarchicalRelationship.setRole("NT");
                try {
                    Connection conn = ds.getConnection();
                    conn.setAutoCommit(false);
                    if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                        conn.rollback();
                        conn.close();
                    }
                    conn.commit();
                    conn.close();
                } catch (SQLException ex) {
                    Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
                }
                // query.addRelation(id_terme, "NT", getId(relation.getTargetUri()), id_thesaurus);
                break;
            case SKOSProperty.related:
                hierarchicalRelationship.setIdConcept1(idConcept);
                hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
                hierarchicalRelationship.setIdThesaurus(idThesaurus);
                hierarchicalRelationship.setRole("RT");
                try {
                    try (Connection conn = ds.getConnection()) {
                        conn.setAutoCommit(false);
                        if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                            conn.rollback();
                            conn.close();
                        }
                        conn.commit();
                        conn.close();
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
                }
                // query.addRelation(id_terme, "RT", getId(relation.getTargetUri()), id_thesaurus);
                break;
            default:
                break;
        }
    }
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SKOSRelation(skos.SKOSRelation)

Example 8 with SKOSRelation

use of skos.SKOSRelation in project opentheso by miledrousset.

the class WriteSkosBDD method writeRelationsList.

public void writeRelationsList(ArrayList<SKOSRelation> relationsList, String idConcept, String idThesaurus, int idUser) {
    ConceptHelper conceptHelper = new ConceptHelper();
    HierarchicalRelationship hierarchicalRelationship = new HierarchicalRelationship();
    for (SKOSRelation relation : relationsList) {
        switch(relation.getProperty()) {
            case SKOSProperty.related:
                hierarchicalRelationship.setIdConcept1(idConcept);
                hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
                hierarchicalRelationship.setIdThesaurus(idThesaurus);
                hierarchicalRelationship.setRole("RT");
                try {
                    try (Connection conn = ds.getConnection()) {
                        conn.setAutoCommit(false);
                        if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                            conn.rollback();
                            conn.close();
                        }
                        conn.commit();
                        conn.close();
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
                }
                // query.addRelation(id_terme, "RT", getId(relation.getTargetUri()), id_thesaurus);
                break;
            case SKOSProperty.narrower:
                hierarchicalRelationship.setIdConcept1(idConcept);
                hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
                hierarchicalRelationship.setIdThesaurus(idThesaurus);
                hierarchicalRelationship.setRole("NT");
                try {
                    try (Connection conn = ds.getConnection()) {
                        conn.setAutoCommit(false);
                        if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                            conn.rollback();
                            conn.close();
                        }
                        conn.commit();
                        conn.close();
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
                }
                // query.addRelation(id_terme, "NT", getId(relation.getTargetUri()), id_thesaurus);
                break;
            case SKOSProperty.broader:
                hierarchicalRelationship.setIdConcept1(idConcept);
                hierarchicalRelationship.setIdConcept2(getId(relation.getTargetUri()));
                hierarchicalRelationship.setIdThesaurus(idThesaurus);
                hierarchicalRelationship.setRole("BT");
                try {
                    try (Connection conn = ds.getConnection()) {
                        conn.setAutoCommit(false);
                        if (!conceptHelper.addLinkHierarchicalRelation(conn, hierarchicalRelationship, idUser)) {
                            conn.rollback();
                            conn.close();
                        }
                        conn.commit();
                        conn.close();
                    }
                } catch (SQLException ex) {
                    Logger.getLogger(WriteSkosBDD.class.getName()).log(Level.SEVERE, null, ex);
                }
                // query.addRelation(id_terme, "BT", getId(relation.getTargetUri()), id_thesaurus);
                break;
            default:
                break;
        }
    }
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) SQLException(java.sql.SQLException) Connection(java.sql.Connection) SKOSRelation(skos.SKOSRelation)

Example 9 with SKOSRelation

use of skos.SKOSRelation in project opentheso by miledrousset.

the class SkosToJsonld method addRelations.

private void addRelations(ArrayList<SKOSRelation> relations) {
    ArrayList<SKOSRelation> narrower = new ArrayList<>();
    ArrayList<SKOSRelation> related = new ArrayList<>();
    ArrayList<SKOSRelation> broader = new ArrayList<>();
    ArrayList<SKOSRelation> inScheme = new ArrayList<>();
    for (SKOSRelation relation : relations) {
        switch(relation.getProperty()) {
            case SKOSProperty.broader:
                broader.add(relation);
                break;
            case SKOSProperty.narrower:
                narrower.add(relation);
                break;
            case SKOSProperty.related:
                related.add(relation);
                break;
            case SKOSProperty.ConceptScheme:
                inScheme.add(relation);
                break;
            default:
                break;
        }
    }
    // broader
    if (!broader.isEmpty()) {
        addElementRelation(broader, "broader");
    }
    // narrower
    if (!narrower.isEmpty()) {
        addElementRelation(narrower, "narrower");
    }
    // related
    if (!related.isEmpty()) {
        addElementRelation(related, "related");
    }
    // ConceptScheme
    if (!inScheme.isEmpty()) {
        addElementRelation(inScheme, "inScheme");
    }
}
Also used : ArrayList(java.util.ArrayList) SKOSRelation(skos.SKOSRelation)

Example 10 with SKOSRelation

use of skos.SKOSRelation in project opentheso by miledrousset.

the class SkosToJsonld method addElementRelation.

private void addElementRelation(ArrayList<SKOSRelation> skosRelation, String nameSpace) {
    String element;
    String uri;
    StringPlus stringPlus = new StringPlus();
    if (skosRelation.size() > 1) {
        endElement();
        element = "      \"" + nameSpaceSkosCore + nameSpace + "\": [\n";
        boolean first = true;
        for (SKOSRelation skosRelation1 : skosRelation) {
            if (!first)
                element += "        },\n";
            element += "        {\n";
            uri = stringPlus.normalizeStringForXml(skosRelation1.getTargetUri());
            element += "          \"@id\": \"" + uri + "\"\n";
            first = false;
        }
        element += "        }\n";
        element += "      ]";
    } else {
        endElement();
        element = "      \"" + nameSpaceSkosCore + nameSpace + "\": {\n";
        for (SKOSRelation skosRelation1 : skosRelation) {
            uri = stringPlus.normalizeStringForXml(skosRelation1.getTargetUri());
            element += "        \"@id\": \"" + uri + "\"\n";
            element += "      }";
        }
    }
    jsonLd.append(element);
}
Also used : StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) SKOSRelation(skos.SKOSRelation)

Aggregations

SKOSRelation (skos.SKOSRelation)11 Connection (java.sql.Connection)5 SQLException (java.sql.SQLException)5 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)5 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)5 ArrayList (java.util.ArrayList)2 ConceptGroupLabel (mom.trd.opentheso.bdd.datas.ConceptGroupLabel)1 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)1 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)1 SKOSResource (skos.SKOSResource)1