Search in sources :

Example 1 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class WriteBranchSkosBDD method importBranchAfterConcept.

/**
 * Cette fonction permet d'importer une branche sous un Concept
 * @param idConcept
 * @param idThesaurus
 * @param idGroup
 * @param skosDocument
 * @param dateFormat
 * @param useArk
 * @param adressSite
 * @param idUser
 */
public void importBranchAfterConcept(String idConcept, 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) {
            writeFirstConcept(resource, idConcept, idGroup, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
            isfirst = false;
        // on insère le premier concept sans les BT
        } else {
            writeConcept(resource, idConcept, idGroup, idThesaurus, "fr", dateFormat, adressSite, useArk, idUser);
        }
    }
}
Also used : SKOSResource(skos.SKOSResource)

Example 2 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class AlignmentQuery method queryOpentheso.

/**
 * Cette fonction permet de récupérer les alignements présents sur Opentheso
 * pour un concept passé en paramètre et un thésaurus donné
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @param requete
 * @param source
 * @return
 */
public ArrayList<NodeAlignment> queryOpentheso(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
    if (requete.trim().equals("")) {
        return null;
    }
    if (lexicalValue.trim().equals("")) {
        return null;
    }
    listeAlign = new ArrayList<>();
    // construction de la requête de type (webservices Opentheso)
    lexicalValue = lexicalValue.replaceAll(" ", "%20");
    requete = requete.replace("##lang##", lang);
    requete = requete.replace("##value##", lexicalValue);
    try {
        URL url = new URL(requete);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/xml");
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
        String output;
        String xmlRecord = "";
        while ((output = br.readLine()) != null) {
            xmlRecord += output;
        }
        byte[] bytes = xmlRecord.getBytes();
        xmlRecord = new String(bytes, Charset.forName("UTF-8"));
        conn.disconnect();
        StringBuffer sb = new StringBuffer(xmlRecord);
        try {
            SKOSXmlDocument sxd = new ReadFileSKOS().readStringBuffer(sb);
            for (SKOSResource resource : sxd.getResourcesList()) {
                NodeAlignment na = new NodeAlignment();
                na.setInternal_id_concept(idC);
                na.setInternal_id_thesaurus(idTheso);
                // "Pactols");
                na.setThesaurus_target(source);
                na.setUri_target(resource.getUri());
                for (SKOSLabel label : resource.getLabelsList()) {
                    switch(label.getProperty()) {
                        case SKOSProperty.prefLabel:
                            if (label.getLanguage().equals(lang)) {
                                na.setConcept_target(label.getLabel());
                            }
                            break;
                        case SKOSProperty.altLabel:
                            if (label.getLanguage().equals(lang)) {
                                if (na.getConcept_target_alt().isEmpty()) {
                                    na.setConcept_target_alt(label.getLabel());
                                } else {
                                    na.setConcept_target_alt(na.getConcept_target_alt() + ";" + label.getLabel());
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                for (SKOSDocumentation sd : resource.getDocumentationsList()) {
                    if (sd.getProperty() == SKOSProperty.definition && sd.getLanguage().equals(lang)) {
                        na.setDef_target(sd.getText());
                    }
                }
                listeAlign.add(na);
            }
        } catch (Exception ex) {
            Logger.getLogger(AlignmentQuery.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    return listeAlign;
}
Also used : MalformedURLException(java.net.MalformedURLException) SKOSXmlDocument(skos.SKOSXmlDocument) SKOSLabel(skos.SKOSLabel) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) HttpURLConnection(java.net.HttpURLConnection) SKOSResource(skos.SKOSResource) SKOSDocumentation(skos.SKOSDocumentation) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Example 3 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class SkosToJsonld method getJsonLdDocument.

/**
 *  Cette fonction permet de transformer un document Skos en JsonLd
 * @param skosDocument
 * @return StringBuffer
 */
public StringBuffer getJsonLdDocument(SKOSXmlDocument skosDocument) {
    if (skosDocument == null)
        return null;
    if (skosDocument.getResourcesList().isEmpty())
        return emptyJson();
    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 dates
        if (!skosConcept.getDateList().isEmpty()) {
            addDates(skosConcept.getDateList());
        }
        // add Identifier / second
        if (skosConcept.getSdc() != null) {
            if (!skosConcept.getSdc().getIdentifier().isEmpty()) {
                addIdentifier(skosConcept.getSdc().getIdentifier());
            }
        }
        // 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());
        }
        // add mappings
        if (!skosConcept.getMappings().isEmpty()) {
            addMappings(skosConcept.getMappings());
        }
        // endConcept();
        // endElement();
        first = false;
    }
    endLastConcept();
    endJson();
    return jsonLd;
}
Also used : SKOSResource(skos.SKOSResource)

Example 4 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class WriteFileSKOS method writeDescriptor.

/**
 * Cette fonction permet d'exporter un Concept au format SKOS, Si
 * l'identifiant Ark existe, on l'exporte comme URI, sinon, on utilise
 * l'adresse URI du Site par defaut.
 *
 * @param nodeConceptExport
 * @param selectedLanguages
 *
 * @return true ou false
 */
public boolean writeDescriptor(NodeConceptExport nodeConceptExport, List<NodeLang> selectedLanguages) {
    /*
        // test pour savoir si le concept n'a pas de PrefLabel dans cette langue, il sera ignoré
        boolean havePrefLabel = false;
        if(selectedLanguages != null) {
            for (int i = 0; i < nodeConceptExport.getNodeTermTraductions().size(); i++) {
                for (NodeLang selectedLanguage : selectedLanguages) {
                    if (nodeConceptExport.getNodeTermTraductions().get(i).getLang().equalsIgnoreCase(
                            selectedLanguage.getCode())) {
                        havePrefLabel = true;
                    }
                }
            }
            if(!havePrefLabel) return true; // on ignore le concept
        }*/
    SKOSResource concept = new SKOSResource(getUri(nodeConceptExport));
    if (nodeConceptExport == null) {
        return true;
    }
    if (nodeConceptExport.getNodeTermTraductions() == null) {
        return true;
    }
    for (int i = 0; i < nodeConceptExport.getNodeTermTraductions().size(); i++) {
        if (selectedLanguages != null) {
            // if(nodeConceptExport.getNodeTermTraductions().get(i).getLang().equalsIgnoreCase("fr"))
            for (NodeLang selectedLanguage : selectedLanguages) {
                if (nodeConceptExport.getNodeTermTraductions().get(i).getLang().equalsIgnoreCase(selectedLanguage.getCode())) {
                    concept.addLabel(nodeConceptExport.getNodeTermTraductions().get(i).getLexicalValue(), nodeConceptExport.getNodeTermTraductions().get(i).getLang(), SKOSProperty.prefLabel);
                }
            }
        } else {
            concept.addLabel(nodeConceptExport.getNodeTermTraductions().get(i).getLexicalValue(), nodeConceptExport.getNodeTermTraductions().get(i).getLang(), SKOSProperty.prefLabel);
        }
    }
    concept.addDate(nodeConceptExport.getConcept().getCreated().toString(), SKOSProperty.created);
    concept.addDate(nodeConceptExport.getConcept().getModified().toString(), SKOSProperty.modified);
    if (!nodeConceptExport.getConcept().getNotation().isEmpty()) {
        concept.addNotation(nodeConceptExport.getConcept().getNotation(), SKOSProperty.notation);
    }
    if (!nodeConceptExport.getConcept().getIdConcept().isEmpty()) {
        concept.addIdentifier(nodeConceptExport.getConcept().getIdConcept(), SKOSProperty.identifier);
    }
    for (int i = 0; i < nodeConceptExport.getNodeListIdsOfConceptGroup().size(); i++) {
        // concept.addRelation(URI + "/concept#" + nodeConceptExport.getNodeListIdsOfConceptGroup().get(i), SKOSProperty.inScheme);
        concept.addRelation(getRelationUri_inScheme(nodeConceptExport.getNodeListIdsOfConceptGroup().get(i), nodeConceptExport.getConcept().getIdThesaurus()), SKOSProperty.inScheme);
    }
    for (int i = 0; i < nodeConceptExport.getNodeListOfBT().size(); i++) {
        // concept.addRelation(URI + "/concept#" + nodeConceptExport.getNodeListIdsOfBT().get(i), SKOSProperty.broader);
        concept.addRelation(getRelationUri(nodeConceptExport.getNodeListOfBT().get(i).getUri(), nodeConceptExport.getConcept().getIdThesaurus()), SKOSProperty.broader);
    }
    for (int i = 0; i < nodeConceptExport.getNodeListOfNT().size(); i++) {
        // concept.addRelation(URI + "/concept#" + nodeConceptExport.getNodeListIdsOfNT().get(i), SKOSProperty.narrower);
        concept.addRelation(getRelationUri(nodeConceptExport.getNodeListOfNT().get(i).getUri(), nodeConceptExport.getConcept().getIdThesaurus()), SKOSProperty.narrower);
    }
    for (int i = 0; i < nodeConceptExport.getNodeListIdsOfRT().size(); i++) {
        // concept.addRelation(URI + "/concept#" + nodeConceptExport.getNodeListIdsOfRT().get(i), SKOSProperty.related);
        concept.addRelation(getRelationUri(nodeConceptExport.getNodeListIdsOfRT().get(i).getUri(), nodeConceptExport.getConcept().getIdThesaurus()), SKOSProperty.related);
    }
    for (int i = 0; i < nodeConceptExport.getNodeEM().size(); i++) {
        if (nodeConceptExport.getNodeEM().get(i).isHiden()) {
            concept.addLabel(nodeConceptExport.getNodeEM().get(i).getLexical_value(), nodeConceptExport.getNodeEM().get(i).getLang(), SKOSProperty.hiddenLabel);
        } else {
            concept.addLabel(nodeConceptExport.getNodeEM().get(i).getLexical_value(), nodeConceptExport.getNodeEM().get(i).getLang(), SKOSProperty.altLabel);
        }
    }
    for (NodeAlignment alignment : nodeConceptExport.getNodeAlignmentsList()) {
        // alignement exactMatch
        if (alignment.getAlignement_id_type() == 1) {
            concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.exactMatch);
        }
        // alignement closeMatch
        if (alignment.getAlignement_id_type() == 2) {
            concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.closeMatch);
        }
        // alignement broadMatch
        if (alignment.getAlignement_id_type() == 3) {
            concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.broadMatch);
        }
        // alignement relatedMatch
        if (alignment.getAlignement_id_type() == 4) {
            concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.relatedMatch);
        }
        // alignement narrowMatch
        if (alignment.getAlignement_id_type() == 5) {
            concept.addMapping(prepareUriTohtml(alignment.getUri_target()), SKOSMapping.narrowMatch);
        }
    }
    for (NodeNote nodeNote : nodeConceptExport.getNodeNoteTerm()) {
        if (nodeNote.getNotetypecode().equalsIgnoreCase("historyNote")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.historyNote);
        }
        if (nodeNote.getNotetypecode().equalsIgnoreCase("editorialNote")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.editorialNote);
        }
        if (nodeNote.getNotetypecode().equalsIgnoreCase("definition")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.definition);
        }
    }
    for (NodeNote nodeNote : nodeConceptExport.getNodeNoteConcept()) {
        if (nodeNote.getNotetypecode().equalsIgnoreCase("note")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.note);
        }
        if (nodeNote.getNotetypecode().equalsIgnoreCase("scopeNote")) {
            concept.addDocumentation(nodeNote.getLexicalvalue(), nodeNote.getLang(), SKOSProperty.scopeNote);
        }
    }
    if (nodeConceptExport.getNodeGps() != null) {
        concept.addSkosGps(nodeConceptExport.getNodeGps().getLatitude(), SKOSProperty.latitude);
        concept.addSkosGps(nodeConceptExport.getNodeGps().getLongitude(), SKOSProperty.longitude);
    }
    skosBuff.append("    ").append(concept.toString());
    return true;
}
Also used : NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) SKOSResource(skos.SKOSResource) NodeLang(mom.trd.opentheso.bdd.helper.nodes.NodeLang) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 5 with SKOSResource

use of skos.SKOSResource in project opentheso by miledrousset.

the class WriteFileSKOS_Frantiq method writeGroup.

/**
 * @param nodeGroupLabel
 * @param listIdOfTopConcept
 *
 * @return true ou false
 */
public boolean writeGroup(NodeGroupLabel nodeGroupLabel, ArrayList<NodeUri> listIdOfTopConcept) {
    SKOSResource concept;
    // if(nodeGroupLabel.getIdArk() == null || nodeGroupLabel.getIdArk().trim().isEmpty()) {
    /*
            Cette partie est pour l'export des PACTOLS pour Frantiq
            */
    concept = new SKOSResource(serverAdress + "concept#" + nodeGroupLabel.getIdGroup());
    for (int i = 0; i < nodeGroupLabel.getNodeGroupTraductionses().size(); i++) {
        concept.addLabel(nodeGroupLabel.getNodeGroupTraductionses().get(i).getTitle(), nodeGroupLabel.getNodeGroupTraductionses().get(i).getIdLang(), SKOSProperty.prefLabel);
    }
    if (!nodeGroupLabel.getNodeGroupTraductionses().isEmpty()) {
        concept.addDate(nodeGroupLabel.getNodeGroupTraductionses().get(0).getCreated().toString(), SKOSProperty.created);
        concept.addDate(nodeGroupLabel.getNodeGroupTraductionses().get(0).getModified().toString(), SKOSProperty.modified);
    }
    if (!nodeGroupLabel.getIdGroup().isEmpty()) {
        concept.addIdentifier(nodeGroupLabel.getIdGroup(), SKOSProperty.identifier);
    }
    for (NodeUri listIdOfTopConcept1 : listIdOfTopConcept) {
        // if(listIdOfTopConcept1.getIdArk() == null || listIdOfTopConcept1.getIdArk().trim().isEmpty()) {
        concept.addRelation(URI + "concept#" + listIdOfTopConcept1.getIdConcept(), SKOSProperty.narrower);
    /*
                concept.addRelation(serverAdress +
                        "?idc=" + listIdOfTopConcept1.getIdConcept() +
                        "&amp;idt=" + nodeGroupLabel.getIdThesaurus(),
                        SKOSProperty.narrower);*/
    /*    }
            else {
                concept.addRelation(serverArk +
                    listIdOfTopConcept1.getIdArk(),
                    SKOSProperty.narrower);
            }*/
    }
    skosBuff.append("    ").append(concept.toString());
    return true;
}
Also used : SKOSResource(skos.SKOSResource) NodeUri(mom.trd.opentheso.bdd.helper.nodes.NodeUri)

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