Class SchemaCachingRDFSInferencer

  • All Implemented Interfaces:
    FederatedServiceResolverClient, NotifyingSail, Sail, StackableSail

    public class SchemaCachingRDFSInferencer
    extends NotifyingSailWrapper

    The SchemaCachingRDFSInferencer is an RDFS reasoner that caches all schema (TBox) statements and calculates an inference map to quickly determine inferred statements. The reasoner can also be instantiated with a predefined schema for improved performance.

    This reasoner is not a rule based reasoner and will be up to 80x faster than the ForwardChainingRDFSInferencer, as well as being more complete.

    The sail puts no limitations on isolation level for read transactions, however all write/delete/update transactions are serializable with exclusive locks. This limits write/delete/update transactions to one transaction at a time.

    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
      • DEFAULT_CONTEXT

        private static final Resource[] DEFAULT_CONTEXT
      • exclusiveWriteLock

        private final java.util.concurrent.locks.ReentrantLock exclusiveWriteLock
      • useAllRdfsRules

        boolean useAllRdfsRules
      • useInferredToCreateSchema

        protected volatile boolean useInferredToCreateSchema
      • properties

        private java.util.Collection<Resource> properties
      • types

        private java.util.Collection<Resource> types
      • subClassOfStatements

        private java.util.Collection<Statement> subClassOfStatements
      • subPropertyOfStatements

        private java.util.Collection<Statement> subPropertyOfStatements
      • rangeStatements

        private java.util.Collection<Statement> rangeStatements
      • domainStatements

        private java.util.Collection<Statement> domainStatements
      • calculatedTypes

        private java.util.Map<Resource,​java.util.Set<Resource>> calculatedTypes
      • calculatedProperties

        private java.util.Map<Resource,​java.util.Set<Resource>> calculatedProperties
      • calculatedRange

        private java.util.Map<Resource,​java.util.Set<Resource>> calculatedRange
      • calculatedDomain

        private java.util.Map<Resource,​java.util.Set<Resource>> calculatedDomain
      • sharedSchema

        private boolean sharedSchema
      • addInferredStatementsToDefaultContext

        private boolean addInferredStatementsToDefaultContext
      • unmodifiable

        private volatile boolean unmodifiable
    • Constructor Detail

      • SchemaCachingRDFSInferencer

        public SchemaCachingRDFSInferencer()
        Instantiate a new SchemaCachingRDFSInferencer
      • SchemaCachingRDFSInferencer

        public SchemaCachingRDFSInferencer​(NotifyingSail data)
        Instantiate a SchemaCachingRDFSInferencer.
        Parameters:
        data - Base sail for storing data.
      • SchemaCachingRDFSInferencer

        public SchemaCachingRDFSInferencer​(NotifyingSail data,
                                           Repository predefinedSchema)
        Instantiate a SchemaCachingRDFSInferencer with a predefined schema. The schema will be used for inference, all other schema statements added will be ignored and no schema statements can be removed. Using a predefined schema significantly improves performance.
        Parameters:
        data - Base sail for storing data.
        predefinedSchema - Repository containing the schema.
      • SchemaCachingRDFSInferencer

        public SchemaCachingRDFSInferencer​(NotifyingSail data,
                                           boolean useAllRdfsRules)
        Instantiate a SchemaCachingRDFSInferencer.
        Parameters:
        data - Base sail for storing data.
        useAllRdfsRules - Usel all RDFS rules. If set to false rule rdf4a and rdfs4b will be ignore
      • SchemaCachingRDFSInferencer

        public SchemaCachingRDFSInferencer​(NotifyingSail data,
                                           Repository predefinedSchema,
                                           boolean useAllRdfsRules)
        Instantiate a SchemaCachingRDFSInferencer with a predefined schema. The schema will be used for inference, all other schema statements added will be ignored and no schema statements can be removed. Using a predefined schema significantly improves performance.
        Parameters:
        data - Base sail for storing data.
        predefinedSchema - Repository containing the schema.
        useAllRdfsRules - Usel all RDFS rules. If set to false rule rdf4a and rdfs4b will be ignore
    • Method Detail

      • clearInferenceTables

        void clearInferenceTables()
      • acquireExclusiveWriteLock

        void acquireExclusiveWriteLock()
        Tries to obtain an exclusive write lock on this store. This method will block until either the lock is obtained or an interrupt signal is received.
        Throws:
        SailException - if the thread is interrupted while waiting to obtain the lock.
      • releaseExclusiveWriteLock

        void releaseExclusiveWriteLock()
        Releases the exclusive write lock.
      • init

        public void init()
                  throws SailException
        Description copied from interface: Sail
        Initializes the Sail. Care should be taken that required initialization parameters have been set before this method is called. Please consult the specific Sail implementation for information about the relevant parameters.
        Specified by:
        init in interface Sail
        Overrides:
        init in class SailWrapper
        Throws:
        SailException - If the Sail could not be initialized.
      • getValueFactory

        public ValueFactory getValueFactory()
        Description copied from interface: Sail
        Gets a ValueFactory object that can be used to create IRI-, blank node-, literal- and statement objects.
        Specified by:
        getValueFactory in interface Sail
        Overrides:
        getValueFactory in class SailWrapper
        Returns:
        a ValueFactory object for this Sail object.
      • fastInstantiateFrom

        public static SchemaCachingRDFSInferencer fastInstantiateFrom​(SchemaCachingRDFSInferencer sailToInstantiateFrom,
                                                                      NotifyingSail store)
        Instantiate a new SchemaCachingRDFSInferencer from an existing one. Fast instantiation extracts the schema lookup tables generated by the existing sail and uses them to populate the lookup tables of a new reasoner. Schema triples can not be queried in the SchemaCachingRDFSInferencer returned by this method.
        Parameters:
        sailToInstantiateFrom - The SchemaCachingRDFSInferencer to extract the lookup tables from.
        store - Base sail for storing data.
        Returns:
        inferencer
      • fastInstantiateFrom

        public static SchemaCachingRDFSInferencer fastInstantiateFrom​(SchemaCachingRDFSInferencer sailToInstantiateFrom,
                                                                      NotifyingSail store,
                                                                      boolean useAllRdfsRules)
        Instantiate a new SchemaCachingRDFSInferencer from an existing one. Fast instantiation extracts the schema lookup tables generated by the existing sail and uses them to populate the lookup tables of a new reasoner. Schema triples can not be queried in the SchemaCachingRDFSInferencer returned by this method.
        Parameters:
        sailToInstantiateFrom - The SchemaCachingRDFSInferencer to extract the lookup tables from.
        store - Base sail for storing data.
        useAllRdfsRules - Use all RDFS rules. If set to false rule rdf4a and rdfs4b will be ignore
        Returns:
        inferencer
      • makeUnmodifiable

        private void makeUnmodifiable()
      • addSubClassOfStatement

        void addSubClassOfStatement​(Statement st)
      • addSubPropertyOfStatement

        void addSubPropertyOfStatement​(Statement st)
      • addRangeStatement

        void addRangeStatement​(Statement st)
      • addDomainStatement

        void addDomainStatement​(Statement st)
      • hasType

        boolean hasType​(Resource r)
      • hasProperty

        boolean hasProperty​(Resource property)
      • addProperty

        void addProperty​(Resource property)
      • resolveProperties

        java.util.Set<Resource> resolveProperties​(Resource predicate)
      • resolveRangeTypes

        java.util.Set<Resource> resolveRangeTypes​(IRI predicate)
      • resolveDomainTypes

        java.util.Set<Resource> resolveDomainTypes​(IRI predicate)
      • calculateSubClassOf

        private void calculateSubClassOf​(java.util.Collection<Statement> subClassOfStatements)
      • getStream

        private java.util.stream.Stream<java.util.Map.Entry<Resource,​java.util.Set<Resource>>> getStream​(java.util.Map<Resource,​java.util.Set<Resource>> map)
      • calculateSubPropertyOf

        private void calculateSubPropertyOf​(java.util.Collection<Statement> subPropertyOfStatemenets)
      • addAll

        private void addAll​(java.util.Set<Resource> res,
                            java.util.List<java.util.Set<Resource>> from)
      • calculateDomainAndRange

        private void calculateDomainAndRange​(java.util.Collection<Statement> rangeOrDomainStatements,
                                             java.util.Map<Resource,​java.util.Set<Resource>> calculatedRangeOrDomain)
      • isAddInferredStatementsToDefaultContext

        public boolean isAddInferredStatementsToDefaultContext()

        Inferred statements can either be added to the default context or to the context that the original inserted statement has.

      • setAddInferredStatementsToDefaultContext

        public void setAddInferredStatementsToDefaultContext​(boolean addInferredStatementsToDefaultContext)

        Inferred statements can either be added to the default context or to the context that the original inserted statement has. setAddInferredStatementsToDefaultContext(true) will add all inferred statements to the default context.

        Which context a tbox statement is added to is undefined.

        Before 3.0 default value for addInferredStatementsToDefaultContext was true. From 3.0 the default value is false.

        Parameters:
        addInferredStatementsToDefaultContext -
      • usesPredefinedSchema

        boolean usesPredefinedSchema()