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.rdfThe 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