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/10 18:25:16 UTC
svn commit: r1419595 [3/6] - in /jena/trunk: jena-arq/
jena-arq/src/main/java/com/hp/hpl/jena/sparql/core/
jena-arq/src/main/java/com/hp/hpl/jena/sparql/graph/
jena-arq/src/main/java/com/hp/hpl/jena/sparql/modify/
jena-arq/src/main/java/org/openjena/ri...
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelCom.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelCom.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelCom.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelCom.java Mon Dec 10 17:25:00 2012
@@ -18,24 +18,27 @@
package com.hp.hpl.jena.rdf.model.impl;
-import com.hp.hpl.jena.rdf.model.*;
-import com.hp.hpl.jena.shared.*;
-import com.hp.hpl.jena.shared.impl.*;
-import com.hp.hpl.jena.graph.*;
-import com.hp.hpl.jena.graph.impl.*;
-import com.hp.hpl.jena.graph.query.*;
-
-import com.hp.hpl.jena.util.CollectionFactory;
-import com.hp.hpl.jena.util.iterator.*;
-import com.hp.hpl.jena.vocabulary.RDF;
-import com.hp.hpl.jena.datatypes.*;
-import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
-import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
-import com.hp.hpl.jena.enhanced.*;
-
-import java.io.*;
-import java.net.URL;
-import java.util.*;
+import java.io.* ;
+import java.net.URL ;
+import java.util.* ;
+
+import com.hp.hpl.jena.datatypes.DatatypeFormatException ;
+import com.hp.hpl.jena.datatypes.RDFDatatype ;
+import com.hp.hpl.jena.datatypes.TypeMapper ;
+import com.hp.hpl.jena.datatypes.xsd.XSDDatatype ;
+import com.hp.hpl.jena.datatypes.xsd.XSDDateTime ;
+import com.hp.hpl.jena.enhanced.BuiltinPersonalities ;
+import com.hp.hpl.jena.enhanced.EnhGraph ;
+import com.hp.hpl.jena.enhanced.Personality ;
+import com.hp.hpl.jena.graph.* ;
+import com.hp.hpl.jena.graph.impl.LiteralLabel ;
+import com.hp.hpl.jena.graph.impl.LiteralLabelFactory ;
+import com.hp.hpl.jena.rdf.model.* ;
+import com.hp.hpl.jena.shared.* ;
+import com.hp.hpl.jena.shared.impl.PrefixMappingImpl ;
+import com.hp.hpl.jena.util.CollectionFactory ;
+import com.hp.hpl.jena.util.iterator.* ;
+import com.hp.hpl.jena.vocabulary.RDF ;
/** Common methods for model implementations.
*
@@ -48,65 +51,61 @@ import java.util.*;
*/
public class ModelCom extends EnhGraph
- implements Model, PrefixMapping, Lock
+implements Model, PrefixMapping, Lock
{
- private static final RDFReaderF readerFactory = new RDFReaderFImpl();
- private static final RDFWriterF writerFactory = new RDFWriterFImpl();
- private Lock modelLock = null ;
-
+ private static final RDFReaderF readerFactory = new RDFReaderFImpl();
+ private static final RDFWriterF writerFactory = new RDFWriterFImpl();
+ private Lock modelLock = null ;
+
/**
make a model based on the specified graph
- */
- public ModelCom( Graph base )
- { this( base, BuiltinPersonalities.model ); }
-
+ */
+ public ModelCom( Graph base )
+ { this( base, BuiltinPersonalities.model ); }
+
public ModelCom( Graph base, Personality<RDFNode> personality )
- { super( base, personality );
- withDefaultMappings( defaultPrefixMapping ); }
-
+ { super( base, personality );
+ withDefaultMappings( defaultPrefixMapping ); }
+
private static PrefixMapping defaultPrefixMapping = PrefixMapping.Factory.create();
-
+
public static PrefixMapping getDefaultModelPrefixes()
- { return defaultPrefixMapping; }
-
+ { return defaultPrefixMapping; }
+
public static PrefixMapping setDefaultModelPrefixes( PrefixMapping pm )
- { PrefixMapping result = defaultPrefixMapping;
- defaultPrefixMapping = pm;
- return result; }
-
- @Override
- public QueryHandler queryHandler()
- { return getGraph().queryHandler(); }
-
+ { PrefixMapping result = defaultPrefixMapping;
+ defaultPrefixMapping = pm;
+ return result; }
+
@Override
public Graph getGraph()
- { return graph; }
-
+ { return graph; }
+
protected static Model createWorkModel()
- { return ModelFactory.createDefaultModel(); }
-
+ { return ModelFactory.createDefaultModel(); }
+
@Override
public RDFNode asRDFNode( Node n )
- {
+ {
return n.isLiteral()
- ? (RDFNode) this.getNodeAs( n, Literal.class )
- : (RDFNode) this.getNodeAs( n, Resource.class );
- }
+ ? (RDFNode) this.getNodeAs( n, Literal.class )
+ : (RDFNode) this.getNodeAs( n, Resource.class );
+ }
@Override
public Resource wrapAsResource( Node n )
- {
+ {
if (n.isLiteral())
throw new UnsupportedOperationException( "literal cannot be converted to Resource" );
return this.getNodeAs( n, Resource.class );
- }
+ }
/**
the ModelReifier does everything to do with reification.
- */
+ */
protected ModelReifier modelReifier = new ModelReifier( this );
-
+
@Override
@Deprecated public Resource getResource(String uri, ResourceF f) {
try {
@@ -115,438 +114,441 @@ public class ModelCom extends EnhGraph
throw new JenaException(e);
}
}
-
+
@Override
public Model addLiteral( Resource s, Property p, boolean o )
- { return add(s, p, createTypedLiteral( o ) ); }
-
+ { return add(s, p, createTypedLiteral( o ) ); }
+
@Override
public Model addLiteral( Resource s, Property p, long o )
- { return add(s, p, createTypedLiteral( o ) ); }
-
+ { return add(s, p, createTypedLiteral( o ) ); }
+
@Override
public Model addLiteral( Resource s, Property p, int o )
- { return add(s, p, createTypedLiteral( o ) ); }
-
+ { return add(s, p, createTypedLiteral( o ) ); }
+
@Override
public Model addLiteral( Resource s, Property p, char o )
- { return add(s, p, createTypedLiteral( o ) ); }
-
+ { return add(s, p, createTypedLiteral( o ) ); }
+
@Override
public Model addLiteral( Resource s, Property p, float o )
- { return add( s, p, createTypedLiteral( o ) ); }
-
+ { return add( s, p, createTypedLiteral( o ) ); }
+
@Override
public Model addLiteral( Resource s, Property p, double o )
- { return add(s, p, createTypedLiteral( o ) ); }
-
+ { return add(s, p, createTypedLiteral( o ) ); }
+
@Override
public Model add(Resource s, Property p, String o) {
return add( s, p, o, "", false );
}
-
+
@Override
public Model add(Resource s, Property p, String o, boolean wellFormed)
- {
+ {
add( s, p, literal( o, "", wellFormed ) );
return this;
- }
-
+ }
+
public Model add( Resource s, Property p, String o, String lang,
- boolean wellFormed) {
+ boolean wellFormed) {
add( s, p, literal( o, lang, wellFormed ) );
return this;
}
-
+
@Override
public Model add(Resource s, Property p, String lex, RDFDatatype datatype)
{
add( s, p, literal( lex, datatype)) ;
return this;
}
-
+
private Literal literal( String s, String lang, boolean wellFormed )
- { return new LiteralImpl( Node.createLiteral( s, lang, wellFormed), this ); }
-
+ { return new LiteralImpl( Node.createLiteral( s, lang, wellFormed), this ); }
+
private Literal literal( String lex, RDFDatatype datatype)
{ return new LiteralImpl( Node.createLiteral( lex, "", datatype), this ); }
@Override
public Model add( Resource s, Property p, String o, String l )
- { return add( s, p, o, l, false ); }
+ { return add( s, p, o, l, false ); }
@Override
@Deprecated public Model addLiteral( Resource s, Property p, Object o )
- { return add( s, p, asObject( o ) ); }
+ { return add( s, p, asObject( o ) ); }
@Override
public Model addLiteral( Resource s, Property p, Literal o )
- { return add( s, p, o ); }
-
+ { return add( s, p, o ); }
+
private RDFNode asObject( Object o )
- { return o instanceof RDFNode ? (RDFNode) o : createTypedLiteral( o ); }
+ { return o instanceof RDFNode ? (RDFNode) o : createTypedLiteral( o ); }
@Override
public Model add( StmtIterator iter ) {
- try { getBulkUpdateHandler().add( asTriples( iter ) ); }
+ try { GraphUtil.add( getGraph(), asTriples( iter ) ); }
finally { iter.close(); }
return this;
}
-
+
@Override
public Model add( Model m )
- { return add( m, false ); }
-
+ { return add( m, false ); }
+
+ @Deprecated
@Override
public Model add( Model m, boolean suppressReifications ) {
- getBulkUpdateHandler().add( m.getGraph(), !suppressReifications );
+ // suppressReifications is a no-op.
+ GraphUtil.addInto( getGraph(), m.getGraph() );
return this;
}
-
+
@Override
public RDFReader getReader() {
return readerFactory.getReader();
}
-
+
@Override
public RDFReader getReader(String lang) {
return readerFactory.getReader(lang);
}
-
+
@Override
public String setReaderClassName(String lang, String className) {
return readerFactory.setReaderClassName(lang, className);
}
-
+
@Override
public Model read(String url) {
readerFactory .getReader() .read(this, url);
return this;
}
-
+
@Override
public Model read(Reader reader, String base) {
readerFactory .getReader() .read(this, reader, base);
return this;
}
-
- @Override
+
+ @Override
public Model read(InputStream reader, String base) {
- readerFactory .getReader() .read(this, reader, base);
- return this;
- }
-
+ readerFactory .getReader() .read(this, reader, base);
+ return this;
+ }
+
@Override
public Model read(String url, String lang) {
readerFactory. getReader(lang) .read(this, url);
return this;
}
-
+
@Override
public Model read( String url, String base, String lang )
- {
+ {
try
- {
+ {
InputStream is = new URL( url ) .openStream();
try { read( is, base, lang ); }
finally { if (null != is) { is.close(); } }
- }
+ }
catch (IOException e) { throw new WrappedIOException( e ); }
return this;
- }
-
+ }
+
@Override
public Model read(Reader reader, String base, String lang)
- {
+ {
readerFactory .getReader(lang) .read(this, reader, base);
return this;
- }
-
- @Override
+ }
+
+ @Override
public Model read(InputStream reader, String base, String lang)
- {
- readerFactory .getReader(lang) .read(this, reader, base);
- return this;
- }
+ {
+ readerFactory .getReader(lang) .read(this, reader, base);
+ return this;
+ }
/**
Get the model's writer after priming it with the model's namespace
prefixes.
- */
+ */
@Override
public RDFWriter getWriter() {
return writerFactory.getWriter();
}
-
+
/**
Get the model's writer after priming it with the model's namespace
prefixes.
- */
+ */
@Override
public RDFWriter getWriter(String lang) {
return writerFactory.getWriter(lang);
}
-
+
@Override
public String setWriterClassName(String lang, String className) {
return writerFactory.setWriterClassName(lang, className);
}
-
+
@Override
public Model write(Writer writer)
- {
+ {
getWriter() .write(this, writer, "");
return this;
- }
-
+ }
+
@Override
public Model write(Writer writer, String lang)
- {
+ {
getWriter(lang) .write(this, writer, "");
return this;
- }
-
+ }
+
@Override
public Model write(Writer writer, String lang, String base)
- {
+ {
getWriter(lang) .write(this, writer, base);
return this;
- }
-
- @Override
+ }
+
+ @Override
public Model write( OutputStream writer )
- {
+ {
getWriter() .write(this, writer, "");
- return this;
- }
-
- @Override
+ return this;
+ }
+
+ @Override
public Model write(OutputStream writer, String lang)
- {
- getWriter(lang) .write(this, writer, "");
- return this;
- }
-
- @Override
+ {
+ getWriter(lang) .write(this, writer, "");
+ return this;
+ }
+
+ @Override
public Model write(OutputStream writer, String lang, String base)
- {
+ {
getWriter(lang) .write(this, writer, base);
- return this;
- }
-
+ return this;
+ }
+
@Override
public Model remove(Statement s) {
graph.delete(s.asTriple());
return this;
}
-
+
@Override
public Model remove( Resource s, Property p, RDFNode o ) {
graph.delete( Triple.create( s.asNode(), p.asNode(), o.asNode() ) );
return this;
}
-
-
+
+
@Override
public Model remove( StmtIterator iter )
- {
- getBulkUpdateHandler().delete( asTriples( iter ) );
+ {
+ GraphUtil.delete( getGraph(), asTriples( iter ) );
return this;
- }
-
+ }
+
@Override
public Model remove( Model m )
- { return remove( m, false ); }
-
+ { return remove( m, false ); }
+
@Override
+ @Deprecated
public Model remove( Model m, boolean suppressReifications )
- {
- getBulkUpdateHandler().delete( m.getGraph(), !suppressReifications );
+ {
+ GraphUtil.deleteFrom( getGraph(), m.getGraph());
return this;
- }
-
+ }
+
@Override
public Model removeAll()
- {
- getGraph().getBulkUpdateHandler().removeAll();
+ {
+ getGraph().clear();
return this;
- }
-
+ }
+
@Override
public Model removeAll( Resource s, Property p, RDFNode o )
- {
- getGraph().getBulkUpdateHandler().remove( asNode( s ), asNode( p ), asNode( o ) );
+ {
+ getGraph().remove( asNode( s ), asNode( p ), asNode( o ) );
return this;
- }
-
+ }
+
@Override
public boolean containsLiteral( Resource s, Property p, boolean o )
- { return contains(s, p, createTypedLiteral( o ) ); }
-
+ { return contains(s, p, createTypedLiteral( o ) ); }
+
@Override
public boolean containsLiteral( Resource s, Property p, long o )
- { return contains(s, p, createTypedLiteral( o ) ); }
-
+ { return contains(s, p, createTypedLiteral( o ) ); }
+
@Override
public boolean containsLiteral( Resource s, Property p, int o )
- { return contains(s, p, createTypedLiteral( o ) ); }
-
+ { return contains(s, p, createTypedLiteral( o ) ); }
+
@Override
public boolean containsLiteral( Resource s, Property p, char o )
- { return contains(s, p, createTypedLiteral( o ) ); }
-
+ { return contains(s, p, createTypedLiteral( o ) ); }
+
@Override
public boolean containsLiteral( Resource s, Property p, float o )
- { return contains(s, p, createTypedLiteral( o ) ); }
-
+ { return contains(s, p, createTypedLiteral( o ) ); }
+
@Override
public boolean containsLiteral( Resource s, Property p, double o )
- { return contains(s, p, createTypedLiteral( o ) ); }
-
+ { return contains(s, p, createTypedLiteral( o ) ); }
+
@Override
public boolean contains( Resource s, Property p, String o )
- { return contains( s, p, o, "" ); }
-
+ { return contains( s, p, o, "" ); }
+
@Override
public boolean contains( Resource s, Property p, String o, String l )
- { return contains( s, p, literal( o, l, false ) ); }
-
+ { return contains( s, p, literal( o, l, false ) ); }
+
@Override
public boolean containsLiteral(Resource s, Property p, Object o)
- { return contains( s, p, asObject( o ) ); }
-
+ { return contains( s, p, asObject( o ) ); }
+
@Override
public boolean containsAny( Model model )
- { return containsAnyThenClose( model.listStatements() ); }
-
+ { return containsAnyThenClose( model.listStatements() ); }
+
@Override
public boolean containsAll( Model model )
- { return containsAllThenClose( model.listStatements() ); }
-
+ { return containsAllThenClose( model.listStatements() ); }
+
protected boolean containsAnyThenClose( StmtIterator iter )
- { try { return containsAny( iter ); } finally { iter.close(); } }
+ { try { return containsAny( iter ); } finally { iter.close(); } }
protected boolean containsAllThenClose( StmtIterator iter )
- { try { return containsAll( iter ); } finally { iter.close(); } }
-
+ { try { return containsAll( iter ); } finally { iter.close(); } }
+
@Override
public boolean containsAny( StmtIterator iter )
- {
+ {
while (iter.hasNext()) if (contains(iter.nextStatement())) return true;
return false;
- }
-
+ }
+
@Override
public boolean containsAll( StmtIterator iter )
- {
+ {
while (iter.hasNext()) if (!contains(iter.nextStatement())) return false;
return true;
- }
-
+ }
+
protected StmtIterator listStatements( Resource S, Property P, Node O )
- {
+ {
return IteratorFactory.asStmtIterator
( graph.find( asNode( S ), asNode( P ), O ), this );
- }
-
+ }
+
@Override
public StmtIterator listStatements( Resource S, Property P, RDFNode O )
- { return listStatements( S, P, asNode( O ) ); }
-
+ { return listStatements( S, P, asNode( O ) ); }
+
@Override
public StmtIterator listStatements( Resource S, Property P, String O ) {
return O == null ? listStatements(S, P, Node.ANY)
- : listStatements( S, P, Node.createLiteral( O ) );
+ : listStatements( S, P, Node.createLiteral( O ) );
}
-
+
@Override
public StmtIterator listStatements( Resource S, Property P, String O, String L ) {
return O == null ? listStatements(S, P, Node.ANY)
- : listStatements( S, P, Node.createLiteral( O, L, false ) );
+ : listStatements( S, P, Node.createLiteral( O, L, false ) );
}
-
+
@Override
public StmtIterator listLiteralStatements( Resource S, Property P, boolean O )
- { return listStatements( S, P, createTypedLiteral( O ) ); }
-
+ { return listStatements( S, P, createTypedLiteral( O ) ); }
+
@Override
public StmtIterator listLiteralStatements( Resource S, Property P, long O )
- { return listStatements( S, P, createTypedLiteral( O ) ); }
-
+ { return listStatements( S, P, createTypedLiteral( O ) ); }
+
@Override
public StmtIterator listLiteralStatements( Resource S, Property P, char O )
- { return listStatements( S, P, createTypedLiteral( O ) ); }
-
+ { return listStatements( S, P, createTypedLiteral( O ) ); }
+
@Override
public StmtIterator listLiteralStatements( Resource S, Property P, float O )
- { return listStatements( S, P, createTypedLiteral( O ) ); }
-
+ { return listStatements( S, P, createTypedLiteral( O ) ); }
+
@Override
public StmtIterator listLiteralStatements( Resource S, Property P, double O )
- { return listStatements( S, P, createTypedLiteral( O ) ); }
-
+ { return listStatements( S, P, createTypedLiteral( O ) ); }
+
/*
list resources with property [was: list subjects with property]
- */
-
+ */
+
@Override
public ResIterator listResourcesWithProperty( Property p, boolean o )
- { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
-
+ { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
+
@Override
public ResIterator listResourcesWithProperty( Property p, char o )
- { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
-
+ { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
+
@Override
public ResIterator listResourcesWithProperty( Property p, long o )
- { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
-
+ { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
+
@Override
public ResIterator listResourcesWithProperty( Property p, float o )
- { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
-
+ { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
+
@Override
public ResIterator listResourcesWithProperty( Property p, double o )
- { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
-
+ { return listResourcesWithProperty(p, createTypedLiteral( o ) ); }
+
@Override
public ResIterator listResourcesWithProperty( Property p, Object o )
- { return listResourcesWithProperty( p, createTypedLiteral( o ) ); }
-
+ { return listResourcesWithProperty( p, createTypedLiteral( o ) ); }
+
@Override
public ResIterator listSubjectsWithProperty( Property p, RDFNode o )
- { return listResourcesWithProperty( p, o ); }
-
+ { return listResourcesWithProperty( p, o ); }
+
@Override
public ResIterator listSubjectsWithProperty( Property p, String o )
- { return listSubjectsWithProperty( p, o, "" ); }
-
+ { return listSubjectsWithProperty( p, o, "" ); }
+
@Override
public ResIterator listSubjectsWithProperty( Property p, String o, String l )
- { return listResourcesWithProperty(p, literal( o, l, false ) ); }
-
+ { return listResourcesWithProperty(p, literal( o, l, false ) ); }
+
@Override
public Resource createResource( Resource type )
- { return createResource().addProperty( RDF.type, type ); }
-
+ { return createResource().addProperty( RDF.type, type ); }
+
@Override
public Resource createResource( String uri,Resource type )
- { return getResource( uri ).addProperty( RDF.type, type ); }
-
+ { return getResource( uri ).addProperty( RDF.type, type ); }
+
@Override
@Deprecated public Resource createResource( ResourceF f )
- { return createResource( null, f ); }
-
+ { return createResource( null, f ); }
+
@Override
public Resource createResource( AnonId id )
- { return new ResourceImpl( id, this ); }
-
+ { return new ResourceImpl( id, this ); }
+
@Override
@Deprecated public Resource createResource( String uri, ResourceF f )
- { return f.createResource( createResource( uri ) ); }
-
-
+ { return f.createResource( createResource( uri ) ); }
+
+
/** create a type literal from a boolean value.
*
* <p> The value is converted to a string using its <CODE>toString</CODE>
@@ -559,7 +561,7 @@ public class ModelCom extends EnhGraph
public Literal createTypedLiteral( boolean v ) {
return createTypedLiteral( new Boolean( v ) );
}
-
+
/** create a typed literal from an integer value.
*
* @param v the value of the literal
@@ -570,7 +572,7 @@ public class ModelCom extends EnhGraph
public Literal createTypedLiteral(int v) {
return createTypedLiteral(new Integer(v));
}
-
+
/** create a typed literal from a long integer value.
*
* @param v the value of the literal
@@ -581,7 +583,7 @@ public class ModelCom extends EnhGraph
public Literal createTypedLiteral(long v) {
return createTypedLiteral(new Long(v));
}
-
+
/** create a typed literal from a char value.
*
* @param v the value of the literal
@@ -592,7 +594,7 @@ public class ModelCom extends EnhGraph
public Literal createTypedLiteral(char v) {
return createTypedLiteral(new Character(v));
}
-
+
/** create a typed literal from a float value.
*
* @param v the value of the literal
@@ -603,7 +605,7 @@ public class ModelCom extends EnhGraph
public Literal createTypedLiteral(float v) {
return createTypedLiteral(new Float(v));
}
-
+
/** create a typed literal from a double value.
*
* @param v the value of the literal
@@ -614,7 +616,7 @@ public class ModelCom extends EnhGraph
public Literal createTypedLiteral(double v) {
return createTypedLiteral(new Double(v));
}
-
+
/** create a typed literal from a String value.
*
* @param v the value of the literal
@@ -635,9 +637,9 @@ public class ModelCom extends EnhGraph
Object value = new XSDDateTime(cal);
LiteralLabel ll = LiteralLabelFactory.create(value, "", XSDDatatype.XSDdateTime);
return new LiteralImpl(Node.createLiteral(ll), this);
-
+
}
-
+
/**
* Build a typed literal from its lexical form. The
* lexical form will be parsed now and the value stored. If
@@ -649,10 +651,10 @@ public class ModelCom extends EnhGraph
*/
@Override
public Literal createTypedLiteral(String lex, RDFDatatype dtype)
- throws DatatypeFormatException {
+ throws DatatypeFormatException {
return new LiteralImpl( Node.createLiteral( lex, "", dtype ), this);
}
-
+
/**
* Build a typed literal from its value form.
*
@@ -680,7 +682,7 @@ public class ModelCom extends EnhGraph
LiteralLabel ll = LiteralLabelFactory.createLiteralLabel( lex, "", dt );
return new LiteralImpl( Node.createLiteral(ll), this );
}
-
+
/**
* Build a typed literal from its value form.
*
@@ -693,7 +695,7 @@ public class ModelCom extends EnhGraph
LiteralLabel ll = LiteralLabelFactory.create(value, "", dt);
return new LiteralImpl(Node.createLiteral(ll), this);
}
-
+
/**
* Build a typed literal label from its value form using
* whatever datatype is currently registered as the the default
@@ -702,96 +704,96 @@ public class ModelCom extends EnhGraph
*/
@Override
public Literal createTypedLiteral( Object value )
- {
+ {
// Catch special case of a Calendar which we want to act as if it were an XSDDateTime
if (value instanceof Calendar)
return createTypedLiteral( (Calendar)value );
LiteralLabel ll = LiteralLabelFactory.create( value );
return new LiteralImpl( Node.createLiteral( ll ), this);
- }
-
+ }
+
@Override
public Literal createLiteral( String v )
- { return createLiteral( v, "" ); }
-
+ { return createLiteral( v, "" ); }
+
@Override
public Literal createLiteral( String v, String l )
- { return literal( v, l, false ); }
-
+ { return literal( v, l, false ); }
+
@Override
public Literal createLiteral( String v, boolean wellFormed )
- { return literal( v, "", wellFormed ); }
-
+ { return literal( v, "", wellFormed ); }
+
public Literal createLiteral(String v, String l, boolean wellFormed)
- { return literal( v, l, wellFormed ); }
-
+ { return literal( v, l, wellFormed ); }
+
@Override
public Statement createLiteralStatement( Resource r, Property p, boolean o )
- { return createStatement( r, p, createTypedLiteral( o ) ); }
-
+ { return createStatement( r, p, createTypedLiteral( o ) ); }
+
@Override
public Statement createLiteralStatement( Resource r, Property p, long o )
- { return createStatement( r, p, createTypedLiteral( o ) ); }
+ { return createStatement( r, p, createTypedLiteral( o ) ); }
@Override
public Statement createLiteralStatement( Resource r, Property p, int o )
- { return createStatement( r, p, createTypedLiteral( o ) ); }
-
+ { return createStatement( r, p, createTypedLiteral( o ) ); }
+
@Override
public Statement createLiteralStatement( Resource r, Property p, char o )
- { return createStatement( r, p, createTypedLiteral( o ) ); }
-
+ { return createStatement( r, p, createTypedLiteral( o ) ); }
+
@Override
public Statement createLiteralStatement( Resource r, Property p, float o )
- { return createStatement( r, p, createTypedLiteral( o ) ); }
-
+ { return createStatement( r, p, createTypedLiteral( o ) ); }
+
@Override
public Statement createLiteralStatement( Resource r, Property p, double o )
- { return createStatement( r, p, createTypedLiteral( o ) ); }
-
+ { return createStatement( r, p, createTypedLiteral( o ) ); }
+
@Override
public Statement createStatement( Resource r, Property p, String o )
- { return createStatement( r, p, createLiteral( o ) ); }
+ { return createStatement( r, p, createLiteral( o ) ); }
@Override
public Statement createLiteralStatement( Resource r, Property p, Object o )
- { return createStatement( r, p, asObject( o ) ); }
-
+ { return createStatement( r, p, asObject( o ) ); }
+
@Override
public Statement createStatement
- ( Resource r, Property p, String o, boolean wellFormed )
- { return createStatement( r, p, o, "", wellFormed ); }
-
+ ( Resource r, Property p, String o, boolean wellFormed )
+ { return createStatement( r, p, o, "", wellFormed ); }
+
@Override
public Statement createStatement(Resource r, Property p, String o, String l)
- { return createStatement( r, p, o, l, false ); }
-
+ { return createStatement( r, p, o, l, false ); }
+
@Override
public Statement createStatement
- ( Resource r, Property p, String o, String l, boolean wellFormed )
- { return createStatement( r, p, literal( o, l, wellFormed ) ); }
-
+ ( Resource r, Property p, String o, String l, boolean wellFormed )
+ { return createStatement( r, p, literal( o, l, wellFormed ) ); }
+
@Override
public Bag createBag()
- { return createBag( null ); }
-
+ { return createBag( null ); }
+
@Override
public Alt createAlt()
- { return createAlt( null ); }
-
+ { return createAlt( null ); }
+
@Override
public Seq createSeq()
- { return createSeq( null ); }
-
+ { return createSeq( null ); }
+
/**
Answer a (the) new empty list
@return An RDF-encoded list of no elements (ie nil)
- */
+ */
@Override
public RDFList createList()
- { return getResource( RDF.nil.getURI() ).as( RDFList.class ); }
-
-
+ { return getResource( RDF.nil.getURI() ).as( RDFList.class ); }
+
+
/**
* <p>Answer a new list containing the resources from the given iterator, in order.</p>
* @param members An iterator, each value of which is expected to be an RDFNode.
@@ -799,13 +801,13 @@ public class ModelCom extends EnhGraph
*/
@Override
public RDFList createList( Iterator<? extends RDFNode> members )
- {
+ {
RDFList list = createList();
while (members != null && members.hasNext()) list = list.with( members.next() );
return list;
- }
-
-
+ }
+
+
/**
* <p>Answer a new list containing the RDF nodes from the given array, in order</p>
* @param members An array of RDFNodes that will be the members of the list
@@ -815,87 +817,87 @@ public class ModelCom extends EnhGraph
public RDFList createList( RDFNode[] members ) {
return createList( Arrays.asList( members ).iterator() );
}
-
+
@Override
public RDFNode getRDFNode( Node n )
- { return asRDFNode( n ); }
-
+ { return asRDFNode( n ); }
+
@Override
public Resource getResource( String uri )
- { return IteratorFactory.asResource(makeURI(uri),this); }
-
+ { return IteratorFactory.asResource(makeURI(uri),this); }
+
@Override
public Property getProperty( String uri )
- {
+ {
if (uri == null) throw new InvalidPropertyURIException( null );
return IteratorFactory.asProperty( makeURI(uri), this );
- }
-
+ }
+
@Override
public Property getProperty( String nameSpace,String localName )
- { return getProperty( nameSpace + localName ); }
-
+ { return getProperty( nameSpace + localName ); }
+
@Override
public Seq getSeq( String uri )
- { return (Seq) IteratorFactory.asResource( makeURI( uri ),Seq.class, this); }
-
+ { return (Seq) IteratorFactory.asResource( makeURI( uri ),Seq.class, this); }
+
@Override
public Seq getSeq( Resource r )
- { return r.as( Seq.class ); }
-
+ { return r.as( Seq.class ); }
+
@Override
public Bag getBag( String uri )
- { return (Bag) IteratorFactory.asResource( makeURI( uri ),Bag.class, this ); }
-
+ { return (Bag) IteratorFactory.asResource( makeURI( uri ),Bag.class, this ); }
+
@Override
public Bag getBag( Resource r )
- { return r.as( Bag.class ); }
-
+ { return r.as( Bag.class ); }
+
static private Node makeURI(String uri)
- { return uri == null ? Node.createAnon() : Node.createURI( uri ); }
-
+ { return uri == null ? Node.createAnon() : Node.createURI( uri ); }
+
@Override
public Alt getAlt( String uri )
- { return (Alt) IteratorFactory.asResource( makeURI(uri) ,Alt.class, this ); }
-
+ { return (Alt) IteratorFactory.asResource( makeURI(uri) ,Alt.class, this ); }
+
@Override
public Alt getAlt( Resource r )
- { return r.as( Alt.class ); }
-
+ { return r.as( Alt.class ); }
+
@Override
public long size()
- { return graph.size(); }
+ { return graph.size(); }
@Override
public boolean isEmpty()
- { return graph.isEmpty(); }
-
+ { return graph.isEmpty(); }
+
private void updateNamespace( Set<String> set, Iterator<Node> it )
- {
+ {
while (it.hasNext())
- {
+ {
Node node = it.next();
if (node.isURI())
- {
+ {
String uri = node.getURI();
String ns = uri.substring( 0, Util.splitNamespace( uri ) );
// String ns = IteratorFactory.asResource( node, this ).getNameSpace();
set.add( ns );
- }
}
}
-
- private Iterator<Node> listPredicates()
- { return getGraph().queryHandler().predicatesFor( Node.ANY, Node.ANY ); }
-
+ }
+
+ private ExtendedIterator<Node> listPredicates()
+ { return GraphUtil.listPredicates(graph, Node.ANY, Node.ANY ); }
+
private Iterator<Node> listTypes()
- {
+ {
Set<Node> types = CollectionFactory.createHashedSet();
ClosableIterator<Triple> it = graph.find( null, RDF.type.asNode(), null );
while (it.hasNext()) types.add( it.next().getObject() );
return types.iterator();
- }
-
+ }
+
@Override
public NsIterator listNameSpaces() {
Set<String> nameSpaces = CollectionFactory.createHashedSet();
@@ -903,646 +905,645 @@ public class ModelCom extends EnhGraph
updateNamespace( nameSpaces, listTypes() );
return new NsIteratorImpl(nameSpaces.iterator(), nameSpaces);
}
-
+
private PrefixMapping getPrefixMapping()
- { return getGraph().getPrefixMapping(); }
-
+ { return getGraph().getPrefixMapping(); }
+
@Override
public boolean samePrefixMappingAs( PrefixMapping other )
- { return getPrefixMapping().samePrefixMappingAs( other ); }
-
+ { return getPrefixMapping().samePrefixMappingAs( other ); }
+
@Override
public PrefixMapping lock()
- {
+ {
getPrefixMapping().lock();
return this;
- }
-
+ }
+
@Override
public PrefixMapping setNsPrefix( String prefix, String uri )
- {
+ {
getPrefixMapping().setNsPrefix( prefix, uri );
return this;
- }
-
+ }
+
@Override
public PrefixMapping removeNsPrefix( String prefix )
- {
+ {
getPrefixMapping().removeNsPrefix( prefix );
return this;
- }
-
+ }
+
@Override
public PrefixMapping setNsPrefixes( PrefixMapping pm )
- {
+ {
getPrefixMapping().setNsPrefixes( pm );
return this;
- }
-
+ }
+
@Override
public PrefixMapping setNsPrefixes( Map<String, String> map )
- {
+ {
getPrefixMapping().setNsPrefixes( map );
return this;
- }
-
+ }
+
@Override
public PrefixMapping withDefaultMappings( PrefixMapping other )
- {
+ {
getPrefixMapping().withDefaultMappings( other );
return this;
- }
-
+ }
+
@Override
public String getNsPrefixURI( String prefix )
- { return getPrefixMapping().getNsPrefixURI( prefix ); }
+ { return getPrefixMapping().getNsPrefixURI( prefix ); }
@Override
public String getNsURIPrefix( String uri )
- { return getPrefixMapping().getNsURIPrefix( uri ); }
-
+ { return getPrefixMapping().getNsURIPrefix( uri ); }
+
@Override
public Map<String, String> getNsPrefixMap()
- { return getPrefixMapping().getNsPrefixMap(); }
-
+ { return getPrefixMapping().getNsPrefixMap(); }
+
@Override
public String expandPrefix( String prefixed )
- { return getPrefixMapping().expandPrefix( prefixed ); }
-
+ { return getPrefixMapping().expandPrefix( prefixed ); }
+
@Override
public String qnameFor( String uri )
- { return getPrefixMapping().qnameFor( uri ); }
-
+ { return getPrefixMapping().qnameFor( uri ); }
+
@Override
public String shortForm( String uri )
- { return getPrefixMapping().shortForm( uri ); }
-
+ { return getPrefixMapping().shortForm( uri ); }
+
/**
Service method to update the namespaces of a Model given the
mappings from prefix names to sets of URIs.
-
+
If the prefix maps to multiple URIs, then we discard it completely.
-
+
@param the Model who's namespace is to be updated
@param ns the namespace map to add to the Model
- */
+ */
public static void addNamespaces( Model m, Map<String, Set<String>> ns )
- {
+ {
PrefixMapping pm = m;
Iterator<Map.Entry<String, Set<String>>> it = ns.entrySet().iterator();
while (it.hasNext())
- {
+ {
Map.Entry<String, Set<String>> e = it.next();
String key = e.getKey();
Set<String> values = e.getValue();
Set<String> niceValues = CollectionFactory.createHashedSet();
Iterator<String> them = values.iterator();
while (them.hasNext())
- {
+ {
String uri = them.next();
if (PrefixMappingImpl.isNiceURI( uri )) niceValues.add( uri );
- }
+ }
if (niceValues.size() == 1)
pm.setNsPrefix( key, niceValues.iterator().next() );
- }
- }
-
+ }
+ }
+
@Override
public StmtIterator listStatements()
- { return IteratorFactory.asStmtIterator( GraphUtil.findAll( graph ), this); }
+ { return IteratorFactory.asStmtIterator( GraphUtil.findAll( graph ), this); }
/**
add a Statement to this Model by adding its SPO components.
- */
+ */
@Override
public Model add( Statement s )
- {
+ {
add( s.getSubject(), s.getPredicate(), s.getObject() );
return this;
- }
-
+ }
+
/**
Add all the statements to the model by converting them to an array of corresponding
triples and removing those from the underlying graph.
- */
+ */
@Override
public Model add( Statement [] statements )
- {
- getBulkUpdateHandler().add( StatementImpl.asTriples( statements ) );
+ {
+ GraphUtil.add(getGraph(), StatementImpl.asTriples( statements ) );
return this;
- }
-
- protected BulkUpdateHandler getBulkUpdateHandler()
- { return getGraph().getBulkUpdateHandler(); }
-
+ }
+
/**
Add all the statements to the model by converting the list to an array of
Statement and removing that.
- */
+ */
@Override
public Model add( List<Statement> statements )
- {
- getBulkUpdateHandler().add( asTriples( statements ) );
+ {
+ GraphUtil.add(getGraph(), asTriples( statements ) );
return this;
- }
-
+ }
+
private List<Triple> asTriples( List<Statement> statements )
- {
+ {
List<Triple> L = new ArrayList<Triple>( statements.size() );
for (int i = 0; i < statements.size(); i += 1)
L.add( statements.get(i).asTriple() );
return L;
- }
-
+ }
+
private Iterator<Triple> asTriples( StmtIterator it )
- { return it.mapWith( mapAsTriple ); }
-
- private Map1<Statement, Triple> mapAsTriple = new Map1<Statement, Triple>()
- { @Override
- public Triple map1( Statement s ) { return s.asTriple(); } };
-
+ { return it.mapWith( mapAsTriple ); }
+
+ private Map1<Statement, Triple> mapAsTriple = new Map1<Statement, Triple>() {
+ @Override
+ public Triple map1( Statement s ) { return s.asTriple(); }
+ };
+
/**
remove all the Statements from the model by converting them to triples and
removing those triples from the underlying graph.
- */
+ */
@Override
public Model remove( Statement [] statements )
- {
- getBulkUpdateHandler().delete( StatementImpl.asTriples( statements ) );
+ {
+ GraphUtil.delete( getGraph(), StatementImpl.asTriples( statements ) );
return this;
- }
-
+ }
+
/**
Remove all the Statements from the model by converting the List to a
List(Statement) and removing that.
- */
+ */
@Override
public Model remove( List<Statement> statements )
- {
- getBulkUpdateHandler().delete( asTriples( statements ) );
+ {
+ GraphUtil.delete( getGraph(), asTriples( statements ) );
return this;
- }
-
+ }
+
@Override
public Model add( Resource s, Property p, RDFNode o ) {
modelReifier.noteIfReified( s, p, o );
graph.add( Triple.create( s.asNode(), p.asNode(), o.asNode() ) );
return this;
}
-
+
@Override
+ @Deprecated
public ReificationStyle getReificationStyle()
- { return modelReifier.getReificationStyle(); }
-
+ { return modelReifier.getReificationStyle(); }
+
/**
@return an iterator which delivers all the ReifiedStatements in this model
- */
+ */
@Override
public RSIterator listReifiedStatements()
- { return modelReifier.listReifiedStatements(); }
+ { return modelReifier.listReifiedStatements(); }
/**
@return an iterator each of whose elements is a ReifiedStatement in this
model such that it's getStatement().equals( st )
- */
+ */
@Override
public RSIterator listReifiedStatements( Statement st )
- { return modelReifier.listReifiedStatements( st ); }
-
+ { return modelReifier.listReifiedStatements( st ); }
+
/**
@return true iff this model has a reification of _s_ in some Statement
- */
+ */
@Override
public boolean isReified( Statement s )
- { return modelReifier.isReified( s ); }
-
+ { return modelReifier.isReified( s ); }
+
/**
get any reification of the given statement in this model; make
one if necessary.
-
+
@param s for which a reification is sought
@return a ReifiedStatement that reifies _s_
- */
+ */
@Override
public Resource getAnyReifiedStatement(Statement s)
- { return modelReifier.getAnyReifiedStatement( s ); }
-
+ { return modelReifier.getAnyReifiedStatement( s ); }
+
/**
remove any ReifiedStatements reifying the given statement
@param s the statement who's reifications are to be discarded
- */
+ */
@Override
public void removeAllReifications( Statement s )
- { modelReifier.removeAllReifications( s ); }
-
+ { modelReifier.removeAllReifications( s ); }
+
@Override
public void removeReification( ReifiedStatement rs )
- { modelReifier.removeReification( rs ); }
-
+ { modelReifier.removeReification( rs ); }
+
/**
create a ReifiedStatement that encodes _s_ and belongs to this Model.
- */
+ */
@Override
public ReifiedStatement createReifiedStatement( Statement s )
- { return modelReifier.createReifiedStatement( s ); }
-
+ { return modelReifier.createReifiedStatement( s ); }
+
@Override
public ReifiedStatement createReifiedStatement( String uri, Statement s )
- { return modelReifier.createReifiedStatement( uri, s ); }
-
+ { return modelReifier.createReifiedStatement( uri, s ); }
+
@Override
public boolean contains( Statement s )
- { return graph.contains( s.asTriple() ); }
-
+ { return graph.contains( s.asTriple() ); }
+
@Override
public boolean containsResource( RDFNode r )
- { return graph.queryHandler().containsNode( r.asNode() ); }
+ { return GraphUtil.containsNode( graph, r.asNode() ); }
@Override
public boolean contains( Resource s, Property p )
- { return contains( s, p, (RDFNode) null ); }
-
+ { return contains( s, p, (RDFNode) null ); }
+
@Override
public boolean contains( Resource s, Property p, RDFNode o )
- { return graph.contains( asNode( s ), asNode( p ), asNode( o ) ); }
-
+ { return graph.contains( asNode( s ), asNode( p ), asNode( o ) ); }
+
@Override
public Statement getRequiredProperty( Resource s, Property p )
- { Statement st = getProperty( s, p );
- if (st == null) throw new PropertyNotFoundException( p );
- return st; }
-
+ { Statement st = getProperty( s, p );
+ if (st == null) throw new PropertyNotFoundException( p );
+ return st; }
+
@Override
public Statement getProperty( Resource s, Property p )
- {
+ {
StmtIterator iter = listStatements( s, p, (RDFNode) null );
try { return iter.hasNext() ? iter.nextStatement() : null; }
finally { iter.close(); }
- }
-
+ }
+
public static Node asNode( RDFNode x )
- { return x == null ? Node.ANY : x.asNode(); }
-
+ { return x == null ? Node.ANY : x.asNode(); }
+
private NodeIterator listObjectsFor( RDFNode s, RDFNode p )
- {
- ClosableIterator<Node> xit = graph.queryHandler().objectsFor( asNode( s ), asNode( p ) );
+ {
+ ClosableIterator<Node> xit = GraphUtil.listObjects(graph, asNode( s ), asNode( p ) ) ;
return IteratorFactory.asRDFNodeIterator( xit, this );
- }
+ }
private ResIterator listSubjectsFor( RDFNode p, RDFNode o )
- {
- ClosableIterator<Node> xit = graph.queryHandler().subjectsFor( asNode( p ), asNode( o ) );
+ {
+ ClosableIterator<Node> xit = GraphUtil.listSubjects( graph, asNode( p ), asNode( o ) );
return IteratorFactory.asResIterator( xit, this );
- }
-
+ }
+
@Override
public ResIterator listSubjects()
- { return listSubjectsFor( null, null ); }
-
+ { return listSubjectsFor( null, null ); }
+
@Override
public ResIterator listResourcesWithProperty(Property p)
- { return listSubjectsFor( p, null ); }
-
+ { return listSubjectsFor( p, null ); }
+
@Override
public ResIterator listSubjectsWithProperty(Property p)
- { return listResourcesWithProperty( p ); }
-
+ { return listResourcesWithProperty( p ); }
+
@Override
public ResIterator listResourcesWithProperty(Property p, RDFNode o)
- { return listSubjectsFor( p, o ); }
-
+ { return listSubjectsFor( p, o ); }
+
@Override
public NodeIterator listObjects()
- { return listObjectsFor( null, null ); }
-
+ { return listObjectsFor( null, null ); }
+
@Override
public NodeIterator listObjectsOfProperty(Property p)
- { return listObjectsFor( null, p ); }
-
+ { return listObjectsFor( null, p ); }
+
@Override
public NodeIterator listObjectsOfProperty(Resource s, Property p)
- { return listObjectsFor( s, p ); }
-
+ { return listObjectsFor( s, p ); }
+
@Override
public StmtIterator listStatements( final Selector selector )
- {
+ {
StmtIterator sts = IteratorFactory.asStmtIterator( findTriplesFrom( selector ), this );
return selector.isSimple()
? sts
: new StmtIteratorImpl( sts .filterKeep ( asFilter( selector ) ) )
- ;
- }
-
+ ;
+ }
+
/**
Answer a Filter that filters exactly those things the Selector selects.
-
+
@param s a Selector on statements
@return a Filter that accepts statements that s passes tests on
- */
- public Filter<Statement> asFilter( final Selector s )
- { return new Filter<Statement>()
- { @Override public boolean accept( Statement x ) { return s.test( x ); } };
- }
-
-
- /**
+ */
+ public Filter<Statement> asFilter( final Selector s )
+ { return new Filter<Statement>()
+ { @Override public boolean accept( Statement x ) { return s.test( x ); } };
+ }
+
+
+ /**
Answer an [extended] iterator which returns the triples in this graph which
are selected by the (S, P, O) triple in the selector, ignoring any special
tests it may do.
-
+
@param s a Selector used to supply subject, predicate, and object
@return an extended iterator over the matching (S, P, O) triples
- */
- public ExtendedIterator<Triple> findTriplesFrom( Selector s )
- {
- return graph.find
- ( asNode( s.getSubject() ), asNode( s.getPredicate() ), asNode( s.getObject() ) );
- }
+ */
+ public ExtendedIterator<Triple> findTriplesFrom( Selector s )
+ {
+ return graph.find
+ ( asNode( s.getSubject() ), asNode( s.getPredicate() ), asNode( s.getObject() ) );
+ }
+
+ @Override
+ public boolean supportsTransactions()
+ { return getTransactionHandler().transactionsSupported(); }
+
+ @Override
+ public Model begin()
+ { getTransactionHandler().begin(); return this; }
+
+ @Override
+ public Model abort()
+ { getTransactionHandler().abort(); return this; }
+
+ @Override
+ public Model commit()
+ { getTransactionHandler().commit(); return this; }
+
+ @Override
+ public Object executeInTransaction( Command cmd )
+ { return getTransactionHandler().executeInTransaction( cmd ); }
+
+ private TransactionHandler getTransactionHandler()
+ { return getGraph().getTransactionHandler(); }
+
+ @Override
+ public boolean independent()
+ { return true; }
+
+ @Override
+ public Resource createResource()
+ { return IteratorFactory.asResource( Node.createAnon(),this ); }
+
+ @Override
+ public Resource createResource( String uri )
+ { return getResource( uri ); }
+
+ @Override
+ public Property createProperty( String uri )
+ { return getProperty( uri ); }
+
+ @Override
+ public Property createProperty(String nameSpace, String localName)
+ { return getProperty(nameSpace, localName); }
- @Override
- public boolean supportsTransactions()
- { return getTransactionHandler().transactionsSupported(); }
-
- @Override
- public Model begin()
- { getTransactionHandler().begin(); return this; }
-
- @Override
- public Model abort()
- { getTransactionHandler().abort(); return this; }
-
- @Override
- public Model commit()
- { getTransactionHandler().commit(); return this; }
-
- @Override
- public Object executeInTransaction( Command cmd )
- { return getTransactionHandler().executeInTransaction( cmd ); }
-
- private TransactionHandler getTransactionHandler()
- { return getGraph().getTransactionHandler(); }
-
- @Override
- public boolean independent()
- { return true; }
-
- @Override
- public Resource createResource()
- { return IteratorFactory.asResource( Node.createAnon(),this ); }
-
- @Override
- public Resource createResource( String uri )
- { return getResource( uri ); }
-
- @Override
- public Property createProperty( String uri )
- { return getProperty( uri ); }
-
- @Override
- public Property createProperty(String nameSpace, String localName)
- { return getProperty(nameSpace, localName); }
-
- /**
+ /**
create a Statement from the given r, p, and o.
- */
- @Override
- public Statement createStatement(Resource r, Property p, RDFNode o)
- { return new StatementImpl( r, p, o, this ); }
-
- @Override
- public Bag createBag(String uri)
- { return (Bag) getBag(uri).addProperty( RDF.type, RDF.Bag ); }
-
- @Override
- public Alt createAlt( String uri )
- { return (Alt) getAlt(uri).addProperty( RDF.type, RDF.Alt ); }
-
- @Override
- public Seq createSeq(String uri)
- { return (Seq) getSeq(uri).addProperty( RDF.type, RDF.Seq ); }
+ */
+ @Override
+ public Statement createStatement(Resource r, Property p, RDFNode o)
+ { return new StatementImpl( r, p, o, this ); }
+
+ @Override
+ public Bag createBag(String uri)
+ { return (Bag) getBag(uri).addProperty( RDF.type, RDF.Bag ); }
+
+ @Override
+ public Alt createAlt( String uri )
+ { return (Alt) getAlt(uri).addProperty( RDF.type, RDF.Alt ); }
+
+ @Override
+ public Seq createSeq(String uri)
+ { return (Seq) getSeq(uri).addProperty( RDF.type, RDF.Seq ); }
- /**
+ /**
Answer a Statement in this Model whcih encodes the given Triple.
@param t a triple to wrap as a statement
@return a statement wrapping the triple and in this model
- */
- @Override
- public Statement asStatement( Triple t )
- { return StatementImpl.toStatement( t, this ); }
-
- public Statement [] asStatements( Triple [] triples )
- {
- Statement [] result = new Statement [triples.length];
- for (int i = 0; i < triples.length; i += 1) result[i] = asStatement( triples[i] );
- return result;
- }
-
- public List<Statement> asStatements( List<Triple> triples )
- {
- List<Statement> L = new ArrayList<Statement>( triples.size() );
- for (int i = 0; i < triples.size(); i += 1) L.add( asStatement( triples.get(i) ) );
- return L;
- }
-
- public Model asModel( Graph g )
- { return new ModelCom( g ); }
-
- public StmtIterator asStatements( final Iterator<Triple> it )
- { return new StmtIteratorImpl( new Map1Iterator<Triple, Statement>( mapAsStatement, it ) ); }
-
- protected Map1<Triple, Statement> mapAsStatement = new Map1<Triple, Statement>()
- { @Override
- public Statement map1( Triple t ) { return asStatement( t ); } };
-
- public StmtIterator listBySubject( Container cont )
- { return listStatements( cont, null, (RDFNode) null ); }
+ */
+ @Override
+ public Statement asStatement( Triple t )
+ { return StatementImpl.toStatement( t, this ); }
+
+ public Statement [] asStatements( Triple [] triples )
+ {
+ Statement [] result = new Statement [triples.length];
+ for (int i = 0; i < triples.length; i += 1) result[i] = asStatement( triples[i] );
+ return result;
+ }
+
+ public List<Statement> asStatements( List<Triple> triples )
+ {
+ List<Statement> L = new ArrayList<Statement>( triples.size() );
+ for (int i = 0; i < triples.size(); i += 1) L.add( asStatement( triples.get(i) ) );
+ return L;
+ }
+
+ public Model asModel( Graph g )
+ { return new ModelCom( g ); }
+
+ public StmtIterator asStatements( final Iterator<Triple> it )
+ { return new StmtIteratorImpl( new Map1Iterator<Triple, Statement>( mapAsStatement, it ) ); }
+
+ protected Map1<Triple, Statement> mapAsStatement = new Map1<Triple, Statement>()
+ { @Override
+ public Statement map1( Triple t ) { return asStatement( t ); } };
+
+ public StmtIterator listBySubject( Container cont )
+ { return listStatements( cont, null, (RDFNode) null ); }
+
+ @Override
+ public void close()
+ { graph.close(); }
+
+ @Override
+ public boolean isClosed()
+ { return graph.isClosed(); }
+
+ @Override
+ public boolean supportsSetOperations()
+ {return true;}
+
+ @Override
+ public Model query( Selector selector )
+ { return createWorkModel() .add( listStatements( selector ) ); }
+
+ @Override
+ public Model union( Model model )
+ { return createWorkModel() .add(this) .add( model ); }
- @Override
- public void close()
- { graph.close(); }
-
- @Override
- public boolean isClosed()
- { return graph.isClosed(); }
-
- @Override
- public boolean supportsSetOperations()
- {return true;}
-
- @Override
- public Model query( Selector selector )
- { return createWorkModel() .add( listStatements( selector ) ); }
-
- @Override
- public Model union( Model model )
- { return createWorkModel() .add(this) .add( model ); }
-
- /**
+ /**
Intersect this with another model. As an attempt at optimisation, we try and ensure
we iterate over the smaller model first. Nowadays it's not clear that this is a good
idea, since <code>size()</code> can be expensive on database and inference
models.
-
+
@see com.hp.hpl.jena.rdf.model.Model#intersection(com.hp.hpl.jena.rdf.model.Model)
- */
- @Override
- public Model intersection( Model other )
- { return this.size() < other.size() ? intersect( this, other ) : intersect( other, this ); }
-
- /**
+ */
+ @Override
+ public Model intersection( Model other )
+ { return this.size() < other.size() ? intersect( this, other ) : intersect( other, this ); }
+
+ /**
Answer a Model that is the intersection of the two argument models. The first
argument is the model iterated over, and the second argument is the one used
to check for membership. [So the first one should be "small" and the second one
"membership cheap".]
- */
- public static Model intersect( Model smaller, Model larger )
- {
- Model result = createWorkModel();
- StmtIterator it = smaller.listStatements();
- try { return addCommon( result, it, larger ); }
- finally { it.close(); }
- }
-
- /**
+ */
+ public static Model intersect( Model smaller, Model larger )
+ {
+ Model result = createWorkModel();
+ StmtIterator it = smaller.listStatements();
+ try { return addCommon( result, it, larger ); }
+ finally { it.close(); }
+ }
+
+ /**
Answer the argument result with all the statements from the statement iterator that
are in the other model added to it.
-
+
@param result the Model to add statements to and return
@param it an iterator over the candidate statements
@param other the model that must contain the statements to be added
@return result, after the suitable statements have been added to it
- */
- protected static Model addCommon( Model result, StmtIterator it, Model other )
- {
- while (it.hasNext())
- {
- Statement s = it.nextStatement();
- if (other.contains( s )) result.add( s );
- }
- return result;
- }
-
- @Override
- public Model difference(Model model) {
- Model resultModel = createWorkModel();
- StmtIterator iter = null;
- Statement stmt;
- try {
- iter = listStatements();
- while (iter.hasNext()) {
- stmt = iter.nextStatement();
- if (! model.contains(stmt)) {
- resultModel.add(stmt);
- }
- }
- return resultModel;
- } finally {
- if (null != iter) {
- iter.close();
- }
- }
- }
-
- @Override
- public String toString()
- { return "<ModelCom " + getGraph() + " | " + reifiedToString() + ">"; }
-
- public String reifiedToString()
- { return statementsToString( getHiddenStatements().listStatements() ); }
-
- protected String statementsToString( StmtIterator it )
- {
- StringBuffer b = new StringBuffer();
- while (it.hasNext()) b.append( " " ).append( it.nextStatement() );
- return b.toString();
- }
- /**
+ */
+ protected static Model addCommon( Model result, StmtIterator it, Model other )
+ {
+ while (it.hasNext())
+ {
+ Statement s = it.nextStatement();
+ if (other.contains( s )) result.add( s );
+ }
+ return result;
+ }
+
+ @Override
+ public Model difference(Model model) {
+ Model resultModel = createWorkModel();
+ StmtIterator iter = null;
+ Statement stmt;
+ try {
+ iter = listStatements();
+ while (iter.hasNext()) {
+ stmt = iter.nextStatement();
+ if (! model.contains(stmt)) {
+ resultModel.add(stmt);
+ }
+ }
+ return resultModel;
+ } finally {
+ if (null != iter) {
+ iter.close();
+ }
+ }
+ }
+
+ @Override
+ public String toString()
+ { return "<ModelCom " + getGraph() + " | " + reifiedToString() + ">"; }
+
+ public String reifiedToString()
+ { return statementsToString( getHiddenStatements().listStatements() ); }
+
+ protected String statementsToString( StmtIterator it )
+ {
+ StringBuffer b = new StringBuffer();
+ while (it.hasNext()) b.append( " " ).append( it.nextStatement() );
+ return b.toString();
+ }
+ /**
a read-only Model with all the statements of this Model and any
statements "hidden" by reification. That model is dynamic, ie
any changes this model will be reflected that one.
- */
- public Model getHiddenStatements()
- { return modelReifier.getHiddenStatements(); }
-
- /**
+ */
+ public Model getHiddenStatements()
+ { return modelReifier.getHiddenStatements(); }
+
+ /**
Answer whether or not these two graphs are isomorphic, taking the
hidden (reification) statements into account.
- */
- @Override
- public boolean isIsomorphicWith( Model m )
- {
- Graph L = ModelFactory.withHiddenStatements( this ).getGraph();
- Graph R = ModelFactory.withHiddenStatements( m ).getGraph();
- return L.isIsomorphicWith( R );
- }
-
- public synchronized Lock getModelLock()
- {
- if ( modelLock == null )
- modelLock = new LockMRSW() ;
- return modelLock ;
- }
-
- @Override
- public synchronized Lock getLock()
- {
- return getModelLock() ;
- }
-
-
- @Override
- public void enterCriticalSection(boolean requestReadLock)
- {
- this.getModelLock().enterCriticalSection(requestReadLock) ;
- }
-
- @Override
- public void leaveCriticalSection()
- {
- this.getModelLock().leaveCriticalSection() ;
- }
-
- /**
+ */
+ @Override
+ public boolean isIsomorphicWith( Model m )
+ {
+ Graph L = ModelFactory.withHiddenStatements( this ).getGraph();
+ Graph R = ModelFactory.withHiddenStatements( m ).getGraph();
+ return L.isIsomorphicWith( R );
+ }
+
+ public synchronized Lock getModelLock()
+ {
+ if ( modelLock == null )
+ modelLock = new LockMRSW() ;
+ return modelLock ;
+ }
+
+ @Override
+ public synchronized Lock getLock()
+ {
+ return getModelLock() ;
+ }
+
+
+ @Override
+ public void enterCriticalSection(boolean requestReadLock)
+ {
+ this.getModelLock().enterCriticalSection(requestReadLock) ;
+ }
+
+ @Override
+ public void leaveCriticalSection()
+ {
+ this.getModelLock().leaveCriticalSection() ;
+ }
+
+ /**
Register the listener with this model by registering its GraphListener
adaption with the underlying Graph.
-
+
@param a ModelChangedListener to register for model events
@return this model, for cascading
- */
- @Override
- public Model register( ModelChangedListener listener )
- {
- getGraph().getEventManager().register( adapt( listener ) );
- return this;
- }
-
- /**
+ */
+ @Override
+ public Model register( ModelChangedListener listener )
+ {
+ getGraph().getEventManager().register( adapt( listener ) );
+ return this;
+ }
+
+ /**
Unregister the listener from this model by unregistering its GraphListener
adaption from the underlying Graph.
@param a ModelChangedListener to unregister from model events
@return this model, for cascading
- */
- @Override
- public Model unregister( ModelChangedListener listener )
- {
- getGraph().getEventManager().unregister( adapt( listener ) );
- return this;
- }
-
- /**
+ */
+ @Override
+ public Model unregister( ModelChangedListener listener )
+ {
+ getGraph().getEventManager().unregister( adapt( listener ) );
+ return this;
+ }
+
+ /**
Answer a GraphListener that, when fed graph-level update events,
fires the corresponding model-level event handlers in <code>L</code>.
@see ModelListenerAdapter
@param L a model listener to be wrapped as a graph listener
@return a graph listener wrapping L
- */
- public GraphListener adapt( final ModelChangedListener L )
- { return new ModelListenerAdapter( this, L ); }
-
- @Override
- public Model notifyEvent( Object e )
- {
- getGraph().getEventManager().notifyEvent( getGraph(), e );
- return this;
- }
- }
+ */
+ public GraphListener adapt( final ModelChangedListener L )
+ { return new ModelListenerAdapter( this, L ); }
+
+ @Override
+ public Model notifyEvent( Object e )
+ {
+ getGraph().getEventManager().notifyEvent( getGraph(), e );
+ return this;
+ }
+}
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelReifier.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelReifier.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelReifier.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ModelReifier.java Mon Dec 10 17:25:00 2012
@@ -28,13 +28,10 @@ import com.hp.hpl.jena.util.iterator.*;
/**
This class impedance-matches the reification requests of Model[Com] to the operations
supplied by it's Graph's Reifier.
-
- @author kers
*/
public class ModelReifier
{
private ModelCom model;
- public Reifier reifier;
/**
DEVEL. setting this _true_ means that nodes that reify statements
@@ -50,11 +47,11 @@ public class ModelReifier
public ModelReifier( ModelCom model )
{
this.model = model;
- this.reifier = model.asGraph().getReifier();
}
+ @Deprecated
public ReificationStyle getReificationStyle()
- { return reifier.getStyle(); }
+ { return ReificationStyle.Standard ; }
/**
Answer a version of the model, but with all its reifiying statements
@@ -74,15 +71,14 @@ public class ModelReifier
@return
*/
protected static Graph getHiddenTriples( Model m )
- {
- Graph mGraph = m.getGraph();
- final Reifier r = mGraph.getReifier();
+ {
+ final Graph mGraph = m.getGraph();
return new GraphBase()
- {
+ {
@Override public ExtendedIterator<Triple> graphBaseFind( TripleMatch m )
- { return r.findEither( m, true ); }
- };
- }
+ { return ReifierStd.findEither(mGraph, m, true ); }
+ };
+ }
/**
Answer a model that consists of the hidden reification statements of this model.
@@ -131,7 +127,7 @@ public class ModelReifier
@return true iff s has a reification in this model
*/
public boolean isReified( FrontsTriple s )
- { return reifier.hasTriple( s.asTriple() ); }
+ { return ReifierStd.hasTriple(model.getGraph(), s.asTriple() ); }
/**
Remove all the reifications of a given statement in this model, whatever
@@ -139,7 +135,7 @@ public class ModelReifier
@param s the statement whose reifications are to be removed
*/
public void removeAllReifications( FrontsTriple s )
- { reifier.remove( s.asTriple() ); }
+ { ReifierStd.remove( model.getGraph(), s.asTriple() ); }
/**
Remove a given reification from this model. Other reifications of the same statement
@@ -147,7 +143,7 @@ public class ModelReifier
@param rs the reified statement to be removed
*/
public void removeReification( ReifiedStatement rs )
- { reifier.remove( rs.asNode(), rs.getStatement().asTriple() ); }
+ { ReifierStd.remove( model.getGraph(), rs.asNode(), rs.getStatement().asTriple() ); }
/**
Answer an iterator that iterates over all the reified statements
@@ -204,10 +200,10 @@ public class ModelReifier
};
private ExtendedIterator<ReifiedStatement> findReifiedStatements()
- { return reifier .allNodes() .mapWith( mapToRS ); }
+ { return ReifierStd .allNodes(model.getGraph()) .mapWith( mapToRS ); }
private ExtendedIterator<ReifiedStatement> findReifiedStatements( Triple t )
- { return reifier .allNodes( t ) .mapWith( mapToRS ); }
+ { return ReifierStd .allNodes(model.getGraph(), t ) .mapWith( mapToRS ); }
/**
Answer a ReifiedStatement that is based on the given node.
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ReifiedStatementImpl.java Mon Dec 10 17:25:00 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 ) );
}
}
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/BaseInfGraph.java Mon Dec 10 17:25:00 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
{
@@ -129,7 +109,13 @@ public abstract class BaseInfGraph exten
public boolean findContractSafe() { return true; }
}
+ /**
+ @deprecated Bulk update operations are going to be removed.
+ @see GraphUtil for convenience helpers.
+ */
+
@Override
+ @Deprecated
public BulkUpdateHandler getBulkUpdateHandler()
{
if (bulkHandler == null) bulkHandler = new InfBulkUpdateHandler( this );
@@ -139,8 +125,6 @@ public abstract class BaseInfGraph exten
/**
InfBulkUpdateHandler - a bulk update handler specialised for inference
graphs by code for <code>removeAll()</code>.
-
- @author kers
*/
static class InfBulkUpdateHandler extends SimpleBulkUpdateHandler
{
@@ -148,26 +132,47 @@ public abstract class BaseInfGraph exten
{ super(graph); }
@Override
+ @Deprecated
public void remove( Node s, Node p, Node o )
{
BaseInfGraph g = (BaseInfGraph) graph;
- g.getRawGraph().getBulkUpdateHandler().remove( s, p, o );
+ g.getRawGraph().remove( s, p, o );
g.discardState();
g.rebind();
manager.notifyEvent( graph, GraphEvents.remove( s, p, o ) );
}
@Override
+ @Deprecated
public void removeAll()
{
BaseInfGraph g = (BaseInfGraph) graph;
- g.getRawGraph().getBulkUpdateHandler().removeAll();
+ g.getRawGraph().clear();
g.discardState();
g.rebind();
g.getEventManager().notifyEvent( g, GraphEvents.removeAll );
}
}
+
+ @Override
+ public void remove( Node s, Node p, Node o )
+ {
+ getRawGraph().remove( s, p, o );
+ discardState();
+ rebind();
+ getEventManager().notifyEvent( this, GraphEvents.remove( s, p, o ) );
+ }
+
+ @Override
+ public void clear()
+ {
+ getRawGraph().clear() ;
+ discardState();
+ rebind();
+ getEventManager().notifyEvent( this, GraphEvents.removeAll );
+ }
+
@Override
public TransactionHandler getTransactionHandler()
{ return new InfTransactionHandler( this ); }
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/BasicForwardRuleInfGraph.java Mon Dec 10 17:25:00 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
@@ -417,11 +413,11 @@ public class BasicForwardRuleInfGraph ex
Graph dg = fdeductions.getGraph();
if (dg != null) {
// Reuse the old graph in order to preserve any listeners
- safeDeductions.getBulkUpdateHandler().removeAll();
+ safeDeductions.clear();
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/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleInfGraph.java Mon Dec 10 17:25:00 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 );
}
@@ -407,7 +409,7 @@ public class FBRuleInfGraph extends Bas
// initilize the deductions graph
if (fdeductions != null) {
Graph oldDeductions = (fdeductions).getGraph();
- oldDeductions.getBulkUpdateHandler().removeAll();
+ oldDeductions.clear();
} else {
fdeductions = new FGraph( createDeductionsGraph() );
}
Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java?rev=1419595&r1=1419594&r2=1419595&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/reasoner/rulesys/FBRuleReasoner.java Mon Dec 10 17:25:00 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 );