You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/12/02 18:47:09 UTC
svn commit: r1416206 [3/5] - in /jena/branches/jena-core-simplified/src:
main/java/com/hp/hpl/jena/assembler/assemblers/
main/java/com/hp/hpl/jena/graph/ main/java/com/hp/hpl/jena/graph/compose/
main/java/com/hp/hpl/jena/graph/impl/ main/java/com/hp/hp...
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java Sun Dec 2 17:46:51 2012
@@ -96,18 +96,18 @@ public class ReifiedStatementImpl extend
@return the associated triple if any, otherwise null
*/
private Triple getTriple( EnhGraph eg, Node n )
- { return eg.asGraph().getReifier().getTriple( n ); }
+ { return ReifierStd.getTriple(eg.asGraph(), n ); }
};
- /**
- Answer our Reifier (ie our Model's Graph's Reifier).
- */
- protected Reifier getReifier()
- { return getModel().getGraph().getReifier(); }
+// /**
+// Answer our Reifier (ie our Model's Graph's Reifier).
+// */
+// protected Reifier getReifier()
+// { return getModel().getGraph().getReifier(); }
@Override
public boolean isValid()
- { return getModel().getGraph().getReifier().getTriple( this.asNode() ) != null; }
+ { return ReifierStd.getTriple(getModel().getGraph(), this.asNode() ) != null; }
/**
tell the underlying graph's reifier that this ReifiedStatement's node
@@ -116,7 +116,7 @@ public class ReifiedStatementImpl extend
*/
private ReifiedStatementImpl installInReifier()
{
- getReifier().reifyAs( this.asNode(), statement.asTriple() );
+ ReifierStd.reifyAs(getModel().getGraph(), this.asNode(), statement.asTriple() );
return this;
}
@@ -143,7 +143,7 @@ public class ReifiedStatementImpl extend
public static ReifiedStatement createExistingReifiedStatement( ModelCom model, Node n )
{
- Triple t = model.getGraph().getReifier().getTriple( n );
+ Triple t = ReifierStd.getTriple(model.getGraph(), n );
return new ReifiedStatementImpl( model, n, model.asStatement( t ) );
}
}
Added: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifierStd.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifierStd.java?rev=1416206&view=auto
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifierStd.java (added)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifierStd.java Sun Dec 2 17:46:51 2012
@@ -0,0 +1,276 @@
+/*
+ * 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 com.hp.hpl.jena.rdf.model.impl;
+
+
+import java.util.* ;
+
+import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.shared.AlreadyReifiedException ;
+import com.hp.hpl.jena.shared.CannotReifyException ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
+import com.hp.hpl.jena.util.iterator.Filter ;
+import com.hp.hpl.jena.util.iterator.NullIterator ;
+import com.hp.hpl.jena.util.iterator.WrappedIterator ;
+import com.hp.hpl.jena.vocabulary.RDF ;
+
+/** A Reifier that only supports one style Standard (intercept, no conceal
+ * -- and intercept is a no-op anyway because all triples
+ * appear in the underlying graph for storing all triples).
+ * This exists to give reification style "Standard" semantics primarly for legacy reasons.
+ */
+
+public class ReifierStd
+{
+ private ReifierStd() {}
+
+ private final static Node rdfType = RDF.Nodes.type ;
+ private final static Node statement = RDF.Nodes.Statement ;
+ private final static Node subject = RDF.Nodes.subject ;
+ private final static Node predicate = RDF.Nodes.predicate ;
+ private final static Node object = RDF.Nodes.object ;
+
+ // All the methods of the old Reifier interface, converted to statics.
+
+ /**
+ Answer an iterator over the reification triples of this Reifier, or an empty
+ iterator - if showHidden is false, only the exposed triples, otherwise only
+ the concealed ones.
+ */
+
+ public static ExtendedIterator<Triple> findEither(Graph graph, TripleMatch match, boolean showHidden)
+ {
+ if ( showHidden )
+ return NullIterator.instance() ;
+ else
+ return graph.find(match) ;
+ }
+
+ static Filter<Triple> filterReif = new Filter<Triple>() {
+ @Override
+ public boolean accept(Triple triple)
+ {
+ return triple.getPredicate().equals(subject) ||
+ triple.getPredicate().equals(predicate) ||
+ triple.getPredicate().equals(object) ||
+ ( triple.getPredicate().equals(rdfType) && triple.getObject().equals(statement) ) ;
+ }} ;
+
+ /**
+ Answer an iterator over all the reification triples that this Reifier exposes
+ (ie all if Standard, none otherwise) that match m.
+ */
+ public static ExtendedIterator<Triple> findExposed(Graph graph, TripleMatch match)
+ {
+ ExtendedIterator<Triple> it = graph.find(match) ;
+ it = it.filterKeep(filterReif) ;
+ return WrappedIterator.create(it) ;
+ }
+
+ /**
+ * Answer the triple associated with the node <code>n</code>.
+ *
+ * @param n
+ * the node to use as the key
+ * @return the associated triple, or <code>null</code> if none
+ */
+
+ public static Triple getTriple(Graph graph, Node n)
+ {
+ // Must have rdf:type rdf:Statement
+ if ( ! graph.contains(n, rdfType, statement) )
+ return null ;
+ Node s = getObject(graph, n, subject) ;
+ if ( s == null ) return null ;
+ Node p = getObject(graph, n, predicate) ;
+ if ( p == null ) return null ;
+ Node o = getObject(graph, n, object) ;
+ if ( o == null ) return null ;
+ return new Triple(s,p,o) ;
+ }
+
+ // Get one and only one object
+ private static Node getObject(Graph graph, Node n, Node predicate)
+ {
+ ExtendedIterator<Triple> iter = graph.find(n, predicate, Node.ANY) ;
+ try {
+ if ( ! iter.hasNext() )
+ // None.
+ return null ;
+ Triple t = iter.next() ;
+ if ( iter.hasNext() )
+ // Too many.
+ return null ;
+ return t.getObject() ;
+ } finally { iter.close() ; }
+ }
+
+ /**
+ @return true iff there's > 0 mappings to this triple
+ */
+ public static boolean hasTriple(Graph graph, Triple t)
+ {
+ ExtendedIterator<Node> iter = findNodesForTriple(graph, t, false) ;
+ try {
+ return iter.hasNext() ;
+ } finally { iter.close() ; }
+ }
+
+ /**
+ true iff _n_ is associated with some triple.
+ */
+ public static boolean hasTriple(Graph graph, Node node)
+ {
+ return getTriple(graph, node) != null ;
+ }
+
+ /**
+ * return an iterator over all the nodes that are reifiying something in the
+ * graph
+ */
+ public static ExtendedIterator<Node> allNodes(Graph graph)
+ {
+ return allNodes(graph, null) ;
+ }
+
+ /**
+ * return an iterator over all the nodes that are reifiying t in the graph
+ */
+ public static ExtendedIterator<Node> allNodes(Graph graph, Triple t)
+ {
+ return findNodesForTriple(graph, t, false) ;
+ }
+
+ private static ExtendedIterator<Node> findNodesForTriple(Graph graph, Triple t, boolean oneWillDo)
+ {
+ ExtendedIterator<Triple> iter = graph.find(Node.ANY, rdfType, statement) ;
+ List<Node> nodes = new ArrayList<Node>() ;
+ try
+ {
+ while (iter.hasNext())
+ {
+ Triple typeTriple = iter.next() ;
+ Node n = typeTriple.getSubject() ;
+
+ // Check.
+ if ( t != null )
+ {
+ if ( ! exactlyOne(graph, n, subject, t.getSubject()) )
+ continue ;
+ if ( ! exactlyOne(graph, n, predicate, t.getPredicate()) )
+ continue ;
+ if ( ! exactlyOne(graph, n, object, t.getObject()) )
+ continue ;
+ }
+ nodes.add(n) ;
+ if ( oneWillDo )
+ break ;
+ }
+ } finally { iter.close() ; }
+ return WrappedIterator.createNoRemove(nodes.iterator()) ;
+ }
+ // ----
+
+ // check whether there is exactly the triple expected, and no others with same S and P but different O.
+ private static boolean exactlyOne(Graph graph, Node n, Node predicate, Node object)
+ {
+ ExtendedIterator<Triple> iter = graph.find(n, predicate, Node.ANY) ;
+ try {
+ if ( ! iter.hasNext() )
+ return false ;
+
+ while (iter.hasNext())
+ {
+ Node obj = iter.next().getObject() ;
+ if ( ! obj.equals(object) )
+ return false ;
+ }
+ return true ;
+ } finally { iter.close() ; }
+ }
+
+ /**
+ * note the triple _t_ as reified using _n_ as its representing node. If _n_
+ * is already reifying something, a AlreadyReifiedException is thrown.
+ */
+
+ public static Node reifyAs(Graph graph, Node node, Triple triple)
+ {
+ if ( node == null )
+ node = Node.createAnon() ;
+ else
+ {
+ Triple t = getTriple(graph, node) ;
+
+ if ( t != null && ! t.equals(triple) )
+ throw new AlreadyReifiedException(node) ;
+ if ( t != null )
+ // Already there
+ return node ;
+
+ // Check it's a well-formed reification by Jena's uniqueness rules
+ // No fragments (we checked for exact match by getTriple(node))
+ if ( graph.contains(node, subject, Node.ANY) )
+ throw new CannotReifyException(node) ;
+ if ( graph.contains(node, predicate, Node.ANY) )
+ throw new CannotReifyException(node) ;
+ if ( graph.contains(node, object, Node.ANY) )
+ throw new CannotReifyException(node) ;
+ }
+
+ graph.add(new Triple(node, rdfType, statement)) ;
+ graph.add(new Triple(node, subject, triple.getSubject())) ;
+ graph.add(new Triple(node, predicate, triple.getPredicate())) ;
+ graph.add(new Triple(node, object, triple.getObject())) ;
+
+ return node ;
+ }
+ /**
+ remove all bindings which map to this triple.
+ */
+ public static void remove(Graph graph, Triple triple)
+ {
+ // Materialize the nodes to delete - avoid ConcurrentModificationException.
+ for ( Node n : allNodes(graph, triple).toList() )
+ remove(graph, n, triple) ;
+ }
+
+ /**
+ * remove any existing binding for _n_; hasNode(n) will return false and
+ * getTriple(n) will return null. This only removes *unique, single*
+ * bindings.
+ */
+ public static void remove(Graph graph, Node node, Triple triple)
+ {
+ Set<Triple> triples = new HashSet<Triple>();
+ triplesToZap(graph, triples, node, rdfType, statement) ;
+ triplesToZap(graph, triples, node, subject, triple.getSubject()) ;
+ triplesToZap(graph, triples, node, predicate, triple.getPredicate()) ;
+ triplesToZap(graph, triples, node, object, triple.getObject()) ;
+ for ( Triple t : triples )
+ graph.delete(t) ;
+ }
+
+ private static void triplesToZap(Graph graph, Collection<Triple> acc, Node s, Node p , Node o)
+ {
+ ExtendedIterator<Triple> iter = graph.find(s,p,o) ;
+ while(iter.hasNext())
+ acc.add(iter.next()) ;
+ }
+}
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java Sun Dec 2 17:46:51 2012
@@ -27,9 +27,6 @@ import java.util.Iterator;
/**
* A base level implementation of the InfGraph interface.
- *
- * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
- * @version $Revision: 1.1 $ on $Date: 2009-06-29 08:55:50 $
*/
public abstract class BaseInfGraph extends GraphBase implements InfGraph {
@@ -57,28 +54,13 @@ public abstract class BaseInfGraph exten
{ return getRawGraph().getPrefixMapping(); }
/**
- Inference graphs share the reifiers of their underlying raw graphs. This may
- be too simplistic - they won't see quads flying past.
- TODO write a test case that reveals this.
- @see com.hp.hpl.jena.graph.Graph#getReifier()
- */
- @Override
- public Reifier constructReifier()
- { return getRawGraph().getReifier(); }
-
- /**
* Constructor
* @param data the raw data file to be augmented with entailments
* @param reasoner the engine, with associated tbox data, whose find interface
* can be used to extract all entailments from the data.
*/
public BaseInfGraph(Graph data, Reasoner reasoner) {
- this( data, reasoner, ReificationStyle.Minimal ); // should pick style from data? TODO
- }
-
- public BaseInfGraph( Graph data, Reasoner reasoner, ReificationStyle style )
- {
- super( style );
+ super( );
this.fdata = new FGraph( data );
this.reasoner = reasoner;
}
@@ -100,8 +82,6 @@ public abstract class BaseInfGraph exten
triples may be irremovable.
TODO accomodate the properties of the base graph, too.
-
- @author hedgehog
*/
public static class InfCapabilities extends AllCapabilities
{
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java Sun Dec 2 17:46:51 2012
@@ -18,18 +18,23 @@
package com.hp.hpl.jena.reasoner.rulesys;
-import com.hp.hpl.jena.reasoner.*;
-import com.hp.hpl.jena.reasoner.rulesys.impl.*;
-import com.hp.hpl.jena.shared.ReificationStyle;
-import com.hp.hpl.jena.graph.*;
+import java.util.Iterator ;
+import java.util.List ;
-import java.util.*;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
-import com.hp.hpl.jena.util.OneToManyMap;
-import com.hp.hpl.jena.util.iterator.*;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.hp.hpl.jena.graph.Factory ;
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.reasoner.* ;
+import com.hp.hpl.jena.reasoner.rulesys.impl.FRuleEngine ;
+import com.hp.hpl.jena.reasoner.rulesys.impl.FRuleEngineI ;
+import com.hp.hpl.jena.reasoner.rulesys.impl.SafeGraph ;
+import com.hp.hpl.jena.util.OneToManyMap ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
+import com.hp.hpl.jena.util.iterator.NullIterator ;
/**
* An inference graph interface that runs a set of forward chaining
@@ -39,14 +44,9 @@ import org.slf4j.LoggerFactory;
* This implementation has a horribly inefficient rule chainer built in.
* Once we have this working generalize this to an interface than
* can call out to a rule engine and build a real rule engine (e.g. Rete style). </p>
- *
- * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
- * @version $Revision: 1.4 $ on $Date: 2009-10-06 07:59:55 $
*/
-public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRuleInfGraphI {
-//=======================================================================
-// variables
+public class BasicForwardRuleInfGraph extends BaseInfGraph implements ForwardRuleInfGraphI {
/** Table of derivation records, maps from triple to RuleDerivation */
protected OneToManyMap<Triple, Derivation> derivations;
@@ -104,17 +104,13 @@ public class BasicForwardRuleInfGraph ex
* @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) {
- this( reasoner, rules, schema, ReificationStyle.Minimal );
- }
-
- public BasicForwardRuleInfGraph( Reasoner reasoner, List<Rule> rules, Graph schema, ReificationStyle style )
- {
- super( null, reasoner, style );
+ 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
@@ -421,7 +417,7 @@ public class BasicForwardRuleInfGraph ex
return dg;
}
}
- Graph dg = Factory.createGraphMem( style );
+ Graph dg = Factory.createGraphMem( );
safeDeductions = new SafeGraph( dg );
return dg;
}
@@ -528,15 +524,4 @@ public class BasicForwardRuleInfGraph ex
return engine.getNRulesFired();
}
- @Override
- public Reifier constructReifier()
- {
- BasicFBReifier.GetReifier deductionsReifier = new BasicFBReifier.GetReifier()
- {
- @Override
- public Reifier getReifier() { return getDeductionsGraph().getReifier(); }
- };
- return new BasicFBReifier( this, getRawGraph().getReifier(), deductionsReifier, style );
- }
-
}
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java Sun Dec 2 17:46:51 2012
@@ -18,29 +18,35 @@
package com.hp.hpl.jena.reasoner.rulesys;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.reasoner.rulesys.impl.*;
-import com.hp.hpl.jena.reasoner.transitiveReasoner.*;
-import com.hp.hpl.jena.reasoner.*;
-import com.hp.hpl.jena.shared.ReificationStyle;
-import com.hp.hpl.jena.shared.impl.JenaParameters;
-import com.hp.hpl.jena.datatypes.RDFDatatype;
-import com.hp.hpl.jena.datatypes.TypeMapper;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.impl.LiteralLabel;
+import java.util.* ;
-import java.util.*;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+import com.hp.hpl.jena.datatypes.RDFDatatype ;
+import com.hp.hpl.jena.datatypes.TypeMapper ;
+import com.hp.hpl.jena.graph.Factory ;
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.graph.impl.LiteralLabel ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.RDFNode ;
+import com.hp.hpl.jena.reasoner.* ;
+import com.hp.hpl.jena.reasoner.rulesys.impl.* ;
+import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveEngine ;
+import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveGraphCache ;
+import com.hp.hpl.jena.reasoner.transitiveReasoner.TransitiveReasoner ;
+import com.hp.hpl.jena.shared.impl.JenaParameters ;
+import com.hp.hpl.jena.util.OneToManyMap ;
+import com.hp.hpl.jena.util.PrintUtil ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
+import com.hp.hpl.jena.util.iterator.Filter ;
+import com.hp.hpl.jena.util.iterator.UniqueExtendedIterator ;
+import com.hp.hpl.jena.vocabulary.RDFS ;
+import com.hp.hpl.jena.vocabulary.ReasonerVocabulary ;
//import com.hp.hpl.jena.util.PrintUtil;
-import com.hp.hpl.jena.util.OneToManyMap;
-import com.hp.hpl.jena.util.PrintUtil;
-import com.hp.hpl.jena.util.iterator.*;
-import com.hp.hpl.jena.vocabulary.*;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* An inference graph that uses a mixture of forward and backward
@@ -116,11 +122,7 @@ public class FBRuleInfGraph extends Bas
* @param schema the (optional) schema graph to be included
*/
public FBRuleInfGraph(Reasoner reasoner, List<Rule> rules, Graph schema) {
- this( reasoner, rules, schema, ReificationStyle.Minimal );
- }
-
- public FBRuleInfGraph( Reasoner reasoner, List<Rule> rules, Graph schema, ReificationStyle style ) {
- super( reasoner, rules, schema, style );
+ super( reasoner, rules, schema );
this.rawRules = rules;
constructorInit( schema );
}
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java Sun Dec 2 17:46:51 2012
@@ -231,9 +231,8 @@ public class FBRuleReasoner implements R
*/
@Override
public InfGraph bind( Graph data ) throws ReasonerException {
- ReificationStyle style = data.getReifier().getStyle();
Graph schemaArg = schemaGraph == null ? getPreload() : (FBRuleInfGraph) schemaGraph;
- FBRuleInfGraph graph = new FBRuleInfGraph( this, rules, schemaArg, style );
+ FBRuleInfGraph graph = new FBRuleInfGraph( this, rules, schemaArg );
graph.setDerivationLogging( recordDerivations );
graph.setTraceOn( traceOn );
graph.rebind( data );
Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/shared/ReificationStyle.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/shared/ReificationStyle.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/shared/ReificationStyle.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/shared/ReificationStyle.java Sun Dec 2 17:46:51 2012
@@ -27,7 +27,9 @@ package com.hp.hpl.jena.shared;
public class ReificationStyle
{
public static final ReificationStyle Standard = new ReificationStyle( true, false );
+ @Deprecated
public static final ReificationStyle Convenient = new ReificationStyle( true, true );
+ @Deprecated
public static final ReificationStyle Minimal = new ReificationStyle( false, true );
private boolean intercept;
Copied: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java (from r1415851, jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java)
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java?p2=jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java&p1=jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java&r1=1415851&r2=1416206&rev=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/AssemblerTestBase.java Sun Dec 2 17:46:51 2012
@@ -32,10 +32,8 @@ import com.hp.hpl.jena.vocabulary.*;
may be over-ridden in subclasses to control the parser that is used to
construct models and the prefixes added to the model (these features
added for Eyeball).
-
- @author kers
*/
-public abstract class AssemblerTestBase extends ModelTestBase
+public class AssemblerTestBase extends ModelTestBase
{
protected Class<? extends Assembler> getAssemblerClass()
{ throw new BrokenException( "this class must define getAssemblerClass" ); }
@@ -89,7 +87,7 @@ public abstract class AssemblerTestBase
protected Model model( String string )
{
- Model result = createModel( ReificationStyle.Standard );
+ Model result = createModel( );
setRequiredPrefixes( result );
return modelAddFacts( result, string );
}
Modified: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestFileModelAssembler.java Sun Dec 2 17:46:51 2012
@@ -27,7 +27,7 @@ import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.shared.*;
import com.hp.hpl.jena.util.FileUtils;
-public class TestFileModelAssembler extends ModelAssemblerTestBase
+public class TestFileModelAssembler extends AssemblerTestBase
{
public TestFileModelAssembler( String name )
@@ -57,11 +57,10 @@ public class TestFileModelAssembler exte
{
FileModelAssembler a = new FileModelAssembler();
File x = FileUtils.tempFileName( "fileModelAssembler", ".n3" );
- Model m = a.createFileModel( x, "N3", true, false, ReificationStyle.Convenient );
+ Model m = a.createFileModel( x, "N3", true, false);
assertInstanceOf( FileGraph.class, m.getGraph() );
FileGraph fg = (FileGraph) m.getGraph();
assertEquals( x, fg.name );
- assertSame( ReificationStyle.Convenient, fg.getReifier().getStyle() );
}
public void testFileModelAssemblerUsesSpecialisedMethod()
@@ -70,7 +69,7 @@ public class TestFileModelAssembler exte
FileModelAssembler a = new FileModelAssembler()
{
@Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle style )
+ public Model createFileModel( File fullName, String lang, boolean create, boolean strict)
{ return model; }
};
Resource root = resourceInModel( "x rdf:type ja:FileModel; x ja:modelName 'junk'; x ja:directory file:" );
@@ -85,7 +84,7 @@ public class TestFileModelAssembler exte
FileModelAssembler a = new FileModelAssembler()
{
@Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle style )
+ public Model createFileModel( File fullName, String lang, boolean create, boolean strict)
{
assertEquals( "LANG", lang );
return model;
@@ -109,7 +108,7 @@ public class TestFileModelAssembler exte
FileModelAssembler a = new FileModelAssembler()
{
@Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle style )
+ public Model createFileModel( File fullName, String lang, boolean create, boolean strict)
{ return model; }
};
try
@@ -121,30 +120,6 @@ public class TestFileModelAssembler exte
assertEquals( rdfNode( m, lang ), e.getObject() ); }
}
- public void testFileModelAssemblerUsesStyle()
- {
- testUsesStyle( "ja:minimal", ReificationStyle.Minimal );
- testUsesStyle( "ja:standard", ReificationStyle.Standard );
- testUsesStyle( "ja:convenient", ReificationStyle.Convenient );
- }
-
- private void testUsesStyle( String styleString, final ReificationStyle style )
- {
- final Model model = ModelFactory.createDefaultModel();
- FileModelAssembler a = new FileModelAssembler()
- {
- @Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle s )
- {
- assertSame( style, s );
- return model;
- }
- };
- Resource root = resourceInModel( "x rdf:type ja:FileModel; x ja:modelName 'junk'; x ja:directory file:" + "; x ja:reificationMode " + styleString );
- Model m = a.openModel( root );
- assertSame( model, m );
- }
-
public void testStrictAndCreateCanBeSetFromProperties()
{
NoteAssemblerBooleans a = new NoteAssemblerBooleans();
@@ -169,7 +144,7 @@ public class TestFileModelAssembler exte
{ this.model = model(); }
@Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle s )
+ public Model createFileModel( File fullName, String lang, boolean create, boolean strict )
{
this.create = create;
this.strict = strict;
@@ -194,7 +169,7 @@ public class TestFileModelAssembler exte
FileModelAssembler a = new FileModelAssembler()
{
@Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle s )
+ public Model createFileModel( File fullName, String lang, boolean create, boolean strict)
{
if (mayCreate && mayReuse)
{
@@ -249,10 +224,9 @@ public class TestFileModelAssembler exte
FileModelAssembler a = new FileModelAssembler()
{
@Override
- public Model createFileModel( File fullName, String lang, boolean create, boolean strict, ReificationStyle style )
+ public Model createFileModel( File fullName, String lang, boolean create, boolean strict)
{
assertEquals( wantedFullName, fullName );
- assertEquals( wantedStyle, style );
assertEquals( wantedCreate, create );
assertEquals( wantedStrict, strict );
return model;
Modified: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestMemoryModelAssembler.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestMemoryModelAssembler.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestMemoryModelAssembler.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestMemoryModelAssembler.java Sun Dec 2 17:46:51 2012
@@ -24,7 +24,7 @@ import com.hp.hpl.jena.assembler.assembl
import com.hp.hpl.jena.mem.GraphMemBase;
import com.hp.hpl.jena.rdf.model.*;
-public class TestMemoryModelAssembler extends ModelAssemblerTestBase
+public class TestMemoryModelAssembler extends AssemblerTestBase
{
public TestMemoryModelAssembler( String name )
{ super( name ); }
@@ -42,9 +42,4 @@ public class TestMemoryModelAssembler ex
assertInstanceOf( Model.class, m );
assertInstanceOf( GraphMemBase.class, m.getGraph() );
}
-
- public void testCreatesWithStyle()
- {
- testCreatesWithStyle( new MemoryModelAssembler(), "x rdf:type ja:MemoryModel" );
- }
}
Modified: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestModelAssembler.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestModelAssembler.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestModelAssembler.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/assembler/test/TestModelAssembler.java Sun Dec 2 17:46:51 2012
@@ -87,6 +87,7 @@ public class TestModelAssembler extends
assertEquals( listOfOne( ReificationStyle.Standard ), style );
}
+ @SuppressWarnings("deprecation")
public void testGetsExplicitReificationMode()
{
testGetsStyle( "ja:minimal", ReificationStyle.Minimal );
Modified: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/compose/test/TestMultiUnionReifier.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/compose/test/TestMultiUnionReifier.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/compose/test/TestMultiUnionReifier.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/compose/test/TestMultiUnionReifier.java Sun Dec 2 17:46:51 2012
@@ -18,12 +18,15 @@
package com.hp.hpl.jena.graph.compose.test;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.compose.MultiUnion;
-import com.hp.hpl.jena.graph.test.NodeCreateUtils;
-import com.hp.hpl.jena.rdf.model.test.ModelTestBase;
-import com.hp.hpl.jena.shared.ReificationStyle;
-import com.hp.hpl.jena.util.iterator.ExtendedIterator;
+import com.hp.hpl.jena.graph.Factory ;
+import com.hp.hpl.jena.graph.Graph ;
+import com.hp.hpl.jena.graph.GraphUtil ;
+import com.hp.hpl.jena.graph.Triple ;
+import com.hp.hpl.jena.graph.compose.MultiUnion ;
+import com.hp.hpl.jena.graph.test.NodeCreateUtils ;
+import com.hp.hpl.jena.rdf.model.impl.ReifierStd ;
+import com.hp.hpl.jena.rdf.model.test.ModelTestBase ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
/**
Test the reifier for multi-unions.
@@ -54,7 +57,7 @@ public class TestMultiUnionReifier exten
private Graph graph( String facts )
{
- Graph result = Factory.createDefaultGraph( ReificationStyle.Standard );
+ Graph result = Factory.createDefaultGraph( );
String [] factArray = facts.split( ";" );
for (int i = 0; i < factArray.length; i += 1)
{
@@ -65,12 +68,12 @@ public class TestMultiUnionReifier exten
{
Triple t = NodeCreateUtils.createTriple( fact.substring( 1 ) );
result.add( t );
- result.getReifier().reifyAs( NodeCreateUtils.create( "_r" + ++count ), t );
+ ReifierStd.reifyAs(result, NodeCreateUtils.create( "_r" + ++count ), t );
}
else if (fact.charAt( 0 ) == '~')
{
Triple t = NodeCreateUtils.createTriple( fact.substring( 1 ) );
- result.getReifier().reifyAs( NodeCreateUtils.create( "_r" + ++count ), t );
+ ReifierStd.reifyAs( result, NodeCreateUtils.create( "_r" + ++count ), t );
}
else
result.add( NodeCreateUtils.createTriple( fact ) );
Modified: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java?rev=1416206&r1=1416205&r2=1416206&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/graph/test/AbstractTestGraph.java Sun Dec 2 17:46:51 2012
@@ -18,67 +18,69 @@
package com.hp.hpl.jena.graph.test;
-import com.hp.hpl.jena.util.CollectionFactory;
-import com.hp.hpl.jena.util.iterator.*;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.query.*;
-import com.hp.hpl.jena.mem.TrackingTripleIterator;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.ModelFactory;
-import com.hp.hpl.jena.shared.*;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.util.*;
+import java.io.FileInputStream ;
+import java.io.FileNotFoundException ;
+import java.util.* ;
+
+import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.mem.TrackingTripleIterator ;
+import com.hp.hpl.jena.rdf.model.Model ;
+import com.hp.hpl.jena.rdf.model.ModelFactory ;
+import com.hp.hpl.jena.rdf.model.impl.ReifierStd ;
+import com.hp.hpl.jena.shared.Command ;
+import com.hp.hpl.jena.shared.JenaException ;
+import com.hp.hpl.jena.util.CollectionFactory ;
+import com.hp.hpl.jena.util.iterator.ClosableIterator ;
+import com.hp.hpl.jena.util.iterator.ExtendedIterator ;
/**
AbstractTestGraph provides a bunch of basic tests for something that
purports to be a Graph. The abstract method getGraph must be overridden
in subclasses to deliver a Graph of interest.
-*/
-public/* abstract */class AbstractTestGraph extends GraphTestBase
- {
+ */
+public abstract class AbstractTestGraph extends GraphTestBase
+{
public AbstractTestGraph( String name )
- { super( name ); }
-
+ { super( name ); }
+
/**
Returns a Graph to take part in the test. Must be overridden in
a subclass.
- */
- // public abstract Graph getGraph();
-
- public Graph getGraph() { return Factory.createGraphMem(); }
-
+ */
+ public abstract Graph getGraph();
+
+ //public Graph getGraph() { return Factory.createGraphMem(); }
+
public Graph getGraphWith( String facts )
- {
+ {
Graph g = getGraph();
graphAdd( g, facts );
return g;
- }
-
+ }
+
public void testCloseSetsIsClosed()
- {
+ {
Graph g = getGraph();
assertFalse( "unclosed Graph shouild not be isClosed()", g.isClosed() );
g.close();
assertTrue( "closed Graph should be isClosed()", g.isClosed() );
- }
-
+ }
+
/**
This test case was generated by Ian and was caused by GraphMem
not keeping up with changes to the find interface.
- */
+ */
public void testFindAndContains()
- {
+ {
Graph g = getGraph();
Node r = NodeCreateUtils.create( "r" ), s = NodeCreateUtils.create( "s" ), p = NodeCreateUtils.create( "P" );
g.add( Triple.create( r, p, s ) );
assertTrue( g.contains( r, p, Node.ANY ) );
assertEquals( 1, g.find( r, p, Node.ANY ).toList().size() );
- }
-
+ }
+
public void testRepeatedSubjectDoesNotConceal()
- {
+ {
Graph g = getGraphWith( "s P o; s Q r" );
assertTrue( g.contains( triple( "s P o" ) ) );
assertTrue( g.contains( triple( "s Q r" ) ) );
@@ -86,33 +88,33 @@ public/* abstract */class AbstractTestGr
assertTrue( g.contains( triple( "?? Q r" ) ) );
assertTrue( g.contains( triple( "?? P ??" ) ) );
assertTrue( g.contains( triple( "?? Q ??" ) ) );
- }
-
+ }
+
public void testFindByFluidTriple()
- {
+ {
Graph g = getGraphWith( "x y z " );
Set<Triple> expect = tripleSet( "x y z" );
assertEquals( expect, g.find( triple( "?? y z" ) ).toSet() );
assertEquals( expect, g.find( triple( "x ?? z" ) ).toSet() );
assertEquals( expect, g.find( triple( "x y ??" ) ).toSet() );
- }
-
+ }
+
public void testContainsConcrete()
- {
+ {
Graph g = getGraphWith( "s P o; _x _R _y; x S 0" );
assertTrue( g.contains( triple( "s P o" ) ) );
assertTrue( g.contains( triple( "_x _R _y" ) ) );
assertTrue( g.contains( triple( "x S 0" ) ) );
- /* */
+ /* */
assertFalse( g.contains( triple( "s P Oh" ) ) );
assertFalse( g.contains( triple( "S P O" ) ) );
assertFalse( g.contains( triple( "s p o" ) ) );
assertFalse( g.contains( triple( "_x _r _y" ) ) );
assertFalse( g.contains( triple( "x S 1" ) ) );
- }
-
+ }
+
public void testContainsFluid()
- {
+ {
Graph g = getGraphWith( "x R y; a P b" );
assertTrue( g.contains( triple( "?? R y" ) ) );
assertTrue( g.contains( triple( "x ?? y" ) ) );
@@ -121,88 +123,83 @@ public/* abstract */class AbstractTestGr
assertTrue( g.contains( triple( "a ?? b" ) ) );
assertTrue( g.contains( triple( "a P ??" ) ) );
assertTrue( g.contains( triple( "?? R y" ) ) );
- /* */
+ /* */
assertFalse( g.contains( triple( "?? R b" ) ) );
assertFalse( g.contains( triple( "a ?? y" ) ) );
assertFalse( g.contains( triple( "x P ??" ) ) );
assertFalse( g.contains( triple( "?? R x" ) ) );
assertFalse( g.contains( triple( "x ?? R" ) ) );
assertFalse( g.contains( triple( "a S ??" ) ) );
- }
-
+ }
+
/**
Check that contains respects by-value semantics.
- */
+ */
public void testContainsByValue()
- {
+ {
if (getGraph().getCapabilities().handlesLiteralTyping())
- { // TODO fix the adhocness of this
+ {
Graph g1 = getGraphWith( "x P '1'xsd:integer" );
assertTrue( g1.contains( triple( "x P '01'xsd:int" ) ) );
- //
+ //
Graph g2 = getGraphWith( "x P '1'xsd:int" );
assertTrue( g2.contains( triple( "x P '1'xsd:integer" ) ) );
- //
+ //
Graph g3 = getGraphWith( "x P '123'xsd:string" );
assertTrue( g3.contains( triple( "x P '123'" ) ) );
- }
}
-
+ }
+
public void testMatchLanguagedLiteralCaseInsensitive()
- {
+ {
Graph m = graphWith( "a p 'chat'en" );
-
- // TODO: should be Graph m = getGraphWith( "a p 'chat'en" );
if (m.getCapabilities().handlesLiteralTyping())
- {
+ {
Node chaten = node( "'chat'en" ), chatEN = node( "'chat'EN" );
assertDiffer( chaten, chatEN );
assertTrue( chaten.sameValueAs( chatEN ) );
assertEquals( chaten.getIndexingValue(), chatEN.getIndexingValue() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chaten ).toList().size() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chatEN ).toList().size() );
- }
}
-
+ }
+
public void testMatchBothLanguagedLiteralsCaseInsensitive()
- {
+ {
Graph m = graphWith( "a p 'chat'en; a p 'chat'EN" );
-
- // TODO: should be Graph m = getGraphWith( "a p 'chat'en; a p 'chat'EN" );
if (m.getCapabilities().handlesLiteralTyping())
- {
+ {
Node chaten = node( "'chat'en" ), chatEN = node( "'chat'EN" );
assertDiffer( chaten, chatEN );
assertTrue( chaten.sameValueAs( chatEN ) );
assertEquals( chaten.getIndexingValue(), chatEN.getIndexingValue() );
assertEquals( 2, m.find( Node.ANY, Node.ANY, chaten ).toList().size() );
assertEquals( 2, m.find( Node.ANY, Node.ANY, chatEN ).toList().size() );
- }
}
-
+ }
+
public void testNoMatchAgainstUnlanguagesLiteral()
- {
+ {
Graph m = graphWith( "a p 'chat'en; a p 'chat'" );
- // TODO: should be Graph m = getGraphWith( "a p 'chat'en; a p 'chat'" );
if (m.getCapabilities().handlesLiteralTyping())
- {
+ {
Node chaten = node( "'chat'en" ), chatEN = node( "'chat'EN" );
assertDiffer( chaten, chatEN );
assertTrue( chaten.sameValueAs( chatEN ) );
assertEquals( chaten.getIndexingValue(), chatEN.getIndexingValue() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chaten ).toList().size() );
assertEquals( 1, m.find( Node.ANY, Node.ANY, chatEN ).toList().size() );
- }
}
-
+ }
+
/**
test isEmpty - moved from the QueryHandler code.
- */
+ */
public void testIsEmpty()
- {
+ {
Graph g = getGraph();
if (canBeEmpty( g ))
- {
+ {
assertTrue( g.isEmpty() );
g.add( NodeCreateUtils.createTriple( "S P O" ) );
assertFalse( g.isEmpty() );
@@ -214,17 +211,17 @@ public/* abstract */class AbstractTestGr
assertFalse( g.isEmpty() );
g.delete( NodeCreateUtils.createTriple( "A B C" ) );
assertTrue( g.isEmpty() );
- }
}
-
+ }
+
public void testAGraph()
- {
+ {
String title = this.getClass().getName();
Graph g = getGraph();
int baseSize = g.size();
graphAdd( g, "x R y; p S q; a T b" );
- /* */
+ /* */
assertContainsAll( title + ": simple graph", g, "x R y; p S q; a T b" );
assertEquals( title + ": size", baseSize + 3, g.size() );
graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" );
@@ -234,160 +231,139 @@ public/* abstract */class AbstractTestGr
assertEquals( title + ": size after deleting", baseSize + 3, g.size() );
assertContainsAll( title + ": modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" );
assertOmitsAll( title + ": modified simple graph", g, "x R y; a T b" );
- /* */
+ /* */
ClosableIterator<Triple> it = g.find( Node.ANY, node("lift"), Node.ANY );
assertTrue( title + ": finds some triple(s)", it.hasNext() );
assertEquals( title + ": finds a 'lift' triple", triple("spindizzies lift cities"), it.next() );
assertFalse( title + ": finds exactly one triple", it.hasNext() );
it.close();
- }
+ }
+
+ // public void testStuff()
+ // {
+ //// testAGraph( "StoreMem", new GraphMem() );
+ //// testAGraph( "StoreMemBySubject", new GraphMem() );
+ //// String [] empty = new String [] {};
+ //// Graph g = graphWith( "x R y; p S q; a T b" );
+ //// /* */
+ //// assertContainsAll( "simple graph", g, "x R y; p S q; a T b" );
+ //// graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" );
+ //// g.delete( triple( "x R y" ) );
+ //// g.delete( triple( "a T b" ) );
+ //// assertContainsAll( "modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" );
+ //// assertOmitsAll( "modified simple graph", g, "x R y; a T b" );
+ // }
-// public void testStuff()
-// {
-//// testAGraph( "StoreMem", new GraphMem() );
-//// testAGraph( "StoreMemBySubject", new GraphMem() );
-//// String [] empty = new String [] {};
-//// Graph g = graphWith( "x R y; p S q; a T b" );
-//// /* */
-//// assertContainsAll( "simple graph", g, "x R y; p S q; a T b" );
-//// graphAdd( g, "spindizzies lift cities; Diracs communicate instantaneously" );
-//// g.delete( triple( "x R y" ) );
-//// g.delete( triple( "a T b" ) );
-//// assertContainsAll( "modified simple graph", g, "p S q; spindizzies lift cities; Diracs communicate instantaneously" );
-//// assertOmitsAll( "modified simple graph", g, "x R y; a T b" );
-// }
-
/**
Test that Graphs have transaction support methods, and that if they fail
on some g they fail because they do not support the operation.
- */
+ */
public void testHasTransactions()
- {
+ {
Graph g = getGraph();
TransactionHandler th = g.getTransactionHandler();
th.transactionsSupported();
try { th.begin(); } catch (UnsupportedOperationException x) {}
try { th.abort(); } catch (UnsupportedOperationException x) {}
try { th.begin(); th.commit(); } catch (UnsupportedOperationException x) {}
- /* */
+ /* */
Command cmd = new Command()
- { @Override
+ { @Override
public Object execute() { return null; } };
- try { th.executeInTransaction( cmd ); }
- catch (UnsupportedOperationException x) {}
- }
-
+ try { th.executeInTransaction( cmd ); }
+ catch (UnsupportedOperationException x) {}
+ }
+
public void testExecuteInTransactionCatchesThrowable()
- {Graph g = getGraph();
- TransactionHandler th = g.getTransactionHandler();
- if (th.transactionsSupported())
- {
- Command cmd = new Command()
- { @Override
- public Object execute() throws Error { throw new Error(); } };
+ {Graph g = getGraph();
+ TransactionHandler th = g.getTransactionHandler();
+ if (th.transactionsSupported())
+ {
+ Command cmd = new Command()
+ { @Override
+ public Object execute() throws Error { throw new Error(); } };
try { th.executeInTransaction( cmd ); }
catch (JenaException x) {}
- }
- }
+ }
+ }
static final Triple [] tripleArray = tripleArray( "S P O; A R B; X Q Y" );
static final List<Triple> tripleList = Arrays.asList( tripleArray( "i lt j; p equals q" ) );
-
+
static final Triple [] setTriples = tripleArray
( "scissors cut paper; paper wraps stone; stone breaks scissors" );
-
+
static final Set<Triple> tripleSet = CollectionFactory.createHashedSet( Arrays.asList( setTriples ) );
-
+
public void testBulkUpdate()
- {
+ {
Graph g = getGraph();
Graph items = graphWith( "pigs might fly; dead can dance" );
int initialSize = g.size();
- /* */
+ /* */
GraphUtil.add( g, tripleArray );
testContains( g, tripleArray );
testOmits( g, tripleList );
- /* */
+ /* */
GraphUtil.add( g, tripleList );
testContains( g, tripleList );
testContains( g, tripleArray );
- /* */
+ /* */
GraphUtil.add( g, tripleSet.iterator() );
testContains( g, tripleSet.iterator() );
testContains( g, tripleList );
testContains( g, tripleArray );
- /* */
+ /* */
GraphUtil.addInto( g, items );
testContains( g, items );
testContains( g, tripleSet.iterator() );
testContains( g, tripleArray );
testContains( g, tripleList );
- /* */
+ /* */
GraphUtil.delete( g, tripleArray );
testOmits( g, tripleArray );
testContains( g, tripleList );
testContains( g, tripleSet.iterator() );
testContains( g, items );
- /* */
+ /* */
GraphUtil.delete( g, tripleSet.iterator() );
testOmits( g, tripleSet.iterator() );
testOmits( g, tripleArray );
testContains( g, tripleList );
testContains( g, items );
- /* */
+ /* */
GraphUtil.deleteFrom( g, items );
testOmits( g, tripleSet.iterator() );
testOmits( g, tripleArray );
testContains( g, tripleList );
testOmits( g, items );
- /* */
+ /* */
GraphUtil.delete( g, tripleList );
assertEquals( "graph has original size", initialSize, g.size() );
- }
-
- public void testBulkAddWithReification()
- {
- testBulkAddWithReification( false );
- testBulkAddWithReification( true );
- }
-
- public void testBulkAddWithReificationPreamble()
- {
+ }
+
+ public void testAddWithReificationPreamble()
+ {
Graph g = getGraph();
- xSPO( g.getReifier() );
- assertFalse( getReificationTriples( g.getReifier() ).isEmpty() );
- }
-
- public void testBulkAddWithReification( boolean withReifications )
- {
- Graph graphToUpdate = getGraph();
- Graph graphToAdd = graphWith( "pigs might fly; dead can dance" );
- Reifier updatedReifier = graphToUpdate.getReifier();
- Reifier addedReifier = graphToAdd.getReifier();
- xSPOyXYZ( addedReifier );
- GraphUtil.addInto( graphToUpdate, graphToAdd, withReifications );
- assertIsomorphic
- (
- withReifications ? getReificationTriples( addedReifier ) : graphWith( "" ),
- getReificationTriples( updatedReifier )
- );
- }
-
- protected void xSPOyXYZ( Reifier r )
- {
- xSPO( r );
- r.reifyAs( NodeCreateUtils.create( "y" ), NodeCreateUtils.createTriple( "X Y Z" ) );
- }
+ xSPO( g );
+ assertFalse( g.isEmpty() );
+ }
+
+ protected void xSPOyXYZ( Graph g)
+ {
+ xSPO( g );
+ ReifierStd.reifyAs( g, NodeCreateUtils.create( "y" ), NodeCreateUtils.createTriple( "X Y Z" ) );
+ }
+
+ protected void aABC( Graph g )
+ { ReifierStd.reifyAs( g , NodeCreateUtils.create( "a" ), NodeCreateUtils.createTriple( "A B C" ) ); }
+
+ protected void xSPO( Graph g )
+ { ReifierStd.reifyAs( g , NodeCreateUtils.create( "x" ), NodeCreateUtils.createTriple( "S P O" ) ); }
- protected void aABC( Reifier r )
- { r.reifyAs( NodeCreateUtils.create( "a" ), NodeCreateUtils.createTriple( "A B C" ) ); }
-
- protected void xSPO( Reifier r )
- { r.reifyAs( NodeCreateUtils.create( "x" ), NodeCreateUtils.createTriple( "S P O" ) ); }
-
public void testRemove()
- {
+ {
testRemove( "?? ?? ??", "?? ?? ??" );
testRemove( "S ?? ??", "S ?? ??" );
testRemove( "S ?? ??", "?? P ??" );
@@ -398,53 +374,27 @@ public/* abstract */class AbstractTestGr
testRemove( "?? ?? O", "S ?? ??" );
testRemove( "?? ?? O", "?? P ??" );
testRemove( "?? ?? O", "?? ?? O" );
- }
-
+ }
+
public void testRemove( String findRemove, String findCheck )
- {
+ {
Graph g = getGraphWith( "S P O" );
ExtendedIterator<Triple> it = g.find( NodeCreateUtils.createTriple( findRemove ) );
try
- {
+ {
it.next(); it.remove(); it.close();
assertEquals( "remove with " + findRemove + ":", 0, g.size() );
assertFalse( g.contains( NodeCreateUtils.createTriple( findCheck ) ) );
- }
+ }
catch (UnsupportedOperationException e) {
it.close();
assertFalse( g.getCapabilities().iteratorRemoveAllowed() );
}
it.close();
- }
-
- public void testBulkRemoveWithReification()
- {
- testBulkUpdateRemoveWithReification( true );
- testBulkUpdateRemoveWithReification( false );
- }
-
- public void testBulkUpdateRemoveWithReification( boolean withReifications )
- {
- Graph g = getGraph();
- Graph items = graphWith( "pigs might fly; dead can dance" );
- Reifier gr = g.getReifier(), ir = items.getReifier();
- xSPOyXYZ( ir );
- xSPO( gr ); aABC( gr );
- GraphUtil.deleteFrom( g, items, withReifications );
- Graph answer = graphWith( "" );
- Reifier ar = answer.getReifier();
- if (withReifications)
- aABC( ar );
- else
- {
- xSPO( ar );
- aABC( ar );
- }
- assertIsomorphic( getReificationTriples( ar ), getReificationTriples( gr ) );
- }
-
+ }
+
public void testHasCapabilities()
- {
+ {
Graph g = getGraph();
Capabilities c = g.getCapabilities();
boolean sa = c.sizeAccurate();
@@ -453,137 +403,137 @@ public/* abstract */class AbstractTestGr
boolean daSome = c.deleteAllowed();
boolean daAll = c.deleteAllowed( true );
boolean cbe = c.canBeEmpty();
- }
-
+ }
+
public void testFind()
- {
+ {
Graph g = getGraph();
graphAdd( g, "S P O" );
assertDiffer( new HashSet<Triple>(), g.find( Node.ANY, Node.ANY, Node.ANY ).toSet() );
assertDiffer( new HashSet<Triple>(), g.find( Triple.ANY ).toSet() );
- }
+ }
protected boolean canBeEmpty( Graph g )
- { return g.isEmpty(); }
-
+ { return g.isEmpty(); }
+
public void testEventRegister()
- {
+ {
Graph g = getGraph();
GraphEventManager gem = g.getEventManager();
assertSame( gem, gem.register( new RecordingListener() ) );
- }
-
+ }
+
/**
Test that we can safely unregister a listener that isn't registered.
- */
+ */
public void testEventUnregister()
- {
+ {
getGraph().getEventManager().unregister( L );
- }
-
+ }
+
/**
Handy triple for test purposes.
- */
+ */
protected Triple SPO = NodeCreateUtils.createTriple( "S P O" );
protected RecordingListener L = new RecordingListener();
-
+
/**
Utility: get a graph, register L with its manager, return the graph.
- */
+ */
protected Graph getAndRegister( GraphListener gl )
- {
+ {
Graph g = getGraph();
g.getEventManager().register( gl );
return g;
- }
-
+ }
+
public void testAddTriple()
- {
+ {
Graph g = getAndRegister( L );
g.add( SPO );
L.assertHas( new Object[] {"add", g, SPO} );
- }
-
+ }
+
public void testDeleteTriple()
- {
+ {
Graph g = getAndRegister( L );
g.delete( SPO );
L.assertHas( new Object[] { "delete", g, SPO} );
- }
-
+ }
+
public void testListSubjects()
- {
+ {
Set<Node> emptySubjects = listSubjects( getGraphWith( "" ) );
Graph g = getGraphWith( "x P y; y Q z" );
assertEquals( nodeSet( "x y" ), remove( listSubjects( g ), emptySubjects ) );
g.delete( triple( "x P y" ) );
assertEquals( nodeSet( "y" ), remove( listSubjects( g ), emptySubjects ) );
- }
+ }
protected Set<Node> listSubjects( Graph g )
- {
- return g.queryHandler().subjectsFor( Node.ANY, Node.ANY ).toSet();
- }
-
+ {
+ return GraphUtil.listSubjects( g, Node.ANY, Node.ANY ).toSet();
+ }
+
public void testListPredicates()
- {
+ {
Set<Node> emptyPredicates = listPredicates( getGraphWith( "" ) );
Graph g = getGraphWith( "x P y; y Q z" );
assertEquals( nodeSet( "P Q" ), remove( listPredicates( g ), emptyPredicates ) );
g.delete( triple( "x P y" ) );
assertEquals( nodeSet( "Q" ), remove( listPredicates( g ), emptyPredicates ) );
- }
+ }
protected Set<Node> listPredicates( Graph g )
- {
- return g.queryHandler().predicatesFor( Node.ANY, Node.ANY ).toSet();
- }
-
+ {
+ return GraphUtil.listPredicates( g, Node.ANY, Node.ANY ).toSet();
+ }
+
public void testListObjects()
- {
+ {
Set<Node> emptyObjects = listObjects( getGraphWith( "" ) );
Graph g = getGraphWith( "x P y; y Q z" );
assertEquals( nodeSet( "y z" ), remove( listObjects( g ), emptyObjects ) );
g.delete( triple( "x P y" ) );
assertEquals( nodeSet( "z" ), remove( listObjects( g ), emptyObjects ) );
- }
+ }
protected Set<Node> listObjects( Graph g )
- {
- return g.queryHandler().objectsFor( Node.ANY, Node.ANY ).toSet();
- }
+ {
+ return GraphUtil.listObjects( g, Node.ANY, Node.ANY ).toSet();
+ }
/**
Answer a set with all the elements of <code>A</code> except those
in <code>B</code>.
- */
+ */
private <T> Set<T> remove( Set<T> A, Set<T> B )
- {
+ {
Set<T> result = new HashSet<T>( A );
result.removeAll( B );
return result;
- }
-
+ }
+
/**
Ensure that triples removed by calling .remove() on the iterator returned by
a find() will generate deletion notifications.
- */
+ */
public void testEventDeleteByFind()
- {
+ {
Graph g = getAndRegister( L );
if (g.getCapabilities().iteratorRemoveAllowed())
- {
+ {
Triple toRemove = triple( "remove this triple" );
g.add( toRemove );
ExtendedIterator<Triple> rtr = g.find( toRemove );
assertTrue( "ensure a(t least) one triple", rtr.hasNext() );
rtr.next(); rtr.remove(); rtr.close();
L.assertHas( new Object[] { "add", g, toRemove, "delete", g, toRemove} );
- }
}
-
+ }
+
public void testTwoListeners()
- {
+ {
RecordingListener L1 = new RecordingListener();
RecordingListener L2 = new RecordingListener();
Graph g = getGraph();
@@ -592,124 +542,124 @@ public/* abstract */class AbstractTestGr
g.add( SPO );
L2.assertHas( new Object[] {"add", g, SPO} );
L1.assertHas( new Object[] {"add", g, SPO} );
- }
-
+ }
+
public void testUnregisterWorks()
- {
+ {
Graph g = getGraph();
GraphEventManager gem = g.getEventManager();
gem.register( L ).unregister( L );
g.add( SPO );
L.assertHas( new Object[] {} );
- }
-
+ }
+
public void testRegisterTwice()
- {
+ {
Graph g = getAndRegister( L );
g.getEventManager().register( L );
g.add( SPO );
L.assertHas( new Object[] {"add", g, SPO, "add", g, SPO} );
- }
-
+ }
+
public void testUnregisterOnce()
- {
+ {
Graph g = getAndRegister( L );
g.getEventManager().register( L ).unregister( L );
g.delete( SPO );
L.assertHas( new Object[] {"delete", g, SPO} );
- }
-
+ }
+
public void testBulkAddArrayEvent()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "x R y; a P b" );
GraphUtil.add(g, triples );
L.assertHas( new Object[] {"add[]", g, triples} );
- }
-
+ }
+
public void testBulkAddList()
- {
+ {
Graph g = getAndRegister( L );
List<Triple> elems = Arrays.asList( tripleArray( "bells ring loudly; pigs might fly" ) );
GraphUtil.add(g, elems) ;
L.assertHas( new Object[] {"addList", g, elems} );
- }
-
+ }
+
public void testBulkDeleteArray()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "x R y; a P b" );
GraphUtil.delete( g, triples );
L.assertHas( new Object[] {"delete[]", g, triples} );
- }
-
+ }
+
public void testBulkDeleteList()
- {
+ {
Graph g = getAndRegister( L );
List<Triple> elems = Arrays.asList( tripleArray( "bells ring loudly; pigs might fly" ) );
GraphUtil.delete( g, elems );
L.assertHas( new Object[] {"deleteList", g, elems} );
- }
-
+ }
+
public void testBulkAddIterator()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "I wrote this; you read that; I wrote this" );
GraphUtil.add(g, asIterator( triples ) );
L.assertHas( new Object[] {"addIterator", g, Arrays.asList( triples )} );
- }
-
+ }
+
public void testBulkDeleteIterator()
- {
+ {
Graph g = getAndRegister( L );
Triple [] triples = tripleArray( "I wrote this; you read that; I wrote this" );
GraphUtil.delete( g, asIterator( triples ) );
L.assertHas( new Object[] {"deleteIterator", g, Arrays.asList( triples )} );
- }
-
+ }
+
public Iterator<Triple> asIterator( Triple [] triples )
- { return Arrays.asList( triples ).iterator(); }
-
+ { return Arrays.asList( triples ).iterator(); }
+
public void testBulkAddGraph()
- {
+ {
Graph g = getAndRegister( L );
Graph triples = graphWith( "this type graph; I type slowly" );
GraphUtil.addInto( g, triples );
L.assertHas( new Object[] {"addGraph", g, triples} );
- }
-
+ }
+
public void testBulkDeleteGraph()
- {
+ {
Graph g = getAndRegister( L );
Graph triples = graphWith( "this type graph; I type slowly" );
GraphUtil.deleteFrom( g, triples );
L.assertHas( new Object[] {"deleteGraph", g, triples} );
- }
-
+ }
+
public void testGeneralEvent()
- {
+ {
Graph g = getAndRegister( L );
Object value = new int[]{};
g.getEventManager().notifyEvent( g, value );
L.assertHas( new Object[] { "someEvent", g, value } );
- }
-
+ }
+
public void testRemoveAllEvent()
- {
+ {
Graph g = getAndRegister( L );
g.removeAll();
L.assertHas( new Object[] { "someEvent", g, GraphEvents.removeAll } );
- }
-
+ }
+
public void testRemoveSomeEvent()
- {
+ {
Graph g = getAndRegister( L );
Node S = node( "S" ), P = node( "??" ), O = node( "??" );
g.remove( S, P, O );
Object event = GraphEvents.remove( S, P, O );
L.assertHas( new Object[] { "someEvent", g, event } );
- }
-
+ }
+
/**
* Test that nodes can be found in all triple positions.
* However, testing for literals in subject positions is suppressed
@@ -717,151 +667,185 @@ public/* abstract */class AbstractTestGr
* such constructs leaking out to the RDF layer.
*/
public void testContainsNode()
- {
+ {
Graph g = getGraph();
graphAdd( g, "a P b; _c _Q _d; a 11 12" );
- QueryHandler qh = g.queryHandler();
- assertTrue( qh.containsNode( node( "a" ) ) );
- assertTrue( qh.containsNode( node( "P" ) ) );
- assertTrue( qh.containsNode( node( "b" ) ) );
- assertTrue( qh.containsNode( node( "_c" ) ) );
- assertTrue( qh.containsNode( node( "_Q" ) ) );
- assertTrue( qh.containsNode( node( "_d" ) ) );
-// assertTrue( qh.containsNode( node( "10" ) ) );
- assertTrue( qh.containsNode( node( "11" ) ) );
- assertTrue( qh.containsNode( node( "12" ) ) );
- /* */
- assertFalse( qh.containsNode( node( "x" ) ) );
- assertFalse( qh.containsNode( node( "_y" ) ) );
- assertFalse( qh.containsNode( node( "99" ) ) );
- }
-
+ assertTrue( containsNode( g, node( "a" ) ) );
+ assertTrue( containsNode( g, node( "P" ) ) );
+ assertTrue( containsNode( g, node( "b" ) ) );
+ assertTrue( containsNode( g, node( "_c" ) ) );
+ assertTrue( containsNode( g, node( "_Q" ) ) );
+ assertTrue( containsNode( g, node( "_d" ) ) );
+ // assertTrue( qh.containsNode( node( "10" ) ) );
+ assertTrue( containsNode( g, node( "11" ) ) );
+ assertTrue( containsNode( g, node( "12" ) ) );
+ /* */
+ assertFalse( containsNode( g, node( "x" ) ) );
+ assertFalse( containsNode( g, node( "_y" ) ) );
+ assertFalse( containsNode( g, node( "99" ) ) );
+ }
+
+
+
+ private boolean containsNode(Graph g, Node node)
+ {
+ return GraphUtil.containsNode(g, node) ;
+ }
+
public void testSubjectsFor()
- {
+ {
+ // First get the answer from the empty graph (not empty for an inf graph)
+ Graph b = getGraphWith( "" );
+ Set<Node> B = GraphUtil.listSubjects( b, Node.ANY, Node.ANY ).toSet();
+
Graph g = getGraphWith( "a P b; a Q c; a P d; b P x; c Q y" );
- testSameSubjects( g, Node.ANY, Node.ANY );
- testSameSubjects( g, node( "P" ), Node.ANY );
- testSameSubjects( g, node( "Q" ), node( "c" ) );
- }
-
- protected void testSameSubjects( Graph g, Node p, Node o )
- {
- Set<Node> bis = SimpleQueryHandler.subjectsFor( g, p, o ).toSet();
- Set<Node> qhs = g.queryHandler().subjectsFor( p, o ).toSet();
- assertEquals( bis, qhs );
- }
-
+
+ testSubjects( g, B, Node.ANY, Node.ANY, node("a"), node("b"), node("c") );
+ testSubjects( g, B, node( "P" ), Node.ANY, node("a"), node("b"));
+ testSubjects( g, B, node( "Q" ), node( "c" ), node("a") );
+ testSubjects( g, B, node( "Q" ), node( "y" ), node("c") );
+ testSubjects( g, B, node( "Q" ), node( "a" ));
+ testSubjects( g, B, node( "Q" ), node( "z" ));
+ }
+
+ protected void testSubjects( Graph g, Collection<Node> exclude, Node p, Node o, Node... expected )
+ {
+ List<Node> R = GraphUtil.listSubjects( g, p, o ).toList();
+ R.removeAll(exclude) ;
+ assertSameUnordered(R, exclude, expected) ;
+ }
+
+ // Same - except for order
+ private void assertSameUnordered(List<Node> x1, Collection<Node>exclude, Node[] expected)
+ {
+ List<Node> x = new ArrayList<Node>() ;
+ x.addAll(x1) ;
+ x.removeAll(exclude) ;
+
+ assertEquals(expected.length, x.size()) ;
+ Set<Node> X = new HashSet<Node>() ;
+ X.addAll(x) ;
+
+ Set<Node> R = new HashSet<Node>() ;
+ R.addAll(Arrays.asList(expected)) ;
+
+ assertEquals( R, X);
+
+ }
+
public void testListSubjectsNoRemove()
- {
+ {
Graph g = getGraphWith( "a P b; b Q c; c R a" );
- Iterator<Node> it = g.queryHandler().subjectsFor( Node.ANY, Node.ANY );
+ Iterator<Node> it = GraphUtil.listSubjects( g, Node.ANY, Node.ANY );
it.next();
try { it.remove(); fail( "listSubjects for " + g.getClass() + " should not support .remove()" ); }
catch (UnsupportedOperationException e) { pass(); }
- }
-
+ }
+
public void testObjectsFor()
- {
+ {
+ // First get the answer from the empty graph (not empty for an inf graph)
+ Graph b = getGraphWith( "" );
+ Set<Node> B = GraphUtil.listObjects( b, Node.ANY, Node.ANY ).toSet();
+
Graph g = getGraphWith( "b P a; c Q a; d P a; x P b; y Q c" );
- testSameObjects( g, Node.ANY, Node.ANY );
- testSameObjects( g, node( "P" ), Node.ANY );
- testSameObjects( g, node( "Q" ), node( "c" ) );
- }
-
- protected void testSameObjects( Graph g, Node s, Node p )
- {
- Set<Node> bis = SimpleQueryHandler.objectsFor( g, s, p ).toSet();
- Set<Node> qhs = g.queryHandler().objectsFor( s, p ).toSet();
- assertEquals( bis, qhs );
- }
+ testObjects( g, B, Node.ANY, Node.ANY, node("a"), node("b"), node("c") );
+ testObjects( g, B, Node.ANY, node( "P" ), node("a"), node("b") );
+ testObjects( g, B, node( "c" ), node( "Q" ), node("a") );
+ testObjects( g, B, node( "y" ), node( "Q" ), node("c") );
+ testObjects( g, B, node( "a" ), node( "Q" ));
+ testObjects( g, B, node( "z" ), node( "Q" ));
+ }
+
+ protected void testObjects( Graph g, Collection<Node> exclude, Node s, Node p, Node... expected )
+ {
+ List<Node> X = GraphUtil.listObjects( g, s, p ).toList();
+ assertSameUnordered(X, exclude, expected) ;
+ }
+
+ public void testPredicatesFor()
+ {
+ // First get the answer from the empty graph (not empty for an inf graph)
+ Graph b = getGraphWith( "" );
+ Set<Node> B = GraphUtil.listPredicates( b, Node.ANY, Node.ANY ).toSet();
+
+ Graph g = getGraphWith( "a P b; z P b; c Q d; e R f; g P b; h Q i" );
+ testPredicates( g, B, Node.ANY, Node.ANY, node("P"), node("Q"), node("R") );
+ testPredicates( g, B, Node.ANY, node( "b" ), node("P") );
+ testPredicates( g, B, node( "g" ), Node.ANY, node("P")) ;
+ testPredicates( g, B, node( "c" ), node( "d" ), node("Q") );
+ testPredicates( g, B, node( "e" ), node( "f" ), node("R") );
+ testPredicates( g, B, node( "e" ), node( "a" ));
+ testPredicates( g, B, node( "z" ), node( "y" ));
+ }
+
+ protected void testPredicates( Graph g, Collection<Node> exclude, Node s, Node o, Node... expected )
+ {
+ List<Node> X = GraphUtil.listPredicates( g, s, o ).toList();
+ assertSameUnordered(X, exclude, expected) ;
+ }
public void testListObjectsNoRemove()
- {
+ {
Graph g = getGraphWith( "a P b; b Q c; c R a" );
- Iterator<Node> it = g.queryHandler().objectsFor( Node.ANY, Node.ANY );
+ Iterator<Node> it = GraphUtil.listObjects( g, Node.ANY, Node.ANY );
it.next();
try { it.remove(); fail( "listObjects for " + g.getClass() + " should not support .remove()" ); }
catch (UnsupportedOperationException e) { pass(); }
- }
-
- public void testListObjectNoDuplicates()
- {
- Graph g = getGraphWith( "a P 1; b P 1" );
- int count = 0;
- Node one = node( "1" );
- Iterator<Node> it = g.queryHandler().objectsFor( Node.ANY, Node.ANY );
- while (it.hasNext()) if (it.next().equals( one )) count += 1;
- assertEquals( 1, count );
- }
-
- public void testPredicatesFor()
- {
- Graph g = getGraphWith( "a P b; c Q d; e R f; g P b; h Q i" );
- testSamePredicates( g, Node.ANY, Node.ANY );
- testSamePredicates( g, Node.ANY, node( "b" ) );
- testSamePredicates( g, node( "g" ), Node.ANY );
- testSamePredicates( g, node( "e" ), node( "f" ) );
- }
-
- protected void testSamePredicates( Graph g, Node s, Node o )
- {
- Set<Node> bis = SimpleQueryHandler.predicatesFor( g, s, o ).toSet();
- Set<Node> qhs = g.queryHandler().predicatesFor( s, o ).toSet();
- assertEquals( bis, qhs );
- }
+ }
public void testListPredicatesNoRemove()
- {
+ {
Graph g = getGraphWith( "a P b; b Q c; c R a" );
- Iterator<Node> it = g.queryHandler().predicatesFor( Node.ANY, Node.ANY );
+ Iterator<Node> it = GraphUtil.listPredicates( g, Node.ANY, Node.ANY );
it.next();
try { it.remove(); fail( "listPredicates for " + g.getClass() + " should not support .remove()" ); }
catch (UnsupportedOperationException e) { pass(); }
- }
-
+ }
+
public void testRemoveAll()
- {
+ {
testRemoveAll( "" );
testRemoveAll( "a R b" );
testRemoveAll( "c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" );
- }
+ }
+
+
-
-
public void testRemoveAll( String triples )
- {
+ {
Graph g = getGraph();
graphAdd( g, triples );
g.removeAll();
assertTrue( g.isEmpty() );
- }
-
+ }
+
public void failingTestDoubleRemoveAll() {
- final Graph g = getGraph();
- if (g.getCapabilities().iteratorRemoveAllowed() ) {
- graphAdd(g,"c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" );
- Iterator<Triple> it = new TrackingTripleIterator(g.find(Triple.ANY)){
- @Override
- public void remove() {
- super.remove(); // removes current
- g.delete(current); // no-op.
- }
- };
- while (it.hasNext()) {
- it.next();
- it.remove();
- }
- assertTrue( g.isEmpty() );
- }
+ final Graph g = getGraph();
+ if (g.getCapabilities().iteratorRemoveAllowed() ) {
+ graphAdd(g,"c S d; e:ff GGG hhhh; _i J 27; Ell Em 'en'" );
+ Iterator<Triple> it = new TrackingTripleIterator(g.find(Triple.ANY)){
+ @Override
+ public void remove() {
+ super.remove(); // removes current
+ g.delete(current); // no-op.
+ }
+ };
+ while (it.hasNext()) {
+ it.next();
+ it.remove();
+ }
+ assertTrue( g.isEmpty() );
+ }
}
-
+
public void testGetStatisticsHandler()
- {
+ {
Graph g = getGraph();
GraphStatisticsHandler h = g.getStatisticsHandler();
assertSame( h, g.getStatisticsHandler() );
- }
-
+ }
+
/**
Test cases for RemoveSPO(); each entry is a triple (add, remove, result).
<ul>
@@ -869,29 +853,29 @@ public/* abstract */class AbstractTestGr
<li>remove - the pattern to use in the removal
<li>result - the triples that should remain in the graph
</ul>
- */
+ */
protected String[][] cases =
- {
- { "x R y", "x R y", "" },
- { "x R y; a P b", "x R y", "a P b" },
- { "x R y; a P b", "?? R y", "a P b" },
- { "x R y; a P b", "x R ??", "a P b" },
- { "x R y; a P b", "x ?? y", "a P b" },
- { "x R y; a P b", "?? ?? ??", "" },
- { "x R y; a P b; c P d", "?? P ??", "x R y" },
- { "x R y; a P b; x S y", "x ?? ??", "a P b" },
- };
-
+ {
+ { "x R y", "x R y", "" },
+ { "x R y; a P b", "x R y", "a P b" },
+ { "x R y; a P b", "?? R y", "a P b" },
+ { "x R y; a P b", "x R ??", "a P b" },
+ { "x R y; a P b", "x ?? y", "a P b" },
+ { "x R y; a P b", "?? ?? ??", "" },
+ { "x R y; a P b; c P d", "?? P ??", "x R y" },
+ { "x R y; a P b; x S y", "x ?? ??", "a P b" },
+ };
+
/**
Test that remove(s, p, o) works, in the presence of inferencing graphs that
mean emptyness isn't available. This is why we go round the houses and
test that expected ~= initialContent + addedStuff - removed - initialContent.
- */
+ */
public void testRemoveSPO()
- {
+ {
for (int i = 0; i < cases.length; i += 1)
for (int j = 0; j < 3; j += 1)
- {
+ {
Graph content = getGraph();
Graph baseContent = copy( content );
graphAdd( content, cases[i][0] );
@@ -900,124 +884,124 @@ public/* abstract */class AbstractTestGr
content.remove( remove.getSubject(), remove.getPredicate(), remove.getObject() );
Graph finalContent = remove( copy( content ), baseContent );
assertIsomorphic( cases[i][1], expected, finalContent );
- }
- }
-
+ }
+ }
+
/** testIsomorphism from file data
* @throws FileNotFoundException */
public void testIsomorphismFile() throws FileNotFoundException {
- testIsomorphismXMLFile(1,true);
- testIsomorphismXMLFile(2,true);
- testIsomorphismXMLFile(3,true);
- testIsomorphismXMLFile(4,true);
- testIsomorphismXMLFile(5,false);
- testIsomorphismXMLFile(6,false);
- testIsomorphismNTripleFile(7,true);
- testIsomorphismNTripleFile(8,false);
-
+ testIsomorphismXMLFile(1,true);
+ testIsomorphismXMLFile(2,true);
+ testIsomorphismXMLFile(3,true);
+ testIsomorphismXMLFile(4,true);
+ testIsomorphismXMLFile(5,false);
+ testIsomorphismXMLFile(6,false);
+ testIsomorphismNTripleFile(7,true);
+ testIsomorphismNTripleFile(8,false);
+
}
private void testIsomorphismNTripleFile(int i, boolean result) throws FileNotFoundException {
- testIsomorphismFile(i,"N-TRIPLE","nt",result);
- }
+ testIsomorphismFile(i,"N-TRIPLE","nt",result);
+ }
+
+ private void testIsomorphismXMLFile(int i, boolean result) throws FileNotFoundException {
+ testIsomorphismFile(i,"RDF/XML","rdf",result);
- private void testIsomorphismXMLFile(int i, boolean result) throws FileNotFoundException {
- testIsomorphismFile(i,"RDF/XML","rdf",result);
-
- }
+ }
String filebase = "testing/regression/testModelEquals/";
- private void testIsomorphismFile(int n, String lang, String suffix, boolean result) throws FileNotFoundException {
+ private void testIsomorphismFile(int n, String lang, String suffix, boolean result) throws FileNotFoundException {
- Graph g1 = getGraph();
- Graph g2 = getGraph();
- Model m1 = ModelFactory.createModelForGraph(g1);
- Model m2 = ModelFactory.createModelForGraph(g2);
-
- m1.read(
- new FileInputStream(filebase + Integer.toString(n) + "-1."+suffix),
- "http://www.example.org/",lang);
- m2.read(
- new FileInputStream(filebase + Integer.toString(n) + "-2."+suffix),
- "http://www.example.org/",lang);
+ Graph g1 = getGraph();
+ Graph g2 = getGraph();
+ Model m1 = ModelFactory.createModelForGraph(g1);
+ Model m2 = ModelFactory.createModelForGraph(g2);
+
+ m1.read(
+ new FileInputStream(filebase + Integer.toString(n) + "-1."+suffix),
+ "http://www.example.org/",lang);
+ m2.read(
+ new FileInputStream(filebase + Integer.toString(n) + "-2."+suffix),
+ "http://www.example.org/",lang);
- boolean rslt = g1.isIsomorphicWith(g2) == result;
- if (!rslt) {
+ boolean rslt = g1.isIsomorphicWith(g2) == result;
+ if (!rslt) {
System.out.println("g1:");
m1.write(System.out, "N-TRIPLE");
System.out.println("g2:");
m2.write(System.out, "N-TRIPLE");
}
assertTrue("Isomorphism test failed",rslt);
- }
+ }
+
+ protected void add( Graph toUpdate, Graph toAdd )
+ {
+ GraphUtil.addInto( toUpdate, toAdd) ;
+ }
- protected void add( Graph toUpdate, Graph toAdd )
- {
- GraphUtil.addInto( toUpdate, toAdd) ;
- }
-
protected Graph remove( Graph toUpdate, Graph toRemove )
- {
+ {
GraphUtil.deleteFrom(toUpdate, toRemove) ;
return toUpdate;
- }
-
-
+ }
+
+
protected Graph copy( Graph g )
- {
+ {
Graph result = Factory.createDefaultGraph();
GraphUtil.addInto(result, g) ;
return result;
- }
-
+ }
+
protected Graph getClosed()
- {
+ {
Graph result = getGraph();
result.close();
return result;
- }
-
-// public void testClosedDelete()
-// {
-// try { getClosed().delete( triple( "x R y" ) ); fail( "delete when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedAdd()
-// {
-// try { getClosed().add( triple( "x R y" ) ); fail( "add when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedContainsTriple()
-// {
-// try { getClosed().contains( triple( "x R y" ) ); fail( "contains[triple] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedContainsSPO()
-// {
-// Node a = Node.ANY;
-// try { getClosed().contains( a, a, a ); fail( "contains[SPO] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedFindTriple()
-// {
-// try { getClosed().find( triple( "x R y" ) ); fail( "find [triple] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedFindSPO()
-// {
-// Node a = Node.ANY;
-// try { getClosed().find( a, a, a ); fail( "find[SPO] when closed" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-//
-// public void testClosedSize()
-// {
-// try { getClosed().size(); fail( "size when closed (" + this.getClass() + ")" ); }
-// catch (ClosedException c) { /* as required */ }
-// }
-
}
+
+ // public void testClosedDelete()
+ // {
+ // try { getClosed().delete( triple( "x R y" ) ); fail( "delete when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedAdd()
+ // {
+ // try { getClosed().add( triple( "x R y" ) ); fail( "add when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedContainsTriple()
+ // {
+ // try { getClosed().contains( triple( "x R y" ) ); fail( "contains[triple] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedContainsSPO()
+ // {
+ // Node a = Node.ANY;
+ // try { getClosed().contains( a, a, a ); fail( "contains[SPO] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedFindTriple()
+ // {
+ // try { getClosed().find( triple( "x R y" ) ); fail( "find [triple] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedFindSPO()
+ // {
+ // Node a = Node.ANY;
+ // try { getClosed().find( a, a, a ); fail( "find[SPO] when closed" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+ //
+ // public void testClosedSize()
+ // {
+ // try { getClosed().size(); fail( "size when closed (" + this.getClass() + ")" ); }
+ // catch (ClosedException c) { /* as required */ }
+ // }
+
+}