Search in sources :

Example 16 with HierarchicalRelationship

use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship 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 17 with HierarchicalRelationship

use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.

the class ImportRdf4jHelper method addRelationNoBTHiera.

private void addRelationNoBTHiera(AddConceptsStruct acs) {
    HierarchicalRelationship hierarchicalRelationship;
    int prop;
    String idConcept2;
    for (SKOSRelation relation : acs.conceptResource.getRelationsList()) {
        prop = relation.getProperty();
        hierarchicalRelationship = new HierarchicalRelationship();
        String role;
        switch(prop) {
            case SKOSProperty.narrower:
                role = "NT";
                break;
            case SKOSProperty.narrowerGeneric:
                role = "NTG";
                break;
            case SKOSProperty.narrowerPartitive:
                role = "NTP";
                break;
            case SKOSProperty.narrowerInstantive:
                role = "NTI";
                break;
            case SKOSProperty.related:
                role = "RT";
                break;
            case SKOSProperty.relatedHasPart:
                role = "RHP";
                break;
            case SKOSProperty.relatedPartOf:
                role = "RPO";
                break;
            default:
                role = "";
        }
        if (!role.equals("")) {
            hierarchicalRelationship.setIdConcept1(acs.concept.getIdConcept());
            // option cochée
            // if(identifierType.equalsIgnoreCase("sans")){
            // idConcept2 = getIdFromUri(relation.getTargetUri());
            // } else {
            // Récupération des Id Ark ou Handle
            idConcept2 = getOriginalId(relation.getTargetUri());
            // }
            hierarchicalRelationship.setIdConcept2(idConcept2);
            hierarchicalRelationship.setIdThesaurus(idTheso);
            hierarchicalRelationship.setRole(role);
            acs.hierarchicalRelationships.add(hierarchicalRelationship);
        } else if (prop == SKOSProperty.inScheme) {
        // ?
        /*} else if (prop == SKOSProperty.memberOf) {
                acs.idGrps.add(getIdFromUri(relation.getTargetUri()));
                //addIdGroupToVector(uri);    ????
                 */
        } else if (prop == SKOSProperty.topConceptOf) {
            acs.isTopConcept = true;
        }
        if (hasTopConcceptList.contains(acs.conceptResource.getUri())) {
            acs.isTopConcept = true;
        }
        String idConcept = acs.conceptResource.getUri();
        String idPere = memberHashMap.get(idConcept);
        if (idPere != null) {
            acs.idGrps.add(idPere);
            memberHashMap.remove(idConcept);
        }
    }
}
Also used : HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation)

Example 18 with HierarchicalRelationship

use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.

the class ImportRdf4jHelper method addBranch.

/**
 * ajoute une brache en choisissant un concept père
 *
 * @param selectedTerme
 * @throws java.text.ParseException
 * @throws java.sql.SQLException
 */
public void addBranch(SelectedTerme selectedTerme) throws ParseException, SQLException {
    String idGroup = selectedTerme.getIdDomaine();
    String idConceptPere = selectedTerme.getIdC();
    idTheso = selectedTerme.getIdTheso();
    SKOSResource root = detectRootOfBranch();
    // on ajoute la racine de la branche
    AddConceptsStruct acs;
    acs = new AddConceptsStruct();
    acs.conceptHelper = new ConceptHelper();
    initAddConceptsStruct(acs, root);
    addRelationNoBTHiera(acs);
    acs.concept.setTopConcept(false);
    acs.concept.setIdGroup(idGroup);
    acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
    // on lie le nouveau concept au concept père
    HierarchicalRelationship hierarchicalRelationship1 = new HierarchicalRelationship(acs.concept.getIdConcept(), idConceptPere, idTheso, "BT");
    HierarchicalRelationship hierarchicalRelationship2 = new HierarchicalRelationship(idConceptPere, acs.concept.getIdConcept(), idTheso, "NT");
    acs.hierarchicalRelationships.add(hierarchicalRelationship1);
    acs.hierarchicalRelationships.add(hierarchicalRelationship2);
    new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
    finalizeAddConceptStruct(acs);
    // on ajoute le reste
    skosXmlDocument.getConceptList().remove(root);
    for (SKOSResource resource : skosXmlDocument.getConceptList()) {
        acs = new AddConceptsStruct();
        acs.conceptHelper = new ConceptHelper();
        initAddConceptsStruct(acs, resource);
        addRelation(acs);
        acs.concept.setTopConcept(false);
        acs.concept.setIdGroup(idGroup);
        acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
        new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
        finalizeAddConceptStruct(acs);
    }
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 19 with HierarchicalRelationship

use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.

the class ImportRdf4jHelper method addSingleConcept.

/**
 * ajoute un seul concept en choisissant un concept père
 *
 * @param selectedTerme
 * @throws java.sql.SQLException
 * @throws java.text.ParseException
 */
public void addSingleConcept(SelectedTerme selectedTerme) throws SQLException, ParseException {
    String idGroup = selectedTerme.getIdDomaine();
    String idConceptPere = selectedTerme.getIdC();
    idTheso = selectedTerme.getIdTheso();
    AddConceptsStruct acs = new AddConceptsStruct();
    acs.conceptHelper = new ConceptHelper();
    // addConcepts
    if (skosXmlDocument.getConceptList().size() == 1) {
        initAddConceptsStruct(acs, skosXmlDocument.getConceptList().get(0));
        addRelationNoBTHiera(acs);
        acs.concept.setTopConcept(false);
        acs.concept.setIdGroup(idGroup);
        acs.conceptHelper.insertConceptInTable(ds, acs.concept, idUser);
        // on lie le nouveau concept au concept père
        HierarchicalRelationship hierarchicalRelationship1 = new HierarchicalRelationship(acs.concept.getIdConcept(), idConceptPere, idTheso, "BT");
        HierarchicalRelationship hierarchicalRelationship2 = new HierarchicalRelationship(idConceptPere, acs.concept.getIdConcept(), idTheso, "NT");
        acs.hierarchicalRelationships.add(hierarchicalRelationship1);
        acs.hierarchicalRelationships.add(hierarchicalRelationship2);
        new GroupHelper().addConceptGroupConcept(ds, idGroup, acs.concept.getIdConcept(), acs.concept.getIdThesaurus());
        finalizeAddConceptStruct(acs);
    } else {
    // erreur il y a plus d'un concept
    }
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 20 with HierarchicalRelationship

use of mom.trd.opentheso.bdd.datas.HierarchicalRelationship in project opentheso by miledrousset.

the class ToolsHelper method removeLoopRelations.

/**
 * Permet de supprimer les relations en boucle qui sont interdites
 * (100 -> BT -> 100) ou  (100 -> NT -> 100)ou (100 -> RT -> 100)
 * c'est incohérent et ca provoque une boucle à l'infini
 * @param ds
 * @param role
 * @param idThesaurus
 * @return
 */
public boolean removeLoopRelations(HikariDataSource ds, String role, String idThesaurus) {
    RelationsHelper relationsHelper = new RelationsHelper();
    // récupération des relations en Loop
    ArrayList<HierarchicalRelationship> tabRelations = relationsHelper.getListLoopRelations(ds, role, idThesaurus);
    if (!tabRelations.isEmpty()) {
        for (HierarchicalRelationship relation : tabRelations) {
            relationsHelper.deleteThisRelation(ds, relation.getIdConcept1(), idThesaurus, role, relation.getIdConcept2());
        }
    }
    return true;
}
Also used : HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship)

Aggregations

HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)20 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)13 Connection (java.sql.Connection)12 SQLException (java.sql.SQLException)12 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)5 SKOSRelation (skos.SKOSRelation)5 ArrayList (java.util.ArrayList)4 Concept (mom.trd.opentheso.bdd.datas.Concept)4 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)4 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)4 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)4 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)4 Term (mom.trd.opentheso.bdd.datas.Term)3 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)3 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)3 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)3 SKOSAnnotation (org.semanticweb.skos.SKOSAnnotation)3 SKOSConcept (org.semanticweb.skos.SKOSConcept)3 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)2 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)2