Search in sources :

Example 1 with SKOSDocumentation

use of mom.trd.opentheso.skosapi.SKOSDocumentation in project opentheso by miledrousset.

the class AgrovocHelper method getTraductions.

/**
 * récupération des traductions
 *
 * @param jsonDatas
 * @param entity
 * @param languages
 * @return
 */
private ArrayList<SelectedResource> getTraductions(String xmlDatas, ArrayList<String> languages) {
    ArrayList<SelectedResource> traductions = new ArrayList<>();
    ArrayList<SelectedResource> descriptions = new ArrayList<>();
    String lang;
    String value;
    InputStream inputStream;
    SKOSXmlDocument sxd;
    try {
        inputStream = new ByteArrayInputStream(xmlDatas.getBytes("UTF-8"));
        // / read XML SKOS
        ReadRdf4j readRdf4j = new ReadRdf4j(inputStream, 0);
        sxd = readRdf4j.getsKOSXmlDocument();
        for (SKOSResource resource : sxd.getConceptList()) {
            for (SKOSLabel label : resource.getLabelsList()) {
                switch(label.getProperty()) {
                    case SKOSProperty.prefLabel:
                        lang = label.getLanguage();
                        value = label.getLabel();
                        if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
                            continue;
                        if (languages.contains(lang)) {
                            SelectedResource selectedResource = new SelectedResource();
                            selectedResource.setIdLang(lang);
                            selectedResource.setGettedValue(value);
                            traductions.add(selectedResource);
                        }
                        break;
                    default:
                        break;
                }
            }
            for (SKOSDocumentation sd : resource.getDocumentationsList()) {
                if (sd.getProperty() == SKOSProperty.definition) {
                    value = sd.getText();
                    lang = sd.getLanguage();
                    if (lang == null || value == null || lang.isEmpty() || value.isEmpty())
                        continue;
                    if (languages.contains(lang)) {
                        SelectedResource selectedResource = new SelectedResource();
                        selectedResource.setIdLang(lang);
                        selectedResource.setGettedValue(value);
                        descriptions.add(selectedResource);
                    }
                }
            }
        }
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(OpenthesoHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    resourceDefinitions = descriptions;
    return traductions;
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) SelectedResource(mom.trd.opentheso.core.alignment.SelectedResource) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) IOException(java.io.IOException) SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 2 with SKOSDocumentation

use of mom.trd.opentheso.skosapi.SKOSDocumentation in project opentheso by miledrousset.

the class ImportRdf4jHelper method addDocumentation.

private void addDocumentation(AddConceptsStruct acs) {
    NodeNote nodeNote;
    for (SKOSDocumentation documentation : acs.conceptResource.getDocumentationsList()) {
        String noteTypeCode = "";
        int prop = documentation.getProperty();
        nodeNote = new NodeNote();
        switch(prop) {
            case SKOSProperty.definition:
                noteTypeCode = "definition";
                break;
            case SKOSProperty.scopeNote:
                noteTypeCode = "scopeNote";
                break;
            case SKOSProperty.example:
                noteTypeCode = "example";
                break;
            case SKOSProperty.historyNote:
                noteTypeCode = "historyNote";
                break;
            case SKOSProperty.editorialNote:
                noteTypeCode = "editorialNote";
                break;
            case SKOSProperty.changeNote:
                noteTypeCode = "changeNote";
                break;
            case SKOSProperty.note:
                noteTypeCode = "note";
                break;
        }
        nodeNote.setLang(documentation.getLanguage());
        nodeNote.setLexicalvalue(documentation.getText());
        nodeNote.setNotetypecode(noteTypeCode);
        acs.nodeNotes.add(nodeNote);
    }
}
Also used : SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 3 with SKOSDocumentation

use of mom.trd.opentheso.skosapi.SKOSDocumentation in project opentheso by miledrousset.

the class ImportCandidatsTest method getNotes.

// 30 = definition, 34 = editorialNote, 36= Note, 74= Terme spécifique, 72= Terme générique,
private String getNotes(SKOSResource sKOSResource) {
    String notes = "";
    String propriete = "";
    for (SKOSDocumentation sDocumentation : sKOSResource.getDocumentationsList()) {
        if (!sDocumentation.getText().isEmpty()) {
            /*    if(sDocumentation.getProperty() == SKOSProperty.definition)//30)
                    propriete = "definition";
                if(sDocumentation.getProperty() == SKOSProperty.editorialNote) //34)
                    propriete = "editorialNote";
                if(sDocumentation.getProperty() == SKOSProperty.note)//36)
                    propriete = "Note";*/
            if (sDocumentation.getProperty() == SKOSProperty.changeNote) {
                if (notes.isEmpty())
                    notes = sDocumentation.getText();
                else
                    notes = notes + " ####  " + sDocumentation.getText();
            }
        }
    }
    /*     for (SKOSMatch sKOSMatch : sKOSResource.getMatchList()) {
            if(sKOSMatch.getValue().contains("https://ark.frantiq.fr")) {    
                if(sKOSMatch.getProperty() == 74)
                    propriete = "Terme spécifique";
                if(sKOSMatch.getProperty() == 72)
                    propriete = "Terme générique";
                  
                if(notes.isEmpty())
                    notes = propriete + "--> " + sKOSMatch.getValue();
                else 
                    notes = notes + " ####  " + propriete + "--> " + sKOSMatch.getValue();   
            }
        }*/
    return notes;
}
Also used : SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation)

Example 4 with SKOSDocumentation

use of mom.trd.opentheso.skosapi.SKOSDocumentation in project opentheso by miledrousset.

the class OpenthesoHelper method getValues.

private ArrayList<NodeAlignment> getValues(String xmlDatas, String idC, String idLang, String idTheso, String source) {
    ArrayList<NodeAlignment> listAlignValues = new ArrayList<>();
    // StringBuffer sb = new StringBuffer(xmlDatas);
    InputStream inputStream;
    SKOSXmlDocument sxd;
    try {
        inputStream = new ByteArrayInputStream(xmlDatas.getBytes("UTF-8"));
        // / read XML SKOS
        ReadRdf4j readRdf4j = new ReadRdf4j(inputStream, 0);
        sxd = readRdf4j.getsKOSXmlDocument();
        for (SKOSResource resource : sxd.getConceptList()) {
            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(idLang)) {
                            na.setConcept_target(label.getLabel());
                        }
                        break;
                    case SKOSProperty.altLabel:
                        if (label.getLanguage().equals(idLang)) {
                            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(idLang)) {
                    na.setDef_target(sd.getText());
                }
            }
            listAlignValues.add(na);
        }
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(DownloadBean.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(OpenthesoHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return listAlignValues;
}
Also used : ReadRdf4j(mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DownloadBean(mom.trd.opentheso.SelectedBeans.DownloadBean) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SKOSXmlDocument(mom.trd.opentheso.skosapi.SKOSXmlDocument) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) IOException(java.io.IOException) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 5 with SKOSDocumentation

use of mom.trd.opentheso.skosapi.SKOSDocumentation in project opentheso by miledrousset.

the class WritePdf method writeTerm.

/**
 * ajoute un paragraphe qui decri le term dans le document PDF
 *
 * @param concept
 * @param paragraphs
 */
private void writeTerm(SKOSResource concept, ArrayList<Paragraph> paragraphs, String langue, String langue2) {
    String id = getIdFromUri(concept.getUri());
    int altLabelCount = 0;
    ArrayList<Integer> tradList = idToIsTrad.get(id);
    if (tradList != null) {
        for (int lab : tradList) {
            if (lab == SKOSProperty.altLabel) {
                altLabelCount++;
            }
        }
    }
    int altLabelWrite = 0;
    for (SKOSLabel label : concept.getLabelsList()) {
        if (label.getLanguage().equals(langue) || label.getLanguage().equals(langue2)) {
            String labelValue;
            boolean prefIsTrad = false;
            boolean altIsTrad = false;
            if (label.getLanguage().equals(langue)) {
                labelValue = label.getLabel();
            } else {
                if (tradList != null) {
                    if (tradList.contains(SKOSProperty.prefLabel) && label.getProperty() == SKOSProperty.prefLabel) {
                        prefIsTrad = true;
                    }
                    if (tradList.contains(SKOSProperty.altLabel) && label.getProperty() == SKOSProperty.altLabel) {
                        if (altLabelCount > altLabelWrite) {
                            altIsTrad = true;
                        }
                        altLabelWrite++;
                    }
                }
                labelValue = "-";
            }
            if (label.getProperty() == SKOSProperty.prefLabel && !prefIsTrad) {
                Chunk chunk = new Chunk(labelValue, termFont);
                chunk.setLocalDestination(id);
                paragraphs.add(new Paragraph(chunk));
            } else if (label.getProperty() == SKOSProperty.altLabel && !altIsTrad) {
                paragraphs.add(new Paragraph("    USE: " + labelValue, textFont));
            }
        }
    }
    paragraphs.add(new Paragraph("    ID: " + id, textFont));
    for (SKOSRelation relation : concept.getRelationsList()) {
        int prop = relation.getProperty();
        String codeRelation;
        switch(prop) {
            case SKOSProperty.broader:
                codeRelation = "BT";
                break;
            case SKOSProperty.narrower:
                codeRelation = "NT";
                break;
            case SKOSProperty.related:
                codeRelation = "RT";
                break;
            case SKOSProperty.relatedHasPart:
                codeRelation = "RHP";
                break;
            case SKOSProperty.relatedPartOf:
                codeRelation = "RPO";
                break;
            case SKOSProperty.narrowerGeneric:
                codeRelation = "NTG";
                break;
            case SKOSProperty.narrowerInstantial:
                codeRelation = "NTI";
                break;
            case SKOSProperty.narrowerPartitive:
                codeRelation = "NTP";
                break;
            case SKOSProperty.broaderGeneric:
                codeRelation = "BTG";
                break;
            case SKOSProperty.broaderInstantial:
                codeRelation = "BTI";
                break;
            case SKOSProperty.broaderPartitive:
                codeRelation = "BTP";
                break;
            default:
                continue;
        }
        String key = getIdFromUri(relation.getTargetUri());
        String targetName = idToNameHashMap.get(key);
        if (targetName == null) {
            targetName = key;
        }
        Chunk chunk = new Chunk("    " + codeRelation + ": " + targetName, relationFont);
        chunk.setLocalGoto(getIdFromUri(relation.getTargetUri()));
        paragraphs.add(new Paragraph(chunk));
    }
    for (SKOSDocumentation doc : concept.getDocumentationsList()) {
        if (!doc.getLanguage().equals(langue) && !doc.getLanguage().equals(langue2)) {
            continue;
        }
        int docCount = 0;
        if (tradList != null) {
            for (int lab : tradList) {
                if (lab == SKOSProperty.note) {
                    docCount++;
                }
            }
        }
        int docWrite = 0;
        int prop = doc.getProperty();
        String docTypeName;
        switch(prop) {
            case SKOSProperty.definition:
                docTypeName = "definition";
                break;
            case SKOSProperty.scopeNote:
                docTypeName = "scopeNote";
                break;
            case SKOSProperty.example:
                docTypeName = "example";
                break;
            case SKOSProperty.historyNote:
                docTypeName = "historyNote";
                break;
            case SKOSProperty.editorialNote:
                docTypeName = "editorialNote";
                break;
            case SKOSProperty.changeNote:
                docTypeName = "changeNote";
                break;
            case SKOSProperty.note:
                docTypeName = "note";
                break;
            default:
                docTypeName = "note";
                break;
        }
        String docText = "";
        boolean docIsTrad = false;
        if (doc.getLanguage().equals(langue)) {
            docText = doc.getText();
        } else {
            if (tradList != null && tradList.contains(SKOSProperty.note)) {
                if (docCount > docWrite) {
                    docIsTrad = true;
                }
                docWrite++;
            }
        }
        if (!docIsTrad) {
            paragraphs.add(new Paragraph("    " + docTypeName + ": " + docText, textFont));
        }
    }
    for (SKOSMatch match : concept.getMatchList()) {
        int prop = match.getProperty();
        String matchTypeName = null;
        switch(prop) {
            case SKOSProperty.exactMatch:
                matchTypeName = "exactMatch";
                break;
            case SKOSProperty.closeMatch:
                matchTypeName = "closeMatch";
                break;
            case SKOSProperty.broadMatch:
                matchTypeName = "broadMatch";
                break;
            case SKOSProperty.relatedMatch:
                matchTypeName = "relatedMatch";
                break;
            case SKOSProperty.narrowMatch:
                matchTypeName = "narrowMatch";
                break;
        }
        paragraphs.add(new Paragraph("    " + matchTypeName + ": " + match.getValue(), textFont));
    }
    SKOSGPSCoordinates gps = concept.getGPSCoordinates();
    String lat = gps.getLat();
    String lon = gps.getLon();
    if (lat != null && lon != null) {
        paragraphs.add(new Paragraph("    lat: " + lat, textFont));
        paragraphs.add(new Paragraph("    lat: " + lon, textFont));
    }
}
Also used : SKOSDocumentation(mom.trd.opentheso.skosapi.SKOSDocumentation) SKOSMatch(mom.trd.opentheso.skosapi.SKOSMatch) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation) SKOSLabel(mom.trd.opentheso.skosapi.SKOSLabel) Chunk(com.itextpdf.text.Chunk) SKOSGPSCoordinates(mom.trd.opentheso.skosapi.SKOSGPSCoordinates) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

SKOSDocumentation (mom.trd.opentheso.skosapi.SKOSDocumentation)6 SKOSLabel (mom.trd.opentheso.skosapi.SKOSLabel)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 DownloadBean (mom.trd.opentheso.SelectedBeans.DownloadBean)2 ReadRdf4j (mom.trd.opentheso.core.imports.rdf4j.ReadRdf4j)2 SKOSResource (mom.trd.opentheso.skosapi.SKOSResource)2 SKOSXmlDocument (mom.trd.opentheso.skosapi.SKOSXmlDocument)2 Chunk (com.itextpdf.text.Chunk)1 Paragraph (com.itextpdf.text.Paragraph)1 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)1 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)1 SelectedResource (mom.trd.opentheso.core.alignment.SelectedResource)1 SKOSGPSCoordinates (mom.trd.opentheso.skosapi.SKOSGPSCoordinates)1 SKOSMatch (mom.trd.opentheso.skosapi.SKOSMatch)1 SKOSRelation (mom.trd.opentheso.skosapi.SKOSRelation)1 Literal (org.eclipse.rdf4j.model.Literal)1