This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit 4586238c728c99b84417bf9575d91b23b801ca6f Author: Andy Seaborne <[email protected]> AuthorDate: Fri May 30 19:55:56 2025 +0100 GH-3237: Prepare for GraphMem -> GraphMemValue; GraphMem2* -> GraphMem --- .../org/apache/jena/graph/GraphMemFactory.java | 61 +++++- .../jena/ontology/models/SimpleGraphMaker.java | 43 ++--- .../org/apache/jena/rdf/model/ModelFactory.java | 17 +- .../reasoner/rulesys/BasicForwardRuleInfGraph.java | 122 ++++++------ .../jena/reasoner/rulesys/FBRuleInfGraph.java | 208 ++++++++++----------- .../reasoner/rulesys/LPBackwardRuleInfGraph.java | 74 ++++---- .../jena/reasoner/rulesys/impl/BFRuleContext.java | 2 +- .../org/apache/jena/graph/test/GraphTestBase.java | 2 +- .../org/apache/jena/mem/test/TestCaseBasic.java | 43 ----- .../org/apache/jena/mem/test/TestCaseBugs.java | 60 ------ .../org/apache/jena/mem/test/TestGraphMem2.java | 101 ---------- ...stGraphMemValue.java => TestGraphMemModel.java} | 73 +++++++- ...Package.java => TestPackage_GraphMemValue.java} | 21 +-- .../org/apache/jena/mem/test/TestTripleBunch.java | 2 +- .../TestPackage_GraphMem2.java} | 26 ++- .../org/apache/jena/test/TestPackage_core.java | 7 +- 16 files changed, 375 insertions(+), 487 deletions(-) diff --git a/jena-core/src/main/java/org/apache/jena/graph/GraphMemFactory.java b/jena-core/src/main/java/org/apache/jena/graph/GraphMemFactory.java index c4b0abfa07..64464e3bd2 100644 --- a/jena-core/src/main/java/org/apache/jena/graph/GraphMemFactory.java +++ b/jena-core/src/main/java/org/apache/jena/graph/GraphMemFactory.java @@ -24,6 +24,7 @@ import org.apache.jena.graph.impl.GraphBase ; import org.apache.jena.mem2.GraphMem2Fast; import org.apache.jena.mem2.GraphMem2Legacy; import org.apache.jena.mem2.GraphMem2Roaring; +import org.apache.jena.sys.JenaSystem; import org.apache.jena.util.iterator.ExtendedIterator ; import org.apache.jena.util.iterator.NullIterator ; @@ -47,9 +48,12 @@ import org.apache.jena.util.iterator.NullIterator ; */ public class GraphMemFactory { + static { JenaSystem.init(); } + + private GraphMemFactory() {} // Default for sameTerm/sameValue - // Jena 4 : default false (same value) - // Jena 5 : default false (same term) + // Up to Jena 4 : default false (same value) + // From Jena 5 : default false (same term) private static boolean defaultSameTerm = true; static { // Initial setting. @@ -70,7 +74,9 @@ public class GraphMemFactory * with the system default is same value (Jena4). * <p> * This affects {@link #createDefaultGraph}. + * @deprecated To be removed. */ + @Deprecated(forRemoval = true) public static void setDftGraphSameTerm(boolean value) { defaultSameTerm = value; } @@ -80,12 +86,13 @@ public class GraphMemFactory * (false). * <p> * This is used by {@link #createDefaultGraph}. + * @deprecated To be removed. */ + @Deprecated(forRemoval = true) public static boolean dftGraphSameTerm() { return defaultSameTerm; } - private GraphMemFactory() {} /** * Answer a memory-based graph. @@ -98,9 +105,18 @@ public class GraphMemFactory } /** - * This function will track the preferred general purpose graph for the Model API. + * @deprecated To be renamed. Use {@link #createGraphMemForModel()}. The function will be re-purposed for the default samer-term memory graph. */ + @Deprecated(forRemoval = true) public static Graph createGraphMem() { + //return createGraphMemForModel(); + return createGraphMem2(); + } + + /** + * This function will track the preferred general purpose graph for the Model API. + */ + public static Graph createGraphMemForModel() { @SuppressWarnings("deprecation") Graph g = new org.apache.jena.mem.GraphMem(); return g; @@ -138,9 +154,18 @@ public class GraphMemFactory * with a simpler implementation, primarily due to not providing support for {@link Iterator#remove}. * <p> * See {@link GraphMem2Legacy} for details. + * */ - public static Graph createGraphMem2Basic() - { return new GraphMem2Legacy(); } + public static Graph createGraphMemBasic() + { return new GraphMem2Legacy(); } + + /** + * @deprecated Use {@link #createGraphMemBasic()} + */ + @Deprecated(forRemoval = true) + public static Graph createGraphMem2Basic() + { return createGraphMemBasic(); } + /** * A graph that stores triples in memory. This class is not thread-safe. @@ -154,8 +179,18 @@ public class GraphMemFactory * <p> * See {@link GraphMem2Fast} for details. */ - public static Graph createGraphMem2() - { return new GraphMem2Fast(); } + //public static Graph createGraphMemX() { + public static Graph createGraphMem2() { + return new GraphMem2Fast(); + } + +// /** +// * @deprecated Use {@link #createGraphMemBasic()} +// */ +// @Deprecated(forRemoval = true) +// public static Graph createGraphMem2() { +// return new GraphMem2Fast(); +// } /** * A graph that stores triples in memory. This class is not thread-safe. @@ -170,9 +205,17 @@ public class GraphMemFactory * <p> * See {@link GraphMem2Roaring} for details. */ - public static Graph createGraphMem2Roaring() + public static Graph createGraphMemRoaring() { return new GraphMem2Roaring(); } + + /** + * @deprecated Use {@link #createGraphMemRoaring()} + */ + @Deprecated(forRemoval = true) + public static Graph createGraphMem2Roaring() + { return createGraphMemRoaring(); } + private final static Graph emptyGraph = new GraphBase() { @Override protected ExtendedIterator<Triple> graphBaseFind(Triple triplePattern) { diff --git a/jena-core/src/main/java/org/apache/jena/ontology/models/SimpleGraphMaker.java b/jena-core/src/main/java/org/apache/jena/ontology/models/SimpleGraphMaker.java index 29dfdabb8b..537a33c6e3 100644 --- a/jena-core/src/main/java/org/apache/jena/ontology/models/SimpleGraphMaker.java +++ b/jena-core/src/main/java/org/apache/jena/ontology/models/SimpleGraphMaker.java @@ -35,17 +35,17 @@ public class SimpleGraphMaker extends BaseGraphMaker /** Initialise a SimpleGraphMaker with reification style Minimal - */ + */ public SimpleGraphMaker() { super() ; } /** The mapping from the names of graphs to the Graphs themselves. - */ + */ private Map<String, Graph> graphs = new HashMap<>(); public Graph create() - { return GraphMemFactory.createGraphMem(); } + { return GraphMemFactory.createDefaultGraph(); } /** Create a graph and record it with the given name in the local map. @@ -54,13 +54,12 @@ public class SimpleGraphMaker extends BaseGraphMaker public Graph createGraph( String name, boolean strict ) { GraphMemBase already = (GraphMemBase) graphs.get( name ); - if (already == null) - { - Graph result = GraphMemFactory.createGraphMem( ); + if (already == null) { + Graph result = GraphMemFactory.createDefaultGraph(); graphs.put( name, result ); - return result; + return result; } - else if (strict) + if (strict) throw new AlreadyExistsException( name ); else return already.openAgain(); @@ -70,28 +69,30 @@ public class SimpleGraphMaker extends BaseGraphMaker Open (aka find) a graph with the given name in the local map. */ @Override - public Graph openGraph( String name, boolean strict ) - { - GraphMemBase already = (GraphMemBase) graphs.get( name ); - if (already == null) - if (strict) throw new DoesNotExistException( name ); - else return createGraph( name, true ); + public Graph openGraph(String name, boolean strict) { + GraphMemBase already = (GraphMemBase)graphs.get(name); + if ( already == null ) + if ( strict ) + throw new DoesNotExistException(name); + else + return createGraph(name, true); else return already.openAgain(); } @Override - public Graph openGraph() - { return getGraph(); } + public Graph openGraph() { + return getGraph(); + } /** - Remove the mapping from name to any graph from the local map. + * Remove the mapping from name to any graph from the local map. */ @Override - public void removeGraph( String name ) - { - if (!graphs.containsKey( name )) throw new DoesNotExistException( name ); - graphs.remove( name ); + public void removeGraph(String name) { + if ( !graphs.containsKey(name) ) + throw new DoesNotExistException(name); + graphs.remove(name); } /** diff --git a/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java b/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java index 22652a5939..fb9880d372 100644 --- a/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java +++ b/jena-core/src/main/java/org/apache/jena/rdf/model/ModelFactory.java @@ -47,11 +47,8 @@ import org.apache.jena.sys.JenaSystem ; public class ModelFactory extends ModelFactoryBase { static { JenaSystem.init(); } - /** - No-one can make instances of this. - */ - private ModelFactory() - {} + + private ModelFactory() {} /** * Answer a fresh Model for use with the Model API. @@ -78,10 +75,9 @@ public class ModelFactory extends ModelFactoryBase return createModelForGraph(GraphMemFactory.createDefaultGraphSameValue()); } - /** - Answer a model that encapsulates the given graph. Existing prefixes are - undisturbed. + Answer a model that encapsulates the given graph. + Existing prefixes are undisturbed. @param g A graph structure @return A model presenting an API view of graph g */ @@ -95,8 +91,9 @@ public class ModelFactory extends ModelFactoryBase @return a ModelMaker that constructs memory-based models */ - public static ModelMaker createMemModelMaker() - { return new ModelMakerImpl( new SimpleGraphMaker( ) ); } + public static ModelMaker createMemModelMaker() { + return new ModelMakerImpl(new SimpleGraphMaker()); + } /** * Return a Model through which all the RDFS entailments diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java index 772e7d5109..373a5d5c65 100755 --- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java +++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java @@ -44,33 +44,33 @@ import org.apache.jena.util.iterator.NullIterator ; */ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRuleInfGraphI { - + /** Table of derivation records, maps from triple to RuleDerivation */ protected OneToManyMap<Triple, Derivation> derivations; - + /** The set of deduced triples, this is in addition to base triples in the fdata graph */ protected FGraph fdeductions; - + /** A safe wrapped version of the deductions graph used for reporting getDeductions */ protected Graph safeDeductions; - + /** Reference to any schema graph data bound into the parent reasoner */ protected Graph schemaGraph; - + /** The forward rule engine being used */ protected FRuleEngineI engine; - + /** The original rule set as supplied */ private List<Rule> rules; - + /** Flag, if true then find results will be filtered to remove functors and illegal RDF */ public boolean filterFunctors = true; - + /** Flag which, if true, enables tracing of rule actions to logger.info */ protected boolean traceOn = false; - + // private static Logger logger = LoggerFactory.getLogger(BasicForwardRuleInfGraph.class); - + //======================================================================= // Core methods @@ -80,40 +80,40 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul * any configuration parameters (such as logging) to be set before the data is added. * Note that until the data is added using {@link #rebind rebind} then any operations * like add, remove, find will result in errors. - * - * @param reasoner the parent reasoner + * + * @param reasoner the parent reasoner * @param schema the (optional) schema data which is being processed */ public BasicForwardRuleInfGraph(Reasoner reasoner, Graph schema) { super(null, reasoner); instantiateRuleEngine(null); this.schemaGraph = schema; - } + } /** - * Constructor. Creates a new inference graph based on the given rule set. + * Constructor. Creates a new inference graph based on the given rule set. * No data graph is attached at this stage. This is to allow * any configuration parameters (such as logging) to be set before the data is added. * Note that until the data is added using {@link #rebind rebind} then any operations * like add, remove, find will result in errors. - * - * @param reasoner the parent reasoner + * + * @param reasoner the parent reasoner * @param rules the list of rules to use this time * @param schema the (optional) schema or preload data which is being processed */ public BasicForwardRuleInfGraph(Reasoner reasoner, List<Rule> rules, Graph schema) - { + { super( null, reasoner ); instantiateRuleEngine( rules ); this.rules = rules; this.schemaGraph = schema; } - + /** * Constructor. Creates a new inference graph based on the given rule set * then processes the initial data graph. No precomputed deductions are loaded. - * - * @param reasoner the parent reasoner + * + * @param reasoner the parent reasoner * @param rules the list of rules to use this time * @param schema the (optional) schema or preload data which is being processed * @param data the data graph to be processed @@ -131,15 +131,15 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul protected void instantiateRuleEngine(List<Rule> rules) { engine = FRuleEngineIFactory.getInstance().createFRuleEngineI(this, rules, false); } - + /** * Attach a compiled rule set to this inference graph. - * @param ruleStore a compiled set of rules (i.e. the result of an FRuleEngine.compile). + * @param ruleStore a compiled set of rules (i.e. the result of an FRuleEngine.compile). */ public void setRuleStore(Object ruleStore) { engine.setRuleStore(ruleStore); } - + /** * Replace the underlying data graph for this inference graph and start any * inferences over again. This is primarily using in setting up ontology imports @@ -152,13 +152,13 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul fdata = new FGraph( data ); rebind(); } - + /** * 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. + * the changed data. */ @Override public void rebind() { @@ -173,7 +173,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public Graph getSchemaGraph() { return schemaGraph; } - + /** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit @@ -186,7 +186,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public synchronized void prepare() { if (this.isPrepared()) return; this.setPreparedState(true); - + // initilize the deductions graph fdeductions = new FGraph( createDeductionsGraph() ); boolean rulesLoaded = false; @@ -194,7 +194,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul rulesLoaded = preloadDeductions(schemaGraph); } if (rulesLoaded) { - engine.fastInit(fdata); + engine.fastInit(fdata); } else { engine.init(true, fdata); } @@ -222,7 +222,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul return false; } } - + /** * Add a new deduction to the deductions graph. */ @@ -230,7 +230,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public void addDeduction(Triple t) { getDeductionsGraph().add(t); } - + /** * Set to true to cause functor-valued literals to be dropped from rule output. * Default is true. @@ -239,7 +239,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public void setFunctorFiltering(boolean param) { filterFunctors = param; } - + /** * Extended find interface used in situations where the implementator * may or may not be able to answer the complete query. It will @@ -255,7 +255,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation) { return findWithContinuation(pattern, continuation, true); } - + /** * Internals of findWithContinuation implementation which allows control * over functor filtering. @@ -279,10 +279,10 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul return result; } } - - /** + + /** * Returns an iterator over Triples. - * This implementation assumes that the underlying findWithContinuation + * This implementation assumes that the underlying findWithContinuation * will have also consulted the raw data. */ @Override @@ -292,7 +292,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul /** * Basic pattern lookup interface. - * This implementation assumes that the underlying findWithContinuation + * This implementation assumes that the underlying findWithContinuation * will have also consulted the raw data. * @param pattern a TriplePattern to be matched against the data * @return a ExtendedIterator over all Triples in the data set @@ -302,7 +302,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public ExtendedIterator<Triple> find(TriplePattern pattern) { return findWithContinuation(pattern, null); } - + /** * Add one triple to the data graph, run any rules triggered by @@ -328,10 +328,10 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul int dedSize = fdeductions.getGraph().size(); return baseSize + dedSize; } - - /** - * Removes the triple t (if possible) from the set belonging to this graph. - */ + + /** + * Removes the triple t (if possible) from the set belonging to this graph. + */ @Override public void performDelete(Triple t) { version++; @@ -345,8 +345,8 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul fdeductions.getGraph().delete(t); } } - - /** + + /** * Free all resources, any further use of this Graph is an error. */ @Override @@ -363,7 +363,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul // ======================================================================= // Implementation of ForwardRuleInfGraphI interface which is used by // the forward rule engine to invoke functions in this InfGraph - + /** * Adds a new Backward rule as a rules of a forward rule process. Only some * infgraphs support this. @@ -372,7 +372,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public void addBRule(Rule brule) { throw new ReasonerException("Forward reasoner does not support hybrid rules - " + brule.toShortString()); } - + /** * Deletes a new Backward rule as a rules of a forward rule process. Only some * infgraphs support this. @@ -381,7 +381,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public void deleteBRule(Rule brule) { throw new ReasonerException("Forward reasoner does not support hybrid rules - " + brule.toShortString()); } - + /** * Return the Graph containing all the static deductions available so far. * Will force a prepare. @@ -389,15 +389,15 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul @Override public Graph getDeductionsGraph() { prepare(); - return safeDeductions; + return safeDeductions; } - - /** + + /** * Create the graph used to hold the deductions. Can be overridden * by subclasses that need special purpose graph implementations here. * Assumes the graph underlying fdeductions and associated SafeGraph * wrapper can be reused if present thus enabling preservation of - * listeners. + * listeners. */ protected Graph createDeductionsGraph() { if (fdeductions != null) { @@ -408,11 +408,11 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul return dg; } } - Graph dg = GraphMemFactory.createGraphMem( ); + Graph dg = GraphMemFactory.createDefaultGraph( ); safeDeductions = new SafeGraph( dg ); return dg; } - + /** * Return the Graph containing all the static deductions available so far. * Does not trigger a prepare action. Returns a SafeWrapper and so @@ -424,7 +424,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul return safeDeductions; // return fdeductions.getGraph(); } - + /** * Search the combination of data and deductions graphs for the given triple pattern. * This may different from the normal find operation in the base of hybrid reasoners @@ -434,7 +434,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public ExtendedIterator<Triple> findDataMatches(Node subject, Node predicate, Node object) { return findWithContinuation(new TriplePattern(subject, predicate, object), null, false); } - + /** * Log a dervivation record against the given triple. @@ -443,7 +443,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public void logDerivation(Triple t, Derivation derivation) { derivations.put(t, derivation); } - + /** * Assert a new triple in the deduction graph, bypassing any processing machinery. */ @@ -468,7 +468,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul derivations = null; } } - + /** * Return true if derivation logging is enabled. */ @@ -476,7 +476,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public boolean shouldLogDerivations() { return recordDerivations; } - + /** * Return the derivation of at triple. * The derivation is a List of DerivationRecords @@ -489,7 +489,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul return derivations.getAll(t); } } - + /** * Set the state of the trace flag. If set to true then rule firings * are logged out to the Log at "INFO" level. @@ -497,7 +497,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public void setTraceOn(boolean state) { traceOn = state; } - + /** * Return true if tracing should be acted on - i.e. if traceOn is true * and we are past the bootstrap phase. @@ -506,7 +506,7 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public boolean shouldTrace() { return traceOn && engine.shouldTrace(); } - + /** * Return the number of rules fired since this rule engine instance * was created and initialized @@ -514,5 +514,5 @@ public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRul public long getNRulesFired() { return engine.getNRulesFired(); } - + } diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleInfGraph.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleInfGraph.java index 54377e9c37..73a6c2d74f 100644 --- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleInfGraph.java +++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/FBRuleInfGraph.java @@ -51,46 +51,46 @@ import org.slf4j.LoggerFactory ; * for future reference). */ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements BackwardRuleInfGraphI { - + /** Single context for the reasoner, used when passing information to builtins */ protected BBRuleContext context; - + /** A finder that searches across the data, schema, axioms and forward deductions*/ protected Finder dataFind; - + /** The core backward rule engine which includes all the memoized results */ protected LPBRuleEngine bEngine; - + /** The original rule set as supplied */ protected List<Rule> rawRules; - + /** The rule list after possible extension by preprocessing hooks */ protected List<Rule> rules; - + /** Static switch from Basic to RETE implementation of the forward component */ public static boolean useRETE = true; /** Flag, if true then subClass and subProperty lattices will be optimized using TGCs */ protected boolean useTGCCaching = false; - + /** Optional precomputed cache of the subClass/subproperty lattices */ protected TransitiveEngine transitiveEngine; - + /** Optional list of preprocessing hooks to be run in sequence during preparation time */ protected List<RulePreprocessHook> preprocessorHooks; - + /** Cache of temporary property values inferred through getTemp calls */ protected TempNodeCache tempNodecache; - + /** Table of temp nodes which should be hidden from output listings */ protected Set<Node> hiddenNodes; /** Optional map of property node to datatype ranges */ protected HashMap<Node, List<RDFDatatype>> dtRange = null; - + /** Flag to request datatype range validation be included in the validation step */ protected boolean requestDatatypeRangeValidation = false; - + static Logger logger = LoggerFactory.getLogger(FBRuleInfGraph.class); // ======================================================================= @@ -103,7 +103,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar */ public FBRuleInfGraph(Reasoner reasoner, Graph schema) { super(reasoner, schema); - constructorInit(schema); + constructorInit(schema); } /** @@ -115,9 +115,9 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public FBRuleInfGraph(Reasoner reasoner, List<Rule> rules, Graph schema) { super( reasoner, rules, schema ); this.rawRules = rules; - constructorInit( schema ); + constructorInit( schema ); } - + /** * Constructor. * @param reasoner the reasoner which created this inf graph instance @@ -127,8 +127,8 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar */ public FBRuleInfGraph( Reasoner reasoner, List<Rule> rules, Graph schema, Graph data ) { super(reasoner, rules, schema, data); - this.rawRules = rules; - constructorInit(schema); + this.rawRules = rules; + constructorInit(schema); } @@ -136,7 +136,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar * Common pieces of initialization code which apply in all constructor cases. */ private void constructorInit(Graph schema) { - initLP(schema); + initLP(schema); tempNodecache = new TempNodeCache(this); if (JenaParameters.enableFilteringOfHiddenInfNodes) { hiddenNodes = new HashSet<>(); @@ -145,7 +145,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } } } - + /** * Instantiate the forward rule engine to use. * Subclasses can override this to switch to, say, a RETE implementation. @@ -158,7 +158,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar /** * Initialize the LP engine, based on an optional schema graph. - */ + */ private void initLP(Graph schema) { if (schema != null && schema instanceof FBRuleInfGraph) { LPRuleStore newStore = new LPRuleStore(); @@ -168,7 +168,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar bEngine = new LPBRuleEngine(this); } } - + /** * Instantiate the optional caches for the subclass/suproperty lattices. * Unless this call is made the TGC caching will not be used. @@ -177,7 +177,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar useTGCCaching = true; resetTGCCache(); } - + /** * Rest the transitive graph caches */ @@ -190,11 +190,11 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar new TransitiveGraphCache(ReasonerVocabulary.directSubPropertyOf.asNode(), RDFS.subPropertyOf.asNode())); } } - + // ======================================================================= // Interface between infGraph and the goal processing machinery - + /** * Search the combination of data and deductions graphs for the given triple pattern. * This may different from the normal find operation in the base of hybrid reasoners @@ -204,7 +204,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public ExtendedIterator<Triple> findDataMatches(Node subject, Node predicate, Node object) { return dataFind.find(new TriplePattern(subject, predicate, object)); } - + /** * Search the combination of data and deductions graphs for the given triple pattern. * This may different from the normal find operation in the base of hybrid reasoners @@ -214,7 +214,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public ExtendedIterator<Triple> findDataMatches(TriplePattern pattern) { return dataFind.find(pattern); } - + /** * Process a call to a builtin predicate * @param clause the Functor representing the call @@ -225,7 +225,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar @Override public boolean processBuiltin(ClauseEntry clause, Rule rule, BindingEnvironment env) { throw new ReasonerException("Internal error in FBLP rule engine, incorrect invocation of builtin in rule " + rule); - // TODO: Remove + // TODO: Remove // if (clause instanceof Functor) { // context.setEnv(env); // context.setRule(rule); @@ -234,7 +234,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar // throw new ReasonerException("Illegal builtin predicate: " + clause + " in rule " + rule); // } } - + /** * Adds a new Backward rule as a result of a forward rule process. Only some * infgraphs support this. @@ -247,7 +247,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar bEngine.addRule(brule); bEngine.reset(); } - + /** * Deletes a new Backward rule as a rules of a forward rule process. Only some * infgraphs support this. @@ -260,7 +260,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar bEngine.deleteRule(brule); bEngine.reset(); } - + /** * Adds a set of new Backward rules */ @@ -272,7 +272,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } bEngine.reset(); } - + /** * Return an ordered list of all registered backward rules. Includes those * generated by forward productions. @@ -280,7 +280,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public List<Rule> getBRules() { return bEngine.getAllRules(); } - + /** * Return the originally supplied set of rules, may be a mix of forward * and backward rules. @@ -288,9 +288,9 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public List<Rule> getRules() { return rules; } - + /** - * Set a predicate to be tabled/memoized by the LP engine. + * Set a predicate to be tabled/memoized by the LP engine. */ public void setTabled(Node predicate) { bEngine.tablePredicate(predicate); @@ -298,7 +298,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar logger.info("LP TABLE " + predicate); } } - + /** * Return a compiled representation of all the registered * forward rules. @@ -306,7 +306,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar private Object getForwardRuleStore() { return engine.getRuleStore(); } - + /** * Add a new deduction to the deductions graph. */ @@ -323,16 +323,16 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar * @param instance the base instance node to which the property applies * @param prop the property node whose value is being inferred * @param pclass the (optional, can be null) class for the inferred value. - * @return the bNode representing the property value + * @return the bNode representing the property value */ @Override public Node getTemp(Node instance, Node prop, Node pclass) { return tempNodecache.getTemp(instance, prop, pclass); } - + // ======================================================================= // Core inf graph methods - + /** * Add a new rule to the rule set. This should only be used by implementations * of RuleProprocessHook (which are called during rule system preparation phase). @@ -353,7 +353,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } rules.add(rule); } - + /** * Add a new preprocessing hook defining an operation that * should be run when the preparation phase is underway. @@ -364,7 +364,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } preprocessorHooks.add(hook); } - + /** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit @@ -376,16 +376,16 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar @Override public synchronized void prepare() { if (this.isPrepared()) return; - + this.setPreparedState(true); - + // Restore the original pre-hookProcess rules rules = rawRules; - + // Is there any data to bind in yet? Graph data = null; if (fdata != null) data = fdata.getGraph(); - + // initilize the deductions graph if (fdeductions != null) { Graph oldDeductions = (fdeductions).getGraph(); @@ -395,22 +395,22 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } dataFind = (data == null) ? fdeductions : FinderUtil.cascade(fdeductions, fdata); Finder dataSource = fdata; - + // Initialize the optional TGC caches if (useTGCCaching) { resetTGCCache(); if (schemaGraph != null) { - // Check if we can just reuse the copy of the raw + // Check if we can just reuse the copy of the raw if ( (transitiveEngine.checkOccurance(TransitiveReasoner.subPropertyOf, data) || transitiveEngine.checkOccurance(TransitiveReasoner.subClassOf, data) || transitiveEngine.checkOccurance(RDFS.domain.asNode(), data) || transitiveEngine.checkOccurance(RDFS.range.asNode(), data) )) { - + // The data graph contains some ontology knowledge so split the caches // now and rebuild them using merged data transitiveEngine.insert(((FBRuleInfGraph)schemaGraph).fdata, fdata); - } + } } else { if (data != null) { transitiveEngine.insert(null, fdata); @@ -437,17 +437,17 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar transitiveEngine.setCaching(true, true); // dataFind = FinderUtil.cascade(subClassCache, subPropertyCache, dataFind); dataFind = FinderUtil.cascade(dataFind, transitiveEngine.getSubClassCache(), transitiveEngine.getSubPropertyCache()); - + // Without the next statement then the transitive closures are not seen by the forward rules dataSource = FinderUtil.cascade(dataSource, transitiveEngine.getSubClassCache(), transitiveEngine.getSubPropertyCache()); } - + // Make sure there are no Brules left over from pior runs bEngine.deleteAllRules(); // Call any optional preprocessing hook if (preprocessorHooks != null && preprocessorHooks.size() > 0) { - Graph inserts = GraphMemFactory.createGraphMem(); + Graph inserts = GraphMemFactory.createDefaultGraph(); for ( RulePreprocessHook hook : preprocessorHooks ) { hook.run( this, dataFind, inserts ); @@ -458,7 +458,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar dataFind = FinderUtil.cascade(dataFind, finserts); } } - + boolean rulesLoaded = false; if (schemaGraph != null) { Graph rawPreload = ((InfGraph)schemaGraph).getRawGraph(); @@ -477,13 +477,13 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar // Prepare the context for builtins run in backwards engine context = new BBRuleContext(this); } - + /** * 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. + * the changed data. */ @Override public void rebind() { @@ -491,11 +491,11 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar if (bEngine != null) bEngine.reset(); this.setPreparedState(false); } - + /** * Cause the inference graph to reconsult both the underlying graph and * the reasoner ruleset, permits the forward rule set to be dynamically changed. - * Causes the entire rule engine to be rebuilt from the current ruleset and + * Causes the entire rule engine to be rebuilt from the current ruleset and * reinitialized against the current data. Not needed for normal cases. */ public void rebindAll() { @@ -503,7 +503,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar instantiateRuleEngine( rawRules ); rebind(); } - + /** * Set the state of the trace flag. If set to true then rule firings * are logged out to the Log at "INFO" level. @@ -528,7 +528,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar derivations = null; } } - + /** * Return the number of rules fired since this rule engine instance * was created and initialized. The current implementation only counts @@ -539,7 +539,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public long getNRulesFired() { return engine.getNRulesFired(); } - + /** * Extended find interface used in situations where the implementator * may or may not be able to answer the complete query. It will @@ -566,7 +566,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar return result; } } - + /** * Internal variant of find which omits the filters which block illegal RDF data. * @param pattern a TriplePattern to be matched against the data @@ -576,10 +576,10 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar this.requirePrepared(); return bEngine.find(pattern).filterKeep( new UniqueFilter<Triple>()); } - - /** + + /** * Returns an iterator over Triples. - * This implementation assumes that the underlying findWithContinuation + * This implementation assumes that the underlying findWithContinuation * will have also consulted the raw data. */ @Override @@ -589,7 +589,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar /** * Basic pattern lookup interface. - * This implementation assumes that the underlying findWithContinuation + * This implementation assumes that the underlying findWithContinuation * will have also consulted the raw data. * @param pattern a TriplePattern to be matched against the data * @return a ExtendedIterator over all Triples in the data set @@ -646,9 +646,9 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar bEngine.reset(); } - /** - * Removes the triple t (if possible) from the set belonging to this graph. - */ + /** + * Removes the triple t (if possible) from the set belonging to this graph. + */ @Override public void performDelete(Triple t) { version++; @@ -661,7 +661,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } this.setPreparedState(false); } - } + } // Full incremental remove processing requires reference counting // of all deductions. It's not clear the cost of maintaining the // reference counts is worth it so the current implementation @@ -674,7 +674,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } bEngine.reset(); } - + /** * Return a new inference graph which is a clone of the current graph * together with an additional set of data premises. Attempts to the replace @@ -689,36 +689,36 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar // if (useTGCCaching) graph.setUseTGCCache(); // graph.setDerivationLogging(recordDerivations); // graph.setTraceOn(traceOn); -// // Implementation note: whilst current tests pass its not clear that +// // Implementation note: whilst current tests pass its not clear that // // the nested passing of FBRuleInfGraph's will correctly handle all // // cases of indirectly bound schema data. If we do uncover a problem here // // then either include the raw schema in a Union with the premises or -// // revert of a more brute force version. +// // revert of a more brute force version. // graph.rebind(premises); // return graph; // } - - /** + + /** * Free all resources, any further use of this Graph is an error. */ @Override public void close() { if (!closed) { - bEngine.halt(); + bEngine.halt(); bEngine = null; transitiveEngine = null; super.close(); } } - + // ======================================================================= // Generalized validation machinery. Assumes rule set has special validation // rules that can be turned on. - + /** * Test the consistency of the bound data. This normally tests * the validity of the bound instance data against the bound - * schema data. + * schema data. * @return a ValidityReport structure */ @Override @@ -726,14 +726,14 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar checkOpen(); StandardValidityReport report = new StandardValidityReport(); // Switch on validation - Triple validateOn = Triple.create(NodeFactory.createBlankNode(), + Triple validateOn = Triple.create(NodeFactory.createBlankNode(), ReasonerVocabulary.RB_VALIDATION.asNode(), Functor.makeFunctorNode("on", new Node[] {})); // We sneak this switch directly into the engine to avoid contaminating the // real data - this is only possible only the forward engine has been prepared // add(validateOn); this.requirePrepared(); - engine.add(validateOn); + engine.add(validateOn); // Look for all reports TriplePattern pattern = new TriplePattern(null, ReasonerVocabulary.RB_VALIDATION_REPORT.asNode(), null); final Model forConversion = ModelFactory.createDefaultModel(); @@ -758,20 +758,20 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar } } } - + if (requestDatatypeRangeValidation) { performDatatypeRangeValidation( report ); } return report; } - + /** * Switch on/off datatype range validation */ public void setDatatypeRangeValidation(boolean on) { requestDatatypeRangeValidation = on; } - + /** * Run a datatype range check on all literal values of all properties with a range declaration. * @param report @@ -802,7 +802,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar if (range != null) { if (value.isBlank()) return null; if (!value.isLiteral()) { - return new ValidityReport.Report(true, "dtRange", + return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value); } LiteralLabel ll = value.getLiteral(); @@ -850,7 +850,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar /** * Scan the initial rule set and pick out all the backward-only rules with non-null bodies, - * and transfer these rules to the backward engine. + * and transfer these rules to the backward engine. */ private static List<Rule> extractPureBackwardRules(List<Rule> rules) { List<Rule> bRules = new ArrayList<>(); @@ -891,7 +891,7 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar return false; } } - + /** * Called to flag that a node should be hidden from external queries. */ @@ -904,10 +904,10 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar hiddenNodes.add(n); } } - + // ======================================================================= // Support for LP engine profiling - + /** * Reset the LP engine profile. * @param enable it true then profiling will continue with a new empty profile table, @@ -916,17 +916,17 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar public void resetLPProfile(boolean enable) { bEngine.resetProfile(enable); } - + /** * Print a profile of LP rules used since the last reset. */ public void printLPProfile() { bEngine.printProfile(); } - + // ======================================================================= // Implement Filter signature - + /** * Post-filter query results to hide unwanted * triples from the glare of publicity. Unwanted triples @@ -935,25 +935,25 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar */ public boolean accept(Object tin) { Triple t = (Triple)tin; - + if ((t).getSubject().isLiteral()) return true; - + if (JenaParameters.enableFilteringOfHiddenInfNodes && hiddenNodes != null) { if (hiddenNodes.contains(t.getSubject()) || hiddenNodes.contains(t.getObject()) || hiddenNodes.contains(t.getPredicate())) { return true; } } - + if (filterFunctors) { if (Functor.isFunctor(t.getObject())) { return true; } } - + return false; } - + // ======================================================================= // Inner classes @@ -961,17 +961,17 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar * Structure used to wrap up pre-processed/compiled rule sets. */ public static class RuleStore { - + /** The raw rules */ protected List<Rule> rawRules; - + /** The indexed store used by the forward chainer */ protected Object fRuleStore; - + /** The separated backward rules */ protected List<Rule> bRules; - - /** + + /** * Constructor. */ public RuleStore(List<Rule> rawRules, Object fRuleStore, List<Rule> bRules) { @@ -979,8 +979,8 @@ public class FBRuleInfGraph extends BasicForwardRuleInfGraph implements Backwar this.fRuleStore = fRuleStore; this.bRules = bRules; } - + } - - + + } diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java index 64ca0cc933..3ee42f011d 100644 --- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java +++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/LPBackwardRuleInfGraph.java @@ -39,24 +39,24 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule /** The LP rule engine controller which handles the processing for this graph */ protected LPBRuleEngine engine; - + /** Table of derivation records, maps from triple to RuleDerivation */ protected OneToManyMap<Triple, Derivation> derivations; - + /** An optional graph of separate schema assertions that should also be processed */ protected FGraph fschema; - + /** Cache of deductions made from the rules */ protected FGraph fdeductions; - + /** A finder that searches across the data, schema and axioms */ protected Finder dataFind; - + /** Cache of temporary property values inferred through getTemp calls */ protected TempNodeCache tempNodecache; - + static Logger logger = LoggerFactory.getLogger(LPBackwardRuleInfGraph.class); - + // ======================================================================= // Core methods @@ -64,8 +64,8 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule * Constructor. Create a new backward inference graph to process * the given data. The parent reasoner supplies the ruleset and * any additional schema graph. - * - * @param reasoner the parent reasoner + * + * @param reasoner the parent reasoner * @param ruleStore the indexed set of rules to use * @param data the data graph to be processed * @param schema optional precached schema (use null if not required) @@ -77,7 +77,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule } engine = new LPBRuleEngine(this, ruleStore); tempNodecache = new TempNodeCache(this); - } + } /** * Return the schema graph, if any, bound into this inference graph. @@ -86,7 +86,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule public Graph getSchemaGraph() { return fschema.getGraph(); } - + /** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit @@ -98,8 +98,8 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule @Override public synchronized void prepare() { if (this.isPrepared()) return; - - fdeductions = new FGraph( GraphMemFactory.createGraphMem() ); + + fdeductions = new FGraph( GraphMemFactory.createDefaultGraph() ); extractAxioms(); dataFind = fdata; if (fdeductions != null) { @@ -108,7 +108,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule if (fschema != null) { dataFind = FinderUtil.cascade(dataFind, fschema); } - + this.setPreparedState(true); } @@ -125,13 +125,13 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule fdata = new FGraph(data); this.setPreparedState(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. + * the changed data. */ @Override public synchronized void rebind() { @@ -171,10 +171,10 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule } return result.filterDrop(Functor.acceptFilter); } - - /** + + /** * Returns an iterator over Triples. - * This implementation assumes that the underlying findWithContinuation + * This implementation assumes that the underlying findWithContinuation * will have also consulted the raw data. */ @Override @@ -184,7 +184,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule /** * Basic pattern lookup interface. - * This implementation assumes that the underlying findWithContinuation + * This implementation assumes that the underlying findWithContinuation * will have also consulted the raw data. * @param pattern a TriplePattern to be matched against the data * @return a ExtendedIterator over all Triples in the data set @@ -194,7 +194,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule public ExtendedIterator<Triple> find(TriplePattern pattern) { return findWithContinuation(pattern, null); } - + /** * Add one triple to the data graph, run any rules triggered by * the new data item, recursively adding any generated triples. @@ -206,10 +206,10 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule fdata.getGraph().add(t); this.setPreparedState(false); } - - /** - * Removes the triple t (if possible) from the set belonging to this graph. - */ + + /** + * Removes the triple t (if possible) from the set belonging to this graph. + */ @Override public synchronized void performDelete(Triple t) { version++; @@ -217,9 +217,9 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule fdata.getGraph().delete(t); this.setPreparedState(false); } - + /** - * Set a predicate to be tabled/memoized by the LP engine. + * Set a predicate to be tabled/memoized by the LP engine. */ public void setTabled(Node predicate) { engine.tablePredicate(predicate); @@ -227,7 +227,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule logger.info("LP TABLE " + predicate); } } - + // ======================================================================= // support for proof traces @@ -243,7 +243,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule derivations = null; } } - + /** * Return the derivation of at triple. * The derivation is a List of DerivationRecords @@ -256,7 +256,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule return derivations.getAll(t); } } - + /** * Set the state of the trace flag. If set to true then rule firings * are logged out to the Log at "INFO" level. @@ -264,14 +264,14 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule public void setTraceOn(boolean state) { engine.setTraceOn(state); } - + /** * Return true if tracing is switched on */ public boolean isTraceOn() { return engine.isTraceOn(); } - + // ======================================================================= // Interface between infGraph and the goal processing machinery @@ -291,7 +291,7 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule public ExtendedIterator<Triple> findDataMatches(TriplePattern pattern) { return dataFind.find(pattern); } - + /** * Process a call to a builtin predicate * @param clause the Functor representing the call @@ -301,9 +301,9 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule */ @Override public boolean processBuiltin(ClauseEntry clause, Rule rule, BindingEnvironment env) { - throw new ReasonerException("Internal error in FBLP rule engine, incorrect invocation of building in rule " + rule); + throw new ReasonerException("Internal error in FBLP rule engine, incorrect invocation of building in rule " + rule); } - + /** * Assert a new triple in the deduction graph, bypassing any processing machinery. */ @@ -317,13 +317,13 @@ public class LPBackwardRuleInfGraph extends BaseInfGraph implements BackwardRule * @param instance the base instance node to which the property applies * @param prop the property node whose value is being inferred * @param pclass the (optional, can be null) class for the inferred value. - * @return the bNode representing the property value + * @return the bNode representing the property value */ @Override public Node getTemp(Node instance, Node prop, Node pclass) { return tempNodecache.getTemp(instance, prop, pclass); } - + // ======================================================================= // Rule engine extras diff --git a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BFRuleContext.java b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BFRuleContext.java index 047232650c..f5ca007c68 100644 --- a/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BFRuleContext.java +++ b/jena-core/src/main/java/org/apache/jena/reasoner/rulesys/impl/BFRuleContext.java @@ -66,7 +66,7 @@ public class BFRuleContext implements RuleContext { env = new BindingStack(); stack = new ArrayList<>(); pending = new ArrayList<>(); - pendingCache = GraphMemFactory.createGraphMem(); + pendingCache = GraphMemFactory.createDefaultGraph(); } /** diff --git a/jena-core/src/test/java/org/apache/jena/graph/test/GraphTestBase.java b/jena-core/src/test/java/org/apache/jena/graph/test/GraphTestBase.java index 096bf8685a..b287f9c0d1 100644 --- a/jena-core/src/test/java/org/apache/jena/graph/test/GraphTestBase.java +++ b/jena-core/src/test/java/org/apache/jena/graph/test/GraphTestBase.java @@ -173,7 +173,7 @@ public class GraphTestBase extends JenaTestBase */ public static Graph newGraph() { - Graph result = GraphMemFactory.createGraphMem(); + Graph result = GraphMemFactory.createDefaultGraphSameValue(); result.getPrefixMapping().setNsPrefixes( PrefixMapping.Extended ); return result; } diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestCaseBasic.java b/jena-core/src/test/java/org/apache/jena/mem/test/TestCaseBasic.java deleted file mode 100644 index c5b2148972..0000000000 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestCaseBasic.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.mem.test; - -import org.apache.jena.rdf.model.ModelFactory ; - -public class TestCaseBasic extends org.apache.jena.regression.TestCaseBasic { - - public TestCaseBasic(String name) { - super(name); - } - - @Override - public void setUp() { - m1 = ModelFactory.createDefaultModel(); - m2 = ModelFactory.createDefaultModel(); - m3 = ModelFactory.createDefaultModel(); - m4 = ModelFactory.createDefaultModel(); - } - @Override - public void tearDown() { - m1 = null; - m2 = null; - m3 = null; - m4 = null; - } -} diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestCaseBugs.java b/jena-core/src/test/java/org/apache/jena/mem/test/TestCaseBugs.java deleted file mode 100644 index a9fc3640c5..0000000000 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestCaseBugs.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.mem.test; - -import org.apache.jena.rdf.model.* ; - -public class TestCaseBugs - extends TestCaseBasic { - - Model model = null; - - public TestCaseBugs(String name) { - super(name); - } - - @Override public void setUp() { - model = ModelFactory.createDefaultModel(); - } - - public void bug36() { - // addLiteral deprecated, test suppressed -// Resource r = model.createResource(); -// Object oc = RDFS.Class; -// Object op = RDF.Property; -// -// Statement s = model.createLiteralStatement(r, RDF.type, oc); -// assertInstanceOf(Resource.class, s.getObject() ); -// -// //s.changeObject(op); -// s = model.createLiteralStatement(r, RDF.type, op); -// -// assertInstanceOf(Resource.class, s.getObject() ); -// -// model.addLiteral(r, RDF.type, oc); -// RDFNode n = model.listStatements() -// .nextStatement() -// .getObject(); -// assertInstanceOf(Resource.class, n ); -// -// assertTrue(model.listResourcesWithProperty(RDF.type, oc).hasNext()); -// -// assertTrue(model.containsLiteral(r, RDF.type, oc)); - } -} diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMem2.java b/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMem2.java deleted file mode 100644 index 3d943424df..0000000000 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMem2.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.jena.mem.test; - -import java.util.Iterator ; - -import junit.framework.TestSuite ; -import org.apache.jena.graph.* ; -import org.apache.jena.graph.test.AbstractTestGraph ; -import org.apache.jena.util.iterator.ExtendedIterator ; - -public class TestGraphMem2 extends AbstractTestGraph - { - public TestGraphMem2(String name) - { super( name ); } - - public static TestSuite suite() - { return new TestSuite( TestGraphMem2.class ); } - - @Override - public Graph getNewGraph() { return GraphMemFactory.createGraphMem(); } - - public void testBrokenIndexes() - { - Graph g = getGraphWith( "x R y; x S z" ); - ExtendedIterator<Triple> it = g.find( Node.ANY, Node.ANY, Node.ANY ); - it.removeNext(); it.removeNext(); - assertFalse( g.find( node( "x" ), Node.ANY, Node.ANY ).hasNext() ); - assertFalse( g.find( Node.ANY, node( "R" ), Node.ANY ).hasNext() ); - assertFalse( g.find( Node.ANY, Node.ANY, node( "y" ) ).hasNext() ); - } - - public void testBrokenSubject() - { - Graph g = getGraphWith( "x brokenSubject y" ); - ExtendedIterator<Triple> it = g.find( node( "x" ), Node.ANY, Node.ANY ); - it.removeNext(); - assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); - } - - public void testBrokenPredicate() - { - Graph g = getGraphWith( "x brokenPredicate y" ); - ExtendedIterator<Triple> it = g.find( Node.ANY, node( "brokenPredicate"), Node.ANY ); - it.removeNext(); - assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); - } - - public void testBrokenObject() - { - Graph g = getGraphWith( "x brokenObject y" ); - ExtendedIterator<Triple> it = g.find( Node.ANY, Node.ANY, node( "y" ) ); - it.removeNext(); - assertFalse( g.find( Node.ANY, Node.ANY, Node.ANY ).hasNext() ); - } - - public void testSizeAfterRemove() - { - Graph g = getGraphWith( "x p y" ); - ExtendedIterator<Triple> it = g.find( triple( "x ?? ??" ) ); - it.removeNext(); - assertEquals( 0, g.size() ); - } - - public void testUnnecessaryMatches() - { - Node special = new Node_URI( "eg:foo" ) - { - @Override - public boolean matches( Node s ) - { - fail( "Matched called superfluously." ); - return true; - } - }; - Graph g = getGraphWith( "x p y" ); - g.add( Triple.create( special, special, special ) ); - exhaust( g.find( special, Node.ANY, Node.ANY ) ); - exhaust( g.find( Node.ANY, special, Node.ANY ) ); - exhaust( g.find( Node.ANY, Node.ANY, special ) ); - } - - protected void exhaust( Iterator<?> it ) - { while (it.hasNext()) it.next(); } - } diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemValue.java b/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemModel.java similarity index 84% rename from jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemValue.java rename to jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemModel.java index 1b8f8ebd6d..75797fb17e 100644 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemValue.java +++ b/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemModel.java @@ -23,14 +23,12 @@ import static org.apache.jena.testing_framework.GraphHelper.txnCommit; import static org.apache.jena.testing_framework.GraphHelper.txnRollback; import static org.apache.jena.testing_framework.GraphHelper.txnRun; +import java.util.Iterator; import java.util.Set; import junit.framework.JUnit4TestAdapter; import org.apache.jena.atlas.iterator.Iter; -import org.apache.jena.graph.Graph; -import org.apache.jena.graph.Node; -import org.apache.jena.graph.NodeFactory; -import org.apache.jena.graph.Triple; +import org.apache.jena.graph.*; import org.apache.jena.graph.impl.LiteralLabelFactory; import org.apache.jena.graph.test.AbstractTestGraph; import org.apache.jena.mem.GraphMem ; @@ -46,19 +44,18 @@ import org.junit.Test; * Jena5+ : Only {@link GraphMem} supports this. Other graph are "same term", not "same value" * and language tags are held in canonical form. */ -public class TestGraphMemValue extends AbstractTestGraph { - public TestGraphMemValue(String name) { +public class TestGraphMemModel extends AbstractTestGraph { + public TestGraphMemModel(String name) { super(name); } public static junit.framework.Test suite() { - return new JUnit4TestAdapter(TestGraphMemValue.class); + return new JUnit4TestAdapter(TestGraphMemModel.class); } - @SuppressWarnings("deprecation") @Override public Graph getNewGraph() { - return new GraphMem(); + return GraphMemFactory.createGraphMemForModel(); } @Test public void testSizeAfterRemove() { @@ -278,4 +275,62 @@ public class TestGraphMemValue extends AbstractTestGraph { literalTypingBasedFindTest("a P '1'xsd:short", 1, "'1'xsd:integer", "'1'xsd:short", true); literalTypingBasedFindTest("a P '1'xsd:int", 1, "'1'xsd:integer", "'1'xsd:int", true); } + + @Test + public void testBrokenIndexes() { + Graph g = getGraphWith("x R y; x S z"); + ExtendedIterator<Triple> it = g.find(Node.ANY, Node.ANY, Node.ANY); + it.removeNext(); + it.removeNext(); + assertFalse(g.find(node("x"), Node.ANY, Node.ANY).hasNext()); + assertFalse(g.find(Node.ANY, node("R"), Node.ANY).hasNext()); + assertFalse(g.find(Node.ANY, Node.ANY, node("y")).hasNext()); + } + + @Test + public void testBrokenSubject() { + Graph g = getGraphWith("x brokenSubject y"); + ExtendedIterator<Triple> it = g.find(node("x"), Node.ANY, Node.ANY); + it.removeNext(); + assertFalse(g.find(Node.ANY, Node.ANY, Node.ANY).hasNext()); + } + + @Test + public void testBrokenPredicate() { + Graph g = getGraphWith("x brokenPredicate y"); + ExtendedIterator<Triple> it = g.find(Node.ANY, node("brokenPredicate"), Node.ANY); + it.removeNext(); + assertFalse(g.find(Node.ANY, Node.ANY, Node.ANY).hasNext()); + } + + @Test + public void testBrokenObject() { + Graph g = getGraphWith("x brokenObject y"); + ExtendedIterator<Triple> it = g.find(Node.ANY, Node.ANY, node("y")); + it.removeNext(); + assertFalse(g.find(Node.ANY, Node.ANY, Node.ANY).hasNext()); + } + + @Test + public void testUnnecessaryMatches() { + Node special = new Node_URI("eg:foo") { + @Override + public boolean matches(Node s) { + fail("Matched called superfluously."); + return true; + } + }; + Graph g = getGraphWith("x p y"); + g.add(Triple.create(special, special, special)); + exhaust(g.find(special, Node.ANY, Node.ANY)); + exhaust(g.find(Node.ANY, special, Node.ANY)); + exhaust(g.find(Node.ANY, Node.ANY, special)); + } + + protected void exhaust(Iterator<? > it) { + while (it.hasNext()) + it.next(); + } } + + diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestMemPackage.java b/jena-core/src/test/java/org/apache/jena/mem/test/TestPackage_GraphMemValue.java similarity index 75% rename from jena-core/src/test/java/org/apache/jena/mem/test/TestMemPackage.java rename to jena-core/src/test/java/org/apache/jena/mem/test/TestPackage_GraphMemValue.java index 3cab3cadc1..153a03d134 100644 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestMemPackage.java +++ b/jena-core/src/test/java/org/apache/jena/mem/test/TestPackage_GraphMemValue.java @@ -18,25 +18,22 @@ package org.apache.jena.mem.test; -import junit.framework.TestCase; -import junit.framework.TestSuite; -/** - TestMemPackage - */ -public class TestMemPackage extends TestCase +import junit.framework.*; + +public class TestPackage_GraphMemValue extends TestCase { - public TestMemPackage( String name ) - { super( name ); } - public static TestSuite suite() - { + { TestSuite result = new TestSuite(); + result.addTest( TestGraphMemModel.suite() ); result.addTest( TestGraphTripleStoreMem.suite() ); - result.addTest( new TestSuite( TestArrayTripleBunch.class ) ); - result.addTest( new TestSuite( TestHashedTripleBunch.class ) ); + result.addTest( TestConcurrentModificationException.suite() ); + result.addTestSuite( TestArrayTripleBunch.class ); + result.addTestSuite( TestHashedTripleBunch.class ); result.addTestSuite( TestHashedBunchMap.class ); result.addTestSuite( TestHashCommon.class ); + return result; } } diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestTripleBunch.java b/jena-core/src/test/java/org/apache/jena/mem/test/TestTripleBunch.java index 21a83635f9..92771aa0e7 100644 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestTripleBunch.java +++ b/jena-core/src/test/java/org/apache/jena/mem/test/TestTripleBunch.java @@ -30,7 +30,7 @@ import org.apache.jena.mem.* ; import org.apache.jena.util.iterator.ExtendedIterator ; /** - Test triple bunch implementations - NOT YET FINISHED + Test triple bunch implementations */ public abstract class TestTripleBunch extends GraphTestBase { diff --git a/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemPackage.java b/jena-core/src/test/java/org/apache/jena/mem2/TestPackage_GraphMem2.java similarity index 65% rename from jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemPackage.java rename to jena-core/src/test/java/org/apache/jena/mem2/TestPackage_GraphMem2.java index 768c2a4828..2a4f239f55 100644 --- a/jena-core/src/test/java/org/apache/jena/mem/test/TestGraphMemPackage.java +++ b/jena-core/src/test/java/org/apache/jena/mem2/TestPackage_GraphMem2.java @@ -16,19 +16,17 @@ * limitations under the License. */ -package org.apache.jena.mem.test; +package org.apache.jena.mem2; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; -import junit.framework.*; - -public class TestGraphMemPackage extends TestCase - { - public static TestSuite suite() - { - TestSuite result = new TestSuite(); - result.addTest( TestGraphMemValue.suite() ); - result.addTest( TestGraphMem2.suite() ); - result.addTest( TestConcurrentModificationException.suite() ); - return result; - } - } +@RunWith(Suite.class) [email protected]( { + GraphMem2LegacyTest.class, + GraphMem2FastTest.class, + GraphMem2RoaringTest.class, + GraphMem2Test.class +} ) +public class TestPackage_GraphMem2 { +} diff --git a/jena-core/src/test/java/org/apache/jena/test/TestPackage_core.java b/jena-core/src/test/java/org/apache/jena/test/TestPackage_core.java index 01dc167056..be450f9217 100644 --- a/jena-core/src/test/java/org/apache/jena/test/TestPackage_core.java +++ b/jena-core/src/test/java/org/apache/jena/test/TestPackage_core.java @@ -34,7 +34,7 @@ public class TestPackage_core extends TestCase { RDFReaderFImpl.alternative(new X_RDFReaderF()); TestSuite ts = new TestSuite() ; - ts.setName("Jena") ; + ts.setName("Jena Core") ; addTest(ts, "System setup", TestSystemSetup.suite()); addTest(ts, "IRIx", org.apache.jena.irix.TS_IRIx.suite()); @@ -42,8 +42,9 @@ public class TestPackage_core extends TestCase { addTest(ts, "Enhanced", org.apache.jena.enhanced.test.TestPackage_enh.suite()); addTest(ts, "Datatypes", org.apache.jena.datatypes.TestPackage_dt.suite()); addTest(ts, "Graph", org.apache.jena.graph.test.TestPackage_graph.suite()); - addTest(ts, "Mem", org.apache.jena.mem.test.TestMemPackage.suite() ); - addTest(ts, "Mem2", org.apache.jena.mem.test.TestGraphMemPackage.suite() ); + + addTest(ts, "Mem", org.apache.jena.mem.test.TestPackage_GraphMemValue.suite() ); + addTest(ts, "Model", org.apache.jena.rdf.model.test.TestPackage_model.suite()); addTest(ts, "StandardModels", org.apache.jena.rdf.model.test.TestStandardModels.suite() );
