Search in sources :

Example 1 with SKOSRelation

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

the class ImportRdf4jHelper method addRelation.

private void addRelation(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.broader:
                role = "BT";
                break;
            case SKOSProperty.broaderGeneric:
                role = "BTG";
                break;
            case SKOSProperty.broaderInstantive:
                role = "BTI";
                break;
            case SKOSProperty.broaderPartitive:
                role = "BTP";
                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 uri = acs.conceptResource.getUri();
        String idPere = memberHashMap.get(uri);
        if (idPere != null) {
            acs.idGrps.add(idPere);
            memberHashMap.remove(uri);
        }
    }
}
Also used : HierarchicalRelationship(mom.trd.opentheso.bdd.datas.HierarchicalRelationship) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation)

Example 2 with SKOSRelation

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

the class ImportRdf4jHelper method detectRootOfBranch.

/**
 * detecte la racine d'une branche
 *
 * @return root
 */
private SKOSResource detectRootOfBranch() {
    SKOSResource root = null;
    HashMap<String, String> uriRessourcePere = new HashMap<>();
    ArrayList<String> uriList = new ArrayList<>();
    for (SKOSResource resource : skosXmlDocument.getConceptList()) {
        String uri = resource.getUri();
        uriList.add(uri);
        for (SKOSRelation relation : resource.getRelationsList()) {
            int relationProp = relation.getProperty();
            if (relationProp == SKOSProperty.broader || relationProp == SKOSProperty.broaderGeneric || relationProp == SKOSProperty.broaderInstantive || relationProp == SKOSProperty.broaderPartitive) {
                uriRessourcePere.put(uri, relation.getTargetUri());
            }
        }
    }
    for (SKOSResource resource : skosXmlDocument.getConceptList()) {
        String uri = resource.getUri();
        // si la ressource n'a pas de père alors c'est la racine
        if (uriRessourcePere.get(uri) == null || !uriList.contains(uriRessourcePere.get(uri))) {
            root = resource;
        }
    }
    return root;
}
Also used : SKOSResource(mom.trd.opentheso.skosapi.SKOSResource) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation)

Example 3 with SKOSRelation

use of mom.trd.opentheso.skosapi.SKOSRelation 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.narrowerInstantive:
                codeRelation = "NTI";
                break;
            case SKOSProperty.narrowerPartitive:
                codeRelation = "NTP";
                break;
            case SKOSProperty.broaderGeneric:
                codeRelation = "BTG";
                break;
            case SKOSProperty.broaderInstantive:
                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)

Example 4 with SKOSRelation

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

the class WriteRdf4j method writeRelation.

private void writeRelation(SKOSResource resource) {
    int prop;
    for (SKOSRelation relation : resource.getRelationsList()) {
        IRI uri = vf.createIRI(relation.getTargetUri());
        prop = relation.getProperty();
        switch(prop) {
            case SKOSProperty.member:
                builder.add(SKOS.MEMBER, uri);
                break;
            case SKOSProperty.broader:
                builder.add(SKOS.BROADER, uri);
                break;
            case SKOSProperty.broaderGeneric:
                builder.add("skos:broaderGeneric", uri);
                break;
            case SKOSProperty.broaderInstantive:
                builder.add("skos:broaderInstantive", uri);
                break;
            case SKOSProperty.broaderPartitive:
                builder.add("skos:broaderPartitive", uri);
                break;
            case SKOSProperty.narrower:
                builder.add(SKOS.NARROWER, uri);
                break;
            case SKOSProperty.narrowerGeneric:
                builder.add("skos:narrowerGeneric", uri);
                break;
            case SKOSProperty.narrowerInstantive:
                builder.add("skos:narrowerInstantive", uri);
                break;
            case SKOSProperty.narrowerPartitive:
                builder.add("skos:narrowerPartitive", uri);
                break;
            case SKOSProperty.related:
                builder.add(SKOS.RELATED, uri);
                break;
            case SKOSProperty.relatedHasPart:
                builder.add("skos:relatedHasPart", uri);
                break;
            case SKOSProperty.relatedPartOf:
                builder.add("skos:relatedPartOf", uri);
                break;
            case SKOSProperty.hasTopConcept:
                builder.add(SKOS.HAS_TOP_CONCEPT, uri);
                break;
            case SKOSProperty.inScheme:
                builder.add(SKOS.IN_SCHEME, uri);
                break;
            case SKOSProperty.topConceptOf:
                builder.add(SKOS.TOP_CONCEPT_OF, uri);
                break;
            case SKOSProperty.subGroup:
                builder.add("iso-thes:subGroup", uri);
                break;
            case SKOSProperty.microThesaurusOf:
                builder.add("iso-thes:microThesaurusOf", uri);
                break;
            case SKOSProperty.superGroup:
                builder.add("iso-thes:superGroup", uri);
                break;
        }
    }
}
Also used : IRI(org.eclipse.rdf4j.model.IRI) SKOSRelation(mom.trd.opentheso.skosapi.SKOSRelation)

Example 5 with SKOSRelation

use of mom.trd.opentheso.skosapi.SKOSRelation 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)

Aggregations

SKOSRelation (mom.trd.opentheso.skosapi.SKOSRelation)7 SKOSLabel (mom.trd.opentheso.skosapi.SKOSLabel)3 SKOSResource (mom.trd.opentheso.skosapi.SKOSResource)3 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)2 Chunk (com.itextpdf.text.Chunk)1 Paragraph (com.itextpdf.text.Paragraph)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConceptGroupLabel (mom.trd.opentheso.bdd.datas.ConceptGroupLabel)1 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)1 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)1 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)1 UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)1 SKOSCreator (mom.trd.opentheso.skosapi.SKOSCreator)1 SKOSDocumentation (mom.trd.opentheso.skosapi.SKOSDocumentation)1 SKOSGPSCoordinates (mom.trd.opentheso.skosapi.SKOSGPSCoordinates)1 SKOSMatch (mom.trd.opentheso.skosapi.SKOSMatch)1 SKOSNotation (mom.trd.opentheso.skosapi.SKOSNotation)1 IRI (org.eclipse.rdf4j.model.IRI)1