Search in sources :

Example 11 with NodeUri

use of mom.trd.opentheso.bdd.helper.nodes.NodeUri in project opentheso by miledrousset.

the class ConceptHelper method getListIdsOfTopConceptsForExport.

/**
 * Cettte fonction permet de retourner la liste des TopConcept avec IdArk et
 * handle pour un groupe
 *
 * @param ds
 * @param idGroup
 * @param idThesaurus
 * @return
 */
public ArrayList<NodeUri> getListIdsOfTopConceptsForExport(HikariDataSource ds, String idGroup, String idThesaurus) {
    ArrayList<NodeUri> NodeUris = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept, id_ark, id_handle from concept" + " left join concept_group_concept on id_concept = idconcept" + " and id_thesaurus = idthesaurus" + " where id_thesaurus = '" + idThesaurus + "'" + " and idgroup = '" + idGroup + "'" + " and top_concept = true";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeUri nodeUri = new NodeUri();
                    if ((resultSet.getString("id_ark") == null) || (resultSet.getString("id_ark").trim().isEmpty())) {
                        nodeUri.setIdArk("");
                    } else {
                        nodeUri.setIdArk(resultSet.getString("id_ark"));
                    }
                    if ((resultSet.getString("id_handle") == null) || (resultSet.getString("id_handle").trim().isEmpty())) {
                        nodeUri.setIdHandle("");
                    } else {
                        nodeUri.setIdHandle(resultSet.getString("id_handle"));
                    }
                    nodeUri.setIdConcept(resultSet.getString("id_concept"));
                    NodeUris.add(nodeUri);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting Liste ID of TT of Group with ark and handle : " + idGroup, sqle);
    }
    return NodeUris;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NodeUri(mom.trd.opentheso.bdd.helper.nodes.NodeUri)

Example 12 with NodeUri

use of mom.trd.opentheso.bdd.helper.nodes.NodeUri in project opentheso by miledrousset.

the class ExportRdf4jHelper method writeGroupInfo.

private void writeGroupInfo(SKOSResource sKOSResource, String idThesaurus, String idOfGroupChildren, List<NodeLang> selectedLanguages) {
    NodeGroupLabel nodeGroupLabel;
    nodeGroupLabel = new GroupHelper().getNodeGroupLabel(ds, idOfGroupChildren, idThesaurus);
    sKOSResource.setUri(getUriFromId(idOfGroupChildren));
    sKOSResource.setProperty(SKOSProperty.ConceptGroup);
    for (NodeGroupTraductions traduction : nodeGroupLabel.getNodeGroupTraductionses()) {
        boolean isInSelectedLanguages = false;
        for (NodeLang nodeLang : selectedLanguages) {
            if (nodeLang.getCode().equals(traduction.getIdLang())) {
                isInSelectedLanguages = true;
                break;
            }
        }
        if (!isInSelectedLanguages) {
            continue;
        }
        sKOSResource.addLabel(traduction.getTitle(), traduction.getIdLang(), SKOSProperty.prefLabel);
        // dates
        String created;
        String modified;
        created = traduction.getCreated().toString();
        modified = traduction.getModified().toString();
        if (created != null) {
            sKOSResource.addDate(created, SKOSProperty.created);
        }
        if (modified != null) {
            sKOSResource.addDate(modified, SKOSProperty.modified);
        }
    }
    ArrayList<String> childURI = new GroupHelper().getListGroupChildIdOfGroup(ds, idOfGroupChildren, idThesaurus);
    ArrayList<NodeUri> nodeUris = new ConceptHelper().getListIdsOfTopConceptsForExport(ds, idOfGroupChildren, idThesaurus);
    for (NodeUri nodeUri : nodeUris) {
        sKOSResource.addRelation(getUriFromNodeUri(nodeUri, idThesaurus), SKOSProperty.member);
        addMember(nodeUri.getIdConcept(), idThesaurus, sKOSResource);
    }
    for (String id : childURI) {
        sKOSResource.addRelation(getUriFromId(id), SKOSProperty.subGroup);
        superGroupHashMap.put(id, idOfGroupChildren);
    }
    // addNotes(idOfGroupChildren, group, selectedLanguages);
    // addGPS(idOfGroupChildren, group);
    // addAlignement(idOfGroupChildren, group);
    // addRelation(idOfGroupChildren, group);
    String idSuperGroup = superGroupHashMap.get(idOfGroupChildren);
    if (idSuperGroup != null) {
        sKOSResource.addRelation(getUriFromId(idSuperGroup), SKOSProperty.superGroup);
        superGroupHashMap.remove(idOfGroupChildren);
    }
    skosXmlDocument.addGroup(sKOSResource);
    // liste top concept
    nodeTTs.addAll(nodeUris);
    for (NodeUri topConcept : nodeTTs) {
        skosXmlDocument.getConceptScheme().addRelation(getUriFromNodeUri(topConcept, idThesaurus), SKOSProperty.hasTopConcept);
    }
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeGroupLabel(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroupLabel) NodeLang(mom.trd.opentheso.bdd.helper.nodes.NodeLang) NodeUri(mom.trd.opentheso.bdd.helper.nodes.NodeUri) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) NodeGroupTraductions(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroupTraductions)

Example 13 with NodeUri

use of mom.trd.opentheso.bdd.helper.nodes.NodeUri in project opentheso by miledrousset.

the class ExportTxtHelper method writeConcepts.

/**
 * Permet d'écrire les concepts en bouclant par récursivité pour définir les
 * niveaux
 *
 * @param idGroup
 */
private void writeConcepts(String idGroup) {
    ConceptHelper conceptHelper = new ConceptHelper();
    ArrayList<NodeUri> nodeUris;
    // la liste des TopConcepts pour un Groupe
    nodeUris = conceptHelper.getListIdsOfTopConceptsForExport(ds, idGroup, idTheso);
    if (nodeUris == null) {
        return;
    }
    // pour compter le décalage (indentations)
    nodeUris.forEach((nodeUri) -> {
        String indentation = "";
        countIndentation(nodeUri.getIdConcept(), indentation);
    });
    // on écrit les concepts et le décalage par tabulation
    nodeUris.forEach((nodeUri) -> {
        String indentation = "";
        writeConceptsInfo(nodeUri.getIdConcept(), indentation);
        writeConceptRecursive(nodeUri.getIdConcept(), indentation);
    });
    writeColumnHeader();
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NodeUri(mom.trd.opentheso.bdd.helper.nodes.NodeUri) PrefixString(com.k_int.IR.QueryModels.PrefixString)

Example 14 with NodeUri

use of mom.trd.opentheso.bdd.helper.nodes.NodeUri in project opentheso by miledrousset.

the class ExportFromBDD method exportThesaurusAdvanced.

/**
 * Fonction récursive permettant d'exporter le thésaurus de la tête jusqu'au
 * dernier descripteur en filtrant par langues et domaines choisis
 *
 * @param ds
 * @param idThesaurus
 * @param selectedLanguages
 * @param selectedGroups
 * @param downloadBean
 * @return
 */
public StringBuffer exportThesaurusAdvanced(HikariDataSource ds, String idThesaurus, List<NodeLang> selectedLanguages, List<NodeGroup> selectedGroups, DownloadBean downloadBean) {
    /*
         * Ecriture du thésaurus
         */
    this.downloadBean = downloadBean;
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    NodeThesaurus nodeThesaurus = thesaurusHelper.getNodeThesaurus(ds, idThesaurus);
    WriteFileSKOS writeFileSKOS = new WriteFileSKOS();
    // inititialisation des URI
    writeFileSKOS.setServerArk(serverArk);
    writeFileSKOS.setServerAdress(serverAdress);
    writeFileSKOS.writeHeader();
    String idArk = thesaurusHelper.getIdArkOfThesaurus(ds, idThesaurus);
    if (idArk == null || idArk.trim().isEmpty()) {
        writeFileSKOS.setURI(serverAdress);
    } else {
        writeFileSKOS.setURI(serverArk);
    }
    // writeFileSKOS.setURI("http://opentheso.frantiq.fr/" + nodeThesaurus.getListThesaurusTraduction().get(0).getTitle());
    // thesaurus.description);
    writeFileSKOS.writeThesaurus(nodeThesaurus);
    // ecriture des TopConcept
    GroupHelper conceptGroupHelper = new GroupHelper();
    ArrayList<String> tabIdGroup = conceptGroupHelper.getListIdOfGroup(ds, idThesaurus);
    for (String tabIdGroup1 : tabIdGroup) {
        writeFileSKOS.writeTopConcepts(tabIdGroup1, idThesaurus);
    }
    writeFileSKOS.writeEndOfMicroThesaurusList();
    // fin du bloc thésaurus et id of TopConcept
    // écriture des Domaines et Descripteurs avec traductions
    ArrayList<NodeUri> idOfTopConcept;
    for (String tabIdGroup1 : tabIdGroup) {
        for (NodeGroup nodeGroup : selectedGroups) {
            if (nodeGroup.getConceptGroup().getIdgroup().equalsIgnoreCase(tabIdGroup1)) {
                NodeGroupLabel nodeGroupLabel = conceptGroupHelper.getNodeGroupLabel(ds, tabIdGroup1, idThesaurus);
                idOfTopConcept = new ConceptHelper().getListIdsOfTopConceptsForExport(ds, tabIdGroup1, idThesaurus);
                writeFileSKOS.writeGroup(nodeGroupLabel, idOfTopConcept, selectedLanguages);
            }
        }
    }
    for (String tabIdGroup1 : tabIdGroup) {
        for (NodeGroup nodeGroup : selectedGroups) {
            if (nodeGroup.getConceptGroup().getIdgroup().equalsIgnoreCase(tabIdGroup1)) {
                idOfTopConcept = new ConceptHelper().getListIdsOfTopConceptsForExport(ds, tabIdGroup1, idThesaurus);
                for (NodeUri idOfTopConcept1 : idOfTopConcept) {
                    exportAllConceptsAdvanced(ds, idOfTopConcept1.getIdConcept(), idThesaurus, writeFileSKOS, selectedLanguages);
                }
            }
        }
    }
    writeFileSKOS.endSkos();
    return writeFileSKOS.getSkosBuff();
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) NodeGroupLabel(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroupLabel) NodeThesaurus(mom.trd.opentheso.bdd.helper.nodes.thesaurus.NodeThesaurus) NodeUri(mom.trd.opentheso.bdd.helper.nodes.NodeUri) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) NodeGroup(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroup)

Example 15 with NodeUri

use of mom.trd.opentheso.bdd.helper.nodes.NodeUri in project opentheso by miledrousset.

the class ExportFromBDD method exportThesaurus.

/**
 * Fonction récursive permettant d'exporter le thésaurus de la tête jusqu'au
 * dernier descripteur
 *
 * @param ds
 * @param idThesaurus
 * @return
 */
public StringBuffer exportThesaurus(HikariDataSource ds, String idThesaurus) {
    /*
         * Ecriture du thésaurus
         */
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    NodeThesaurus nodeThesaurus = thesaurusHelper.getNodeThesaurus(ds, idThesaurus);
    WriteFileSKOS writeFileSKOS = new WriteFileSKOS();
    // inititialisation des URI
    writeFileSKOS.setServerArk(serverArk);
    writeFileSKOS.setServerAdress(serverAdress);
    writeFileSKOS.writeHeader();
    String idArk = thesaurusHelper.getIdArkOfThesaurus(ds, idThesaurus);
    if (idArk == null || idArk.trim().isEmpty()) {
        writeFileSKOS.setURI(serverAdress);
    } else {
        writeFileSKOS.setURI(serverArk);
    }
    // writeFileSKOS.setURI("http://opentheso.frantiq.fr/" + nodeThesaurus.getListThesaurusTraduction().get(0).getTitle());
    // thesaurus.description);
    writeFileSKOS.writeThesaurus(nodeThesaurus);
    // ecriture des TopConcept
    GroupHelper conceptGroupHelper = new GroupHelper();
    ArrayList<String> tabIdGroup = conceptGroupHelper.getListIdOfGroup(ds, idThesaurus);
    for (String tabIdGroup1 : tabIdGroup) {
        writeFileSKOS.writeTopConcepts(tabIdGroup1, idThesaurus);
    }
    writeFileSKOS.writeEndOfMicroThesaurusList();
    // fin du bloc thésaurus et id of TopConcept
    // écriture des Domaines et Descripteurs avec traductions
    ArrayList<NodeUri> idOfTopConcept;
    for (String tabIdGroup1 : tabIdGroup) {
        NodeGroupLabel nodeGroupLabel = conceptGroupHelper.getNodeGroupLabel(ds, tabIdGroup1, idThesaurus);
        idOfTopConcept = new ConceptHelper().getListIdsOfTopConceptsForExport(ds, tabIdGroup1, idThesaurus);
        writeFileSKOS.writeGroup(nodeGroupLabel, idOfTopConcept, null);
    }
    for (String tabIdGroup1 : tabIdGroup) {
        idOfTopConcept = new ConceptHelper().getListIdsOfTopConceptsForExport(ds, tabIdGroup1, idThesaurus);
        for (NodeUri idOfTopConcept1 : idOfTopConcept) {
            exportAllConcepts(ds, idOfTopConcept1.getIdConcept(), idThesaurus, writeFileSKOS);
        }
    }
    writeFileSKOS.endSkos();
    return writeFileSKOS.getSkosBuff();
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) NodeGroupLabel(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroupLabel) NodeThesaurus(mom.trd.opentheso.bdd.helper.nodes.thesaurus.NodeThesaurus) NodeUri(mom.trd.opentheso.bdd.helper.nodes.NodeUri) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Aggregations

NodeUri (mom.trd.opentheso.bdd.helper.nodes.NodeUri)20 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)9 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)8 NodeGroupLabel (mom.trd.opentheso.bdd.helper.nodes.group.NodeGroupLabel)8 ArrayList (java.util.ArrayList)5 NodeHieraRelation (mom.trd.opentheso.bdd.helper.nodes.NodeHieraRelation)4 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)3 NodeLang (mom.trd.opentheso.bdd.helper.nodes.NodeLang)3 NodeConceptExport (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptExport)3 NodeThesaurus (mom.trd.opentheso.bdd.helper.nodes.thesaurus.NodeThesaurus)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 Concept (mom.trd.opentheso.bdd.datas.Concept)2 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)2 NodeConcept (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept)2 SKOSResource (skos.SKOSResource)2 PrefixString (com.k_int.IR.QueryModels.PrefixString)1