Skip to : [Content] [Navigation]
 

How can I extract all inferences?

The most straight-forward way to retrieve all the inferences from a Jena reasoner can be done with the following call:

   Iterator i = model.listStatements();

However, getting all inferences is problematic for some datasets since it requires a lot of computation. For example, for ontologies with large number of individuals getting differentFrom inferences can be computationally expensive. Similarly, for ontologies with large number of classes getting disjointWith inferences can be slow. Typically only a subset of all inferences is required for a specific application and it is not necessary to compute the reasoning results that will not be used in the application.

The org.mindswap.pellet.jena.ModelExtractor class provides a convenient way to extract a specific subset of inferences. The inference extractor can be used as follows:

   // Create an inference extractor
   ModelExtractor extractor = new ModelExtractor(model);

   // Extract default set of inferences
   Model inferences = extractor.extractModel();

The default setting extracts the following inferences: DIRECT_SUBCLASS, EQUIVALENT_CLASS, DIRECT_SUBPROPERTY, EQUIVALENT_PROPERTY, INVERSE_PROPERTY, OBJECT_PROPERTY_VALUE, DATA_PROPERTY_VALUE, DIRECT_INSTANCE. This setting is designed to be an acceptable trade-off of performance and coverage. For example, it excludes SAME_AS, DIFFERENT_FROM and DISJOINT_CLASS inferences.

The default setting can be customized to a different set of inferences. For example, extractor can be configured to only retrieve direct subclass relationships as follows:

   extractor.setSelector(
      EnumSet.of( StatementType.DIRECT_SUBCLASS ) );

If disjointness inferences between classes is also needed then:

   extractor.setSelector( 
      EnumSet.of( StatementType.DIRECT_SUBCLASS, StatementType.DISJOINT_CLASS ) );

Note that for convenience, ModelExtractor contains some constant fields that can be passed directly to setSelector, including ALL_CLASS_STATEMENTS, ALL_PROPERTY_STATEMENTS, ALL_INDIVIDUAL_STATEMENTS, and DEFAULT_STATEMENTS.

The command “extract” makes this function available from the command line. For usage information run

   pellet extract -h