Search in sources :

Example 1 with SKOSUntypedLiteral

use of org.semanticweb.skos.SKOSUntypedLiteral in project opentheso by miledrousset.

the class ImportSkosHelper method addThesaurus.

/**
 * Fonction qui permet d'importer les informations d'un thésaurus
 * @return
 */
public boolean addThesaurus() {
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    idGroupDefault = getNewId();
    for (SKOSConceptScheme scheme : dataSet.getSKOSConceptSchemes()) {
        // récupération du nom de thésaurus
        thesaurus.setTitle(getIdFromUri(scheme.getURI().toString()));
        conceptsCount = dataSet.getSKOSConcepts().size();
        for (SKOSAnnotation anno : scheme.getSKOSAnnotations(dataSet)) {
            if (anno.isAnnotationByConstant()) {
                if (anno.getAnnotationValueAsConstant().isTyped()) {
                    SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                // System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                } else {
                    SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                    if (anno.getURI().toString().contains("title")) {
                        DcElement dcElement = new DcElement();
                        dcElement.setName("title");
                        dcElement.setValue(con.getLiteral());
                        if (con.hasLang()) {
                            dcElement.setLanguage(con.getLang());
                        } else
                            dcElement.setLanguage(langueSource);
                        thesaurus.addDcElement(dcElement);
                    } else {
                        DcElement dcElement = new DcElement();
                        dcElement.setName("title");
                        dcElement.setValue(con.getLiteral());
                        if (con.hasLang()) {
                            dcElement.setLanguage(con.getLang());
                        } else
                            dcElement.setLanguage(langueSource);
                        thesaurus.addDcElement(dcElement);
                    }
                }
            // * created or date;
            // if(anno.getURI().getPath().contains("date") ){
            // getThesaurusAnnotation(anno);
            // }
            // //              * modified;
            // if(anno.getURI().getPath().contains("modified") ){
            // getThesaurusAnnotation(anno);
            // }
            // * @param coverage
            // * @param creator
            // * @param description
            // * @param format
            // * @param id_langue
            // * @param publisher
            // * @param relation
            // * @param rights
            // * @param source
            // * @param subject
            // * @param title
            // * @param type
            } else // la liste des TopConcept
            {
                idTopConcept.add(getIdFromUri(anno.getAnnotationValue().getURI().toString()));
            // System.err.println(anno.getAnnotationValue().getURI().toString());
            }
        }
        if (!addThesaurusToBdd(thesaurusHelper)) {
            return false;
        }
        if (thesaurus.getDcElement().isEmpty()) {
            if (thesaurus.getTitle().isEmpty()) {
                thesaurus.setTitle("theso_" + thesaurus.getId_thesaurus());
            } else {
                thesaurus.setTitle(thesaurus.getTitle());
            }
            thesaurus.setLanguage(langueSource);
            thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
        } else {
            for (DcElement dcElement : thesaurus.getDcElement()) {
                thesaurus.setTitle(dcElement.getValue());
                thesaurus.setLanguage(dcElement.getLanguage());
                thesaurusHelper.addThesaurusTraduction(ds, thesaurus);
            }
        }
        return true;
    }
    return false;
}
Also used : SKOSTypedLiteral(org.semanticweb.skos.SKOSTypedLiteral) DcElement(mom.trd.opentheso.bdd.datas.DcElement) SKOSUntypedLiteral(org.semanticweb.skos.SKOSUntypedLiteral) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) SKOSConceptScheme(org.semanticweb.skos.SKOSConceptScheme) SKOSAnnotation(org.semanticweb.skos.SKOSAnnotation)

Example 2 with SKOSUntypedLiteral

use of org.semanticweb.skos.SKOSUntypedLiteral in project opentheso by miledrousset.

the class skosApiTest method testReadSkos.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
// @Test
// public void hello() {}
@Test
public void testReadSkos() {
    /*    ToolsHelper toolsHelper = new ToolsHelper();
        ConceptHelper conceptHelper = new ConceptHelper();
        String id = toolsHelper.getNewId(10);
        for (int i = 0; i < 10; i++) {
            id = toolsHelper.getNewId(10);
        }
      */
    try {
        SKOSManager man = new SKOSManager();
        // 
        SKOSDataset dataSet = man.loadDatasetFromPhysicalURI(URI.create("file:/Users/Miled/Desktop/test_unesco2.rdf"));
        SKOSDataFactory sKOSDataFactory = man.getSKOSDataFactory();
        // print out all concepts;
        for (SKOSConcept concept : dataSet.getSKOSConcepts()) {
            System.out.println("Concept: " + concept.getURI());
            // get the narrower concepts
            for (SKOSEntity narrowerConcepts : concept.getSKOSRelatedEntitiesByProperty(dataSet, man.getSKOSDataFactory().getSKOSNarrowerProperty())) {
                System.err.println("\t hasNarrower: " + narrowerConcepts.getURI());
            }
            // get the broader concepts
            for (SKOSEntity broaderConcepts : concept.getSKOSRelatedEntitiesByProperty(dataSet, man.getSKOSDataFactory().getSKOSBroaderProperty())) {
                System.err.println("\t hasBroader: " + broaderConcepts.getURI());
            }
            // get the related concepts
            for (SKOSEntity relatedConcepts : concept.getSKOSRelatedEntitiesByProperty(dataSet, man.getSKOSDataFactory().getSKOSRelatedProperty())) {
                System.err.println("\t hasRelated: " + relatedConcepts.getURI());
            }
            for (SKOSAnnotation anno : concept.getSKOSAnnotations(dataSet)) {
                System.err.print("\t\tAnnotation: " + anno.getURI() + "-> ");
                if (anno.isAnnotationByConstant()) {
                    if (anno.getAnnotationValueAsConstant().isTyped()) {
                        SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                        System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                    } else {
                        SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                        System.err.print(con.getLiteral());
                        if (con.hasLang()) {
                            System.err.print("@" + con.getLang());
                        }
                    }
                    System.err.println("");
                } else {
                    System.err.println(anno.getAnnotationValue().getURI().toString());
                }
            }
        }
        System.out.println("");
        System.out.println("---------------------");
        System.out.println("");
        System.out.println("Ontology loaded!");
        for (SKOSConceptScheme scheme : dataSet.getSKOSConceptSchemes()) {
            int counter = 0;
            counter = dataSet.getSKOSConcepts().size();
            System.out.println("Count: " + counter);
            // 
            // //
            // //                for (SKOSConcept con : scheme.getConceptsInScheme(dataSet)) {
            // //                    counter++;
            // //                    System.out.println("Concept: " + con.getURI().getFragment());
            // //
            // //                    for (OWLUntypedConstant type : con.getSKOSPrefLabel(dataSet)) {
            // //                        System.out.println("PrefLabel: " + type.getLiteral() + " lang: " + type.getLang());
            // //                    }
            // //
            // //                    for (OWLUntypedConstant type : con.getSKOSAltLabel(vocab)) {
            // //                        System.out.println("AltLabel: " + type.getLiteral() + " lang: " + type.getLang());
            // //                    }
            // //
            // //                    for (SKOSConcept concepts : con.getSKOSBroaderConcepts(vocab)) {
            // //                        System.out.println("\tHas Broader: " + concepts.getURI().getFragment());
            // //                    }
            // //
            // //                }
            System.out.println("Count: " + counter);
            System.out.println("ConceptScheme: " + scheme.getURI());
            for (SKOSAnnotation anno : scheme.getSKOSAnnotations(dataSet)) {
                System.err.print("\t\tAnnotation: " + anno.getURI() + "-> ");
                if (anno.isAnnotationByConstant()) {
                    if (anno.getAnnotationValueAsConstant().isTyped()) {
                        SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                        System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                    } else {
                        SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                        System.err.print(con.getLiteral());
                        if (con.hasLang()) {
                            System.err.print("@" + con.getLang());
                        }
                    }
                    System.err.println("");
                } else {
                    System.err.println(anno.getAnnotationValue().getURI().toString());
                }
            }
            // i can get all the concepts from this scheme
            for (SKOSConcept conceptsInScheme : dataSet.getSKOSConcepts()) {
                System.err.println("\tConcepts: " + conceptsInScheme.getURI());
                for (SKOSAnnotation anno : conceptsInScheme.getSKOSAnnotations(dataSet)) {
                    System.err.print("\t\tAnnotation: " + anno.getURI() + "-> ");
                    if (anno.isAnnotationByConstant()) {
                        if (anno.getAnnotationValueAsConstant().isTyped()) {
                            SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                            System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                        } else {
                            SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                            System.err.print(con.getLiteral());
                            if (con.hasLang()) {
                                System.err.print("@" + con.getLang());
                            }
                        }
                        System.err.println("");
                    } else {
                        System.err.println(anno.getAnnotationValue().getURI().toString());
                    }
                }
            }
        }
    } catch (SKOSCreationException ex) {
        // SKOSCreationException e) {
        ex.printStackTrace();
    }
}
Also used : SKOSUntypedLiteral(org.semanticweb.skos.SKOSUntypedLiteral) SKOSManager(org.semanticweb.skosapibinding.SKOSManager) Test(org.junit.Test)

Example 3 with SKOSUntypedLiteral

use of org.semanticweb.skos.SKOSUntypedLiteral in project opentheso by miledrousset.

the class ImportSkosHelper method getValue.

private Value getValue(SKOSAnnotation anno) {
    Value value = new Value();
    // Annotation: http://www.w3.org/2004/02/skos/core#prefLabel-> arte@e
    if (anno.getAnnotationValueAsConstant().isTyped()) {
        SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
        value.setValue(con.getLiteral());
    // System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
    } else {
        SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
        value.setValue(con.getLiteral());
        if (con.hasLang()) {
            if (!con.getLang().isEmpty())
                value.setLang(con.getLang());
            else
                // la langue par defaut
                value.setLang(langueSource);
        }
    }
    return value;
}
Also used : SKOSTypedLiteral(org.semanticweb.skos.SKOSTypedLiteral) SKOSUntypedLiteral(org.semanticweb.skos.SKOSUntypedLiteral)

Example 4 with SKOSUntypedLiteral

use of org.semanticweb.skos.SKOSUntypedLiteral in project opentheso by miledrousset.

the class skosApiTest_2 method testReadSkos.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
// @Test
// public void hello() {}
@Test
public void testReadSkos() {
    /*    ToolsHelper toolsHelper = new ToolsHelper();
        ConceptHelper conceptHelper = new ConceptHelper();
        String id = toolsHelper.getNewId(10);
        for (int i = 0; i < 10; i++) {
            id = toolsHelper.getNewId(10);
        }
      */
    try {
        SKOSManager man = new SKOSManager();
        // 
        SKOSDataset dataSet = man.loadDatasetFromPhysicalURI(URI.create("file:/Users/Miled/Desktop/rameau17.xml"));
        // print out all concepts;
        for (SKOSConcept concept : dataSet.getSKOSConcepts()) {
            System.out.println("Concept: " + concept.getURI());
            // get the narrower concepts
            for (SKOSEntity narrowerConcepts : concept.getSKOSRelatedEntitiesByProperty(dataSet, man.getSKOSDataFactory().getSKOSNarrowerProperty())) {
                System.err.println("\t hasNarrower: " + narrowerConcepts.getURI());
            }
            // get the broader concepts
            for (SKOSEntity broaderConcepts : concept.getSKOSRelatedEntitiesByProperty(dataSet, man.getSKOSDataFactory().getSKOSBroaderProperty())) {
                System.err.println("\t hasBroader: " + broaderConcepts.getURI());
            }
            for (SKOSAnnotation anno : concept.getSKOSAnnotations(dataSet)) {
                System.err.print("\t\tAnnotation: " + anno.getURI() + "-> ");
                if (anno.isAnnotationByConstant()) {
                    if (anno.getAnnotationValueAsConstant().isTyped()) {
                        SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                        System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                    } else {
                        SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                        System.err.print(con.getLiteral());
                        if (con.hasLang()) {
                            System.err.print("@" + con.getLang());
                        }
                    }
                    System.err.println("");
                } else {
                    System.err.println(anno.getAnnotationValue().getURI().toString());
                }
            }
        }
        System.out.println("");
        System.out.println("---------------------");
        System.out.println("");
        System.out.println("Ontology loaded!");
        for (SKOSConceptScheme scheme : dataSet.getSKOSConceptSchemes()) {
            System.out.println("ConceptScheme: " + scheme.getURI());
            // i can get all the concepts from this scheme
            for (SKOSConcept conceptsInScheme : dataSet.getSKOSConcepts()) {
                System.err.println("\tConcepts: " + conceptsInScheme.getURI());
                for (SKOSAnnotation anno : conceptsInScheme.getSKOSAnnotations(dataSet)) {
                    System.err.print("\t\tAnnotation: " + anno.getURI() + "-> ");
                    if (anno.isAnnotationByConstant()) {
                        if (anno.getAnnotationValueAsConstant().isTyped()) {
                            SKOSTypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSTypedLiteral();
                            System.err.print(con.getLiteral() + " Type: " + con.getDataType().getURI());
                        } else {
                            SKOSUntypedLiteral con = anno.getAnnotationValueAsConstant().getAsSKOSUntypedLiteral();
                            System.err.print(con.getLiteral());
                            if (con.hasLang()) {
                                System.err.print("@" + con.getLang());
                            }
                        }
                        System.err.println("");
                    } else {
                        System.err.println(anno.getAnnotationValue().getURI().toString());
                    }
                }
            }
        }
        for (SKOSConceptScheme scheme : dataSet.getSKOSConceptSchemes()) {
        }
    // 
    // for (SKOSConcept con : scheme.getTopConcepts(vocab)) {
    // 
    // System.out.println("Top Concept: " + con.getURI());
    // 
    // }
    // 
    // int counter = 0;
    // 
    // for (SKOSConcept con : scheme.getConceptsInScheme(vocab)) {
    // counter++;
    // System.out.println("Concept: " + con.getURI().getFragment());
    // 
    // for (OWLUntypedConstant type : con.getSKOSPrefLabel(vocab)) {
    // System.out.println("PrefLabel: " + type.getLiteral() + " lang: " + type.getLang());
    // }
    // 
    // for (OWLUntypedConstant type : con.getSKOSAltLabel(vocab)) {
    // System.out.println("AltLabel: " + type.getLiteral() + " lang: " + type.getLang());
    // }
    // 
    // for (SKOSConcept concepts : con.getSKOSBroaderConcepts(vocab)) {
    // System.out.println("\tHas Broader: " + concepts.getURI().getFragment());
    // }
    // 
    // }
    // System.out.println("Count: " + counter);
    // }
    // 
    // 
    // // see if we can get and find an entity
    // 
    // SKOSEntity entity = vocab.getSKOSEntity("conker");
    // System.out.println("Entity lookup for Nose " + entity.asSKOSConcept().getAsOWLIndividual().getURI());
    // 
    // //            vocab.getAssertions();
    // //            vocab.conatinsSKOSConcept();
    // //            vocab.getSKOSObjectRelationAssertions();
    // //            vocab.getSKOSBroaderAssertions();
    // //            vocab.getSKOSNarrowerAssertions();
    // //            vocab.getSKOSRelatedAssertions();
    // 
    // 
    } catch (SKOSCreationException e) {
        e.printStackTrace();
    }
// 
}
Also used : SKOSUntypedLiteral(org.semanticweb.skos.SKOSUntypedLiteral) SKOSManager(org.semanticweb.skosapibinding.SKOSManager) Test(org.junit.Test)

Aggregations

SKOSUntypedLiteral (org.semanticweb.skos.SKOSUntypedLiteral)4 Test (org.junit.Test)2 SKOSTypedLiteral (org.semanticweb.skos.SKOSTypedLiteral)2 SKOSManager (org.semanticweb.skosapibinding.SKOSManager)2 DcElement (mom.trd.opentheso.bdd.datas.DcElement)1 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)1 SKOSAnnotation (org.semanticweb.skos.SKOSAnnotation)1 SKOSConceptScheme (org.semanticweb.skos.SKOSConceptScheme)1