Search in sources :

Example 1 with SKOSManager

use of org.semanticweb.skosapibinding.SKOSManager in project opentheso by miledrousset.

the class ImportSkosHelper method readFile.

/**
 * Cette fonction a été modifié pour pouvoir lire un fichier SKOS en passant par un
 * InputStream, l'API standard SKOSAPI n'a pas de constructeur adapté
 * cette fonction permet de lire tout type de fichier SKOS-OWL en s'appuyant
 * sur l'api (OWLAPI-SKOSAPI)
 *
 * @param streamFilename
 * @param fileName
 * @return
 * @throws OWLOntologyCreationException
 * @throws SKOSCreationException
 */
public boolean readFile(InputStream streamFilename, String fileName) throws OWLOntologyCreationException, SKOSCreationException {
    try {
        sKOSManager = new SKOSManager();
        onto = ontologieManager.loadOntologyFromOntologyDocument(streamFilename);
        SKOSDatasetImpl voc = new SKOSDatasetImpl(sKOSManager, onto);
        if (voc.getURI() != null) {
            String theso = "";
            for (SKOSConceptScheme scheme : voc.getSKOSConceptSchemes()) {
                theso = theso + " " + scheme.getURI();
            }
            message = "new ontology loaded: " + theso;
            // voc.getAsOWLOntology().getOntologyID();
            // System.out.println("new ontology loaded: " + voc.getAsOWLOntology().getOntologyID());
            skosVocabularies.put(voc.getURI(), voc);
            dataSet = voc;
            return true;
        }
    } catch (SKOSCreationException ex) {
        Logger.getLogger(ImportSkosHelper.class.getName()).log(Level.SEVERE, null, ex);
        message = ex.getMessage();
    }
    return false;
}
Also used : SKOSDatasetImpl(uk.ac.manchester.cs.skos.SKOSDatasetImpl) SKOSConceptScheme(org.semanticweb.skos.SKOSConceptScheme) SKOSManager(org.semanticweb.skosapibinding.SKOSManager) SKOSCreationException(org.semanticweb.skos.SKOSCreationException)

Example 2 with SKOSManager

use of org.semanticweb.skosapibinding.SKOSManager 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 SKOSManager

use of org.semanticweb.skosapibinding.SKOSManager 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

SKOSManager (org.semanticweb.skosapibinding.SKOSManager)3 Test (org.junit.Test)2 SKOSUntypedLiteral (org.semanticweb.skos.SKOSUntypedLiteral)2 SKOSConceptScheme (org.semanticweb.skos.SKOSConceptScheme)1 SKOSCreationException (org.semanticweb.skos.SKOSCreationException)1 SKOSDatasetImpl (uk.ac.manchester.cs.skos.SKOSDatasetImpl)1