removeAll()
.
- */
- static class InfBulkUpdateHandler extends SimpleBulkUpdateHandler
- {
- public InfBulkUpdateHandler( BaseInfGraph graph )
- { super(graph); }
-
- @Override
- @Deprecated
- public void remove( Node s, Node p, Node o )
- {
- BaseInfGraph g = (BaseInfGraph) graph;
- g.getRawGraph().remove( s, p, o );
- g.discardState();
- g.rebind();
- manager.notifyEvent( graph, GraphEvents.remove( s, p, o ) );
- }
-
- @Override
- @Deprecated
- public void removeAll()
- {
- BaseInfGraph g = (BaseInfGraph) graph;
- g.getRawGraph().clear();
- g.discardState();
- g.rebind();
- g.getEventManager().notifyEvent( g, GraphEvents.removeAll );
- }
- }
-
- @Override
- public void remove( Node s, Node p, Node o )
- {
- getRawGraph().remove( s, p, o );
- discardState();
- rebind();
- getEventManager().notifyEvent( this, GraphEvents.remove( s, p, o ) );
- }
-
- @Override
- public void clear()
- {
- getRawGraph().clear() ;
- discardState();
- rebind();
- getEventManager().notifyEvent( this, GraphEvents.removeAll );
- }
-
-
- @Override
- public TransactionHandler getTransactionHandler()
- { return new InfTransactionHandler( this ); }
-
- public static class InfTransactionHandler
- extends TransactionHandlerBase implements TransactionHandler
- {
- protected final BaseInfGraph base;
-
- public InfTransactionHandler( BaseInfGraph base )
- { this.base = base; }
-
- @Override
- public boolean transactionsSupported()
- { return getBaseHandler().transactionsSupported(); }
-
- protected TransactionHandler getBaseHandler()
- { return base.getRawGraph().getTransactionHandler(); }
-
- @Override
- public void begin()
- { getBaseHandler().begin(); }
-
- @Override
- public void abort()
- { getBaseHandler().abort();
- base.rebind(); }
-
- @Override
- public void commit()
- { getBaseHandler().commit(); }
- }
-
- /**
- discard any state that depends on the content of fdata, because
- it's just been majorly trashed, solid gone.
- */
- protected void discardState()
- {}
-
- /**
- * Return the raw RDF data Graph being processed (i.e. the argument
- * to the Reasonder.bind call that created this InfGraph).
- */
- @Override
- public Graph getRawGraph() {
- return fdata.getGraph();
- }
-
- /**
- * Return the Reasoner which is being used to answer queries to this graph.
- */
- @Override
- public Reasoner getReasoner() {
- return reasoner;
- }
-
- /**
- * Replace the underlying data graph for this inference graph and start any
- * inferences over again. This is primarily using in setting up ontology imports
- * processing to allow an imports multiunion graph to be inserted between the
- * inference graph and the raw data, before processing.
- * @param data the new raw data graph
- */
- @Override
- public synchronized void rebind(Graph data) {
- fdata = new FGraph(data);
- isPrepared = false;
- }
-
- /**
- * Cause the inference graph to reconsult the underlying graph to take
- * into account changes. Normally changes are made through the InfGraph's add and
- * remove calls are will be handled appropriately. However, in some cases changes
- * are made "behind the InfGraph's back" and this forces a full reconsult of
- * the changed data.
- */
- @Override
- public synchronized void rebind() {
- version++;
- isPrepared = false;
- }
-
- /**
- * Reset any internal caches. Some systems, such as the tabled backchainer,
- * retain information after each query. A reset will wipe this information preventing
- * unbounded memory use at the expense of more expensive future queries. A reset
- * does not cause the raw data to be reconsulted and so is less expensive than a rebind.
- */
- @Override
- public void reset() {
- version++;
- }
-
- /**
- * Perform any initial processing and caching. This call is optional. Most
- * engines either have negligable set up work or will perform an implicit
- * "prepare" if necessary. The call is provided for those occasions where
- * substantial preparation work is possible (e.g. running a forward chaining
- * rule system) and where an application might wish greater control over when
- * this prepration is done.
- */
- @Override
- public synchronized void prepare() {
- // Default is to do no preparation
- isPrepared = true;
- }
-
- /**
- * Returns a derivations graph. The rule reasoners typically create a
- * graph containing those triples added to the base graph due to rule firings.
- * In some applications it can useful to be able to access those deductions
- * directly, without seeing the raw data which triggered them. In particular,
- * this allows the forward rules to be used as if they were rewrite transformation
- * rules.
- * @return the deductions graph, if relevant for this class of inference
- * engine or null if not.
- */
- @Override
- public Graph getDeductionsGraph() {
- return null;
- }
-
- /**
- * Test a global boolean property of the graph. This might included
- * properties like consistency, OWLSyntacticValidity etc.
- * It remains to be seen what level of generality is needed here. We could
- * replace this by a small number of specific tests for common concepts.
- * @param property the URI of the property to be tested
- * @return a Node giving the value of the global property, this may
- * be a boolean literal, some other literal value (e.g. a size).
- */
- @Override
- public Node getGlobalProperty(Node property) {
- throw new ReasonerException("Global property not implemented: " + property);
- }
-
- /**
- * A convenience version of getGlobalProperty which can only return
- * a boolean result.
- */
- @Override
- public boolean testGlobalProperty(Node property) {
- Node resultNode = getGlobalProperty(property);
- if (resultNode.isLiteral()) {
- Object result = resultNode.getLiteralValue();
- if (result instanceof Boolean) {
- return ((Boolean)result).booleanValue();
- }
- }
- throw new ReasonerException("Global property test returned non-boolean value" +
- "\nTest was: " + property +
- "\nResult was: " + resultNode);
- }
-
- /**
- * Test the consistency of the bound data. This normally tests
- * the validity of the bound instance data against the bound
- * schema data.
- * @return a ValidityReport structure
- */
- @Override
- public ValidityReport validate() {
- checkOpen();
- return new StandardValidityReport();
- }
-
- /**
- * An extension of the Graph.find interface which allows the caller to
- * encode complex expressions in RDF and then refer to those expressions
- * within the query triple. For example, one might encode a class expression
- * and then ask if there are any instances of this class expression in the
- * InfGraph.
- * @param subject the subject Node of the query triple, may be a Node in
- * the graph or a node in the parameter micro-graph or null
- * @param property the property to be retrieved or null
- * @param object the object Node of the query triple, may be a Node in
- * the graph or a node in the parameter micro-graph.
- * @param param a small graph encoding an expression which the subject and/or
- * object nodes refer.
- */
- @Override
- public ExtendedIteratorThis code used to have the .filterKeep component uncommented. We
- * think this is because of earlier history, before .matches on a literal node
- * was implemented as sameValueAs rather than equals. If it turns out that
- * the filter is needed, it can be commented back in, AND a corresponding
- * filter added to find(Node x 3) -- and test cases, of course.
- */
- @Override
- public ExtendedIteratorprepare()
step.
- For testing purposes.
- * @return Whether the graph is prepared
- */
- public synchronized boolean isPrepared()
- { return isPrepared; }
-
- /**
- * Reset prepared state to false
- */
- protected synchronized void setPreparedState(boolean state) {
- this.isPrepared = state;
- }
-
- /**
- * Checks whether the graph is prepared and calls {@link #prepare()} if it is not
- */
- protected synchronized void requirePrepared() {
- if (!this.isPrepared) this.prepare();
- }
-}