Search in sources :

Example 66 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class SkosToJsonld method addElementInScheme.

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

Example 67 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class SkosToJsonld method addLabels.

private void addLabels(ArrayList<SKOSLabel> sKOSLabels) {
    ArrayList<SKOSLabel> prefLabel = new ArrayList<>();
    ArrayList<SKOSLabel> altLabel = new ArrayList<>();
    StringPlus stringPlus = new StringPlus();
    for (SKOSLabel sKOSLabel : sKOSLabels) {
        switch(sKOSLabel.getProperty()) {
            case SKOSProperty.prefLabel:
                prefLabel.add(sKOSLabel);
                break;
            case SKOSProperty.altLabel:
                altLabel.add(sKOSLabel);
                break;
            default:
                break;
        }
    }
    // prefLabls
    String prefLabelString;
    if (!prefLabel.isEmpty()) {
        if (prefLabel.size() > 1) {
            endElement();
            prefLabelString = "      \"" + nameSpaceSkosCore + "prefLabel" + "\": [\n";
            boolean first = true;
            for (SKOSLabel prefLabel1 : prefLabel) {
                if (!first)
                    prefLabelString += ",\n";
                prefLabelString += "        {\n";
                prefLabelString += "          \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
                prefLabelString += "          \"@value\": \"" + stringPlus.normalizeStringForXml(prefLabel1.getLabel()) + "\"\n";
                prefLabelString += "        }";
                first = false;
            }
            prefLabelString += "\n      ]";
        } else {
            endElement();
            prefLabelString = "      \"" + nameSpaceSkosCore + "prefLabel" + "\": {\n";
            for (SKOSLabel prefLabel1 : prefLabel) {
                prefLabelString += "        \"@language\": \"" + prefLabel1.getLanguage() + "\",\n";
                prefLabelString += "        \"@value\": \"" + stringPlus.normalizeStringForXml(prefLabel1.getLabel()) + "\"\n";
                prefLabelString += "      }";
            }
        }
        jsonLd.append(prefLabelString);
    }
    // altLables
    String altLabelString;
    if (!altLabel.isEmpty()) {
        if (altLabel.size() > 1) {
            endElement();
            altLabelString = "      \"" + nameSpaceSkosCore + "altLabel" + "\": [\n";
            boolean first = true;
            for (SKOSLabel altLabel1 : altLabel) {
                if (!first)
                    altLabelString += ",\n";
                altLabelString += "        {\n";
                altLabelString += "          \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
                altLabelString += "          \"@value\": \"" + stringPlus.normalizeStringForXml(altLabel1.getLabel()) + "\"\n";
                altLabelString += "        }";
                first = false;
            }
            altLabelString += "\n      ]";
        } else {
            endElement();
            altLabelString = "      \"" + nameSpaceSkosCore + "altLabel" + "\": {\n";
            for (SKOSLabel altLabel1 : altLabel) {
                altLabelString += "        \"@language\": \"" + altLabel1.getLanguage() + "\",\n";
                altLabelString += "        \"@value\": \"" + stringPlus.normalizeStringForXml(altLabel1.getLabel()) + "\"\n";
                altLabelString += "      }";
            }
        }
        jsonLd.append(altLabelString);
    }
}
Also used : StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) ArrayList(java.util.ArrayList) SKOSLabel(skos.SKOSLabel)

Example 68 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class SkosToJsonld method addElementMapping.

private void addElementMapping(ArrayList<SKOSMapping> skosRelation, String nameSpace) {
    String element;
    String uri;
    StringPlus stringPlus = new StringPlus();
    if (skosRelation.size() > 1) {
        boolean first = true;
        endElement();
        element = "      \"" + nameSpaceSkosCore + nameSpace + "\": [\n";
        for (SKOSMapping 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 (SKOSMapping skosRelation1 : skosRelation) {
            uri = stringPlus.normalizeStringForXml(skosRelation1.getTargetUri());
            element += "        \"@id\": \"" + uri + "\"\n";
            element += "      }";
        }
    }
    jsonLd.append(element);
}
Also used : StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) SKOSMapping(skos.SKOSMapping)

Example 69 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus 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)

Example 70 with StringPlus

use of mom.trd.opentheso.bdd.tools.StringPlus in project opentheso by miledrousset.

the class SearchHelper method getListPermuteNonPreferredTerm.

/**
 * Cette fonction permet de récupérer une liste des concepts Synonymes sous
 * forme permutée
 *
 * @param ds
 * @param idThesaurus
 * @param idLang
 * @param value
 * @return ArrayList de NodePermute
 */
public ArrayList<NodePermute> getListPermuteNonPreferredTerm(HikariDataSource ds, String idThesaurus, String idLang, String value) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodePermute> nodePermuteList = null;
    value = new StringPlus().convertString(value);
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT DISTINCT ord, id_concept, " + " id_lang, lexical_value, id_group" + " FROM permuted WHERE" + " id_lang = '" + idLang + "'" + " and id_thesaurus = '" + idThesaurus + "'" + " and ispreferredterm = " + false + " and unaccent_string(lexical_value) ilike" + " unaccent_string('" + value + "%')" + " order by lexical_value ASC LIMIT 200";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                nodePermuteList = new ArrayList<>();
                while (resultSet.next()) {
                    NodePermute nodePermute = new NodePermute();
                    nodePermute.setIdThesaurus(idThesaurus);
                    nodePermute.setIdConcept(resultSet.getString("id_concept"));
                    nodePermute.setIdLang(resultSet.getString("id_lang"));
                    nodePermute.setSearchedValue(resultSet.getString("lexical_value"));
                    nodePermute.setIndexOfValue(resultSet.getInt("ord"));
                    nodePermute.setIdGroup(resultSet.getString("id_group"));
                    nodePermute.setIsPreferredTerm(false);
                    // cas où le terme recherché est égal au terme retrouvé, on le place en premier
                    if (value.trim().equalsIgnoreCase(nodePermute.getSearchedValue().trim())) {
                        nodePermuteList.add(0, nodePermute);
                    } else {
                        nodePermuteList.add(nodePermute);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting List Permute of Value : " + value, sqle);
    }
    if (nodePermuteList != null) {
        nodePermuteList = addColumnsToPermute(ds, idThesaurus, nodePermuteList);
    }
    return nodePermuteList;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NodePermute(mom.trd.opentheso.bdd.helper.nodes.NodePermute)

Aggregations

StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)80 SQLException (java.sql.SQLException)63 Statement (java.sql.Statement)63 Connection (java.sql.Connection)56 ResultSet (java.sql.ResultSet)30 PreparedStatement (java.sql.PreparedStatement)19 ArrayList (java.util.ArrayList)12 NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)6 NodeSearch (mom.trd.opentheso.bdd.helper.nodes.search.NodeSearch)6 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)4 FacesMessage (javax.faces.application.FacesMessage)2 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)2 NodeBT (mom.trd.opentheso.bdd.helper.nodes.NodeBT)2 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)2 NodePermute (mom.trd.opentheso.bdd.helper.nodes.NodePermute)2 NodeConcept (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept)2 PrefixString (com.k_int.IR.QueryModels.PrefixString)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 ConnexionTest (connexion.ConnexionTest)1 DcElement (fr.mom.arkeo.soap.DcElement)1