model.isEmpty() should be enough: http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/rdf/model/Model.html#isEmpty()
On Mon, Mar 2, 2015 at 6:58 PM, Maarten van Dessel <maarten.vandes...@ugent.be> wrote: > I'm sorry for the inconvenience, it was a mistake on my end. > Apparently " model.listStatements.hasNext() " does seem to test correctly if > a model is empty. > > >> Op 2-mrt.-2015, om 18:04 heeft Martynas Jusevičius <marty...@graphity.org> >> het volgende geschreven: >> >> What's the query code? You are probably querying from an inferencing >> model that imports example.com ontology. >> >> On Mon, Mar 2, 2015 at 4:58 PM, Maarten van Dessel >> <maartenvandes...@hotmail.com> wrote: >>> Hi everyone, >>> >>> I'm using construct queries in a project. I want to make decisions based on >>> wether the constructed model contains any data. Is there any way on how >>> this can be known? >>> >>> Example query: >>> CONSTRUCT >>> { ?person <http://example.com#hasStatus> <http://example.com#Occupied> .} >>> WHERE >>> { ?person <http://example.com#hasStatus> <http://example.com#Free> .} >>> >>> Printing the resulting model (which seems empty): >>> <rdf:RDF >>> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >>> xmlns:owl="http://www.w3.org/2002/07/owl#" >>> xmlns:example="http://example.com#" >>> xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" >>> xmlns:xsd="http://www.w3.org/2001/XMLSchema#" > >>> </rdf:RDF> >>> >>> My attempt to check wether a model is empty: >>> StmtIterator nodeIterator = model.listStatements(); >>> if (nodeIterator.hasNext()) { >>> // do something >>> } >>> >>> This however doesn't work, since there are still triples returned in the >>> iterator: >>> [http://example.com#hasStatus, >>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type, >>> http://www.w3.org/2002/07/owl#ObjectProperty] >>> >>> Any thoughts are appreciated. >>> >>> Thanks, >>> >>> Maarten >