Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To list all of the instances of an OntClass, you can use one of the aptly named <a href="http://jena.apache.org/documentation/javadoc/jena/com/hp/hpl/jena/ontology/OntClass.html#listInstances%28%29" rel="nofollow"><code>OntClass.listInstances</code></a>. It's described clearly in the javadoc. In general, I'd suggest that if you're using an API, it's good practice to skim the javadoc of the class or interface that you're working with. You don't need to memorize every bit of it, but you'll have some idea of what's available and know where to look when you need something.</p> <h3>Code Sample</h3> <pre class="lang-java prettyprint-override"><code>import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.ontology.OntResource; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.util.iterator.ExtendedIterator; public class ListInstancesExample { public static void main(String[] args) { // Load the wine ontology. final OntModel model = ModelFactory.createOntologyModel( OntModelSpec.OWL_DL_MEM ); model.read( "http://www.w3.org/TR/owl-guide/wine.rdf" ); // Get the Merlot class. final OntClass merlot = model.getOntClass( "http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#Merlot" ); // Print each of its instances. for ( final ExtendedIterator&lt;? extends OntResource&gt; merlots = merlot.listInstances(); merlots.hasNext(); ) { System.out.println( merlots.next() ); } } } </code></pre> <h3>Output</h3> <pre class="lang-none prettyprint-override"><code>http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#LongridgeMerlot http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#GaryFarrellMerlot </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload