NullPointer exception for anonymous individual in getSKOSAnnotations

23 views
Skip to first unread message

H K

unread,
Sep 13, 2013, 1:38:10 PM9/13/13
to skos...@googlegroups.com
Hi,
I'm using the SKOS API to read in SKOS RDF for a library of congress subject heading and then parse that information.  For certain files, I see a NullPointerException thrown by SKOSDataFactoryImpl.getSKOSAnnotation. I've tried to do some debugging and have also run the RDF file through a RDF parser but can't see why this error would be occurring for this file.

The file in question:
http://id.loc.gov/authorities/subjects/sh85034759.skos.rdf

The relevant code snippet (really anytime getSKOSAnnotations is called which appears to be every time any annotation is accessed):
SKOSDataset dataset = manager.loadDataset(conceptURI); // where ConceptURI -> URI ConceptURI = new URI("http://id.loc.gov/authorities/subjects/sh85034759.skos.rdf");
Set<SKOSConcept> skosConcepts = dataset.getSKOSConcepts();
for (SKOSConcept skosConcept : skosConcepts) {

Set<SKOSLiteral> prefLabelProperties = skosConcept
                    .getSKOSRelatedConstantByProperty(dataset,
                            prefLabelProperty); //this method leads to the error
}


The error I get:
ava.lang.NullPointerException
    at uk.ac.manchester.cs.skos.SKOSDataFactoryImpl.getSKOSAnnotation(SKOSDataFactoryImpl.java:148)
    at uk.ac.manchester.cs.skos.SKOSDatasetImpl.getSKOSAnnotations(SKOSDatasetImpl.java:400)
    at uk.ac.manchester.cs.skos.SKOSDatasetImpl.getSKOSAnnotationsByURI(SKOSDatasetImpl.java:377)
    at uk.ac.manchester.cs.skos.SKOSConceptImpl.getSKOSRelatedConstantByProperty(SKOSConceptImpl.java:117) 

Digging a little deeper, the following annotation in the file makes the error occur:
Annotation(<http://www.w3.org/2004/02/skos/core#changeNote> _:http://id.loc.gov/authorities/subjects/sh85034759.skos.rdf#genid4)

Specifically, SKOSDatasetImpl.getSKOSAnnotations's loop through OWL annotations is unable to retrieve either a resource or literal value and so annoVis.getCurrentResource returns null (since the resource is still null).
For reference, that method is as follows (I've added some comments):

 public Set<SKOSAnnotation> getSKOSAnnotations(SKOSEntity entity) {

        Set<SKOSAnnotation> annotations = new HashSet<SKOSAnnotation>();
        OWLIndividual ind = skos2owlConverter.getAsOWLIndiviudal(entity);

        AnnotationVisitor annoVis = new AnnotationVisitor(skosManContent);

        for (OWLAnnotation anno : ind.asOWLNamedIndividual().getAnnotations(owlOntology)) {

            OWLAnnotationValue value = anno.getValue(); //the value it gets is an OWLAnonymousIndividualImpl individual
            value.accept(annoVis); //at this point, annoVis shows neither a resource or a literal
            if (annoVis.getCurrentLiteral() != null) { //this is null so it skips to the next line
                annotations.add(skosManContent.getSKOSDataFactory().getSKOSAnnotation(anno.getProperty().getIRI().toURI(), annoVis.getCurrentLiteral()));
            }
            else { //unfortunately, annoVis.getCurrentResource() is also null, leading to a null pointer exception thrown by getSKOSAnnotation
                annotations.add(skosManContent.getSKOSDataFactory().getSKOSAnnotation(anno.getProperty().getIRI().toURI(), annoVis.getCurrentResource()));
            }
        }

        return annotations;
    }
Any thoughts as to why this is occurring? 
I used the following RDF Validator : http://www.w3.org/RDF/Validator/ and the RDF file seemed fine.

I have seen other SKOS files that have anonymous individuals but they don't seem to be throwing any errors.
Any help would be greatly appreciated!!! : )

H Khan

Simon Jupp

unread,
Sep 17, 2013, 6:26:25 PM9/17/13
to skos-dev
Hi,
I've only had a quick look into this but I don't think the problem is your file. The problem is the SKOS API not dealing with anonymous individuals very nicely. There is an unimplemented method in SKOSDatasetImpl where the anonymous individual is visited, there is an (bad) assumption in the SKOS API that all SKOS resources will be OWLNamedIndividuals according the OWL API implementation. 

My advice at this stage would be to dig into the OWL API implementation, you can access all the OWL objects from the SKOS API. This way you can read all the OWLAnnotations, rather than the limited set of SKOSAnnotations. 

Cheers
Simon


--
You received this message because you are subscribed to the Google Groups "skos-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skos-dev+u...@googlegroups.com.
To post to this group, send email to skos...@googlegroups.com.
Visit this group at http://groups.google.com/group/skos-dev.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages