📄 modelcom.java
字号:
{
ClosableIterator xit = graph.queryHandler().subjectsFor( asNode( p ), asNode( o ) );
return IteratorFactory.asResIterator( xit, this );
}
public ResIterator listSubjects()
{ return listSubjectsFor( null, null ); }
public ResIterator listSubjectsWithProperty(Property p)
{ return listSubjectsFor( p, null ); }
public ResIterator listSubjectsWithProperty(Property p, RDFNode o)
{ return listSubjectsFor( p, o ); }
public NodeIterator listObjects()
{ return listObjectsFor( null, null ); }
public NodeIterator listObjectsOfProperty(Property p)
{ return listObjectsFor( null, p ); }
public NodeIterator listObjectsOfProperty(Resource s, Property p)
{ return listObjectsFor( s, p ); }
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 asFilter( final Selector s )
{ return new Filter()
{ public boolean accept( Object x ) { return s.test( (Statement) 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 findTriplesFrom( Selector s )
{
return graph.find
( asNode( s.getSubject() ), asNode( s.getPredicate() ), asNode( s.getObject() ) );
}
public boolean supportsTransactions()
{ return getTransactionHandler().transactionsSupported(); }
public Model begin()
{ getTransactionHandler().begin(); return this; }
public Model abort()
{ getTransactionHandler().abort(); return this; }
public Model commit()
{ getTransactionHandler().commit(); return this; }
public Object executeInTransaction( Command cmd )
{ return getTransactionHandler().executeInTransaction( cmd ); }
private TransactionHandler getTransactionHandler()
{ return getGraph().getTransactionHandler(); }
public boolean independent()
{ return true; }
public Resource createResource()
{ return IteratorFactory.asResource( Node.createAnon(),this ); }
public Resource createResource( String uri )
{ return getResource( uri ); }
public Property createProperty( String uri )
{ return getProperty( uri ); }
public Property createProperty(String nameSpace, String localName)
{ return getProperty(nameSpace, localName); }
/**
create a Statement from the given r, p, and o.
*/
public Statement createStatement(Resource r, Property p, RDFNode o)
{ return new StatementImpl( r, p, o, this ); }
public Bag createBag(String uri)
{ return (Bag) getBag(uri).addProperty( RDF.type, RDF.Bag ); }
public Alt createAlt( String uri )
{ return (Alt) getAlt(uri).addProperty( RDF.type, RDF.Alt ); }
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
*/
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 asStatements( List triples )
{
List L = new ArrayList( triples.size() );
for (int i = 0; i < triples.size(); i += 1) L.add( asStatement( (Triple) triples.get(i) ) );
return L;
}
public Model asModel( Graph g )
{ return new ModelCom( g ); }
public StmtIterator asStatements( final Iterator it )
{ return new StmtIteratorImpl( new Map1Iterator( mapAsStatement, it ) ); }
protected Map1 mapAsStatement = new Map1()
{ public Object map1( Object t ) { return asStatement( (Triple) t ); } };
public StmtIterator listBySubject( Container cont )
{ return listStatements( cont, null, (RDFNode) null ); }
public void close()
{ graph.close(); }
public boolean isClosed()
{ return graph.isClosed(); }
public boolean supportsSetOperations()
{return true;}
public Model query( Selector selector )
{ return createWorkModel() .add( listStatements( selector ) ); }
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)
*/
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(); }
}
/**
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;
}
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 {
iter.close();
}
}
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(); }
/**
Answer whether or not these two graphs are isomorphic, taking the
hidden (reification) statements into account.
*/
public boolean isIsomorphicWith( Model m )
{
Graph L = ModelFactory.withHiddenStatements( this ).getGraph();
Graph R = ModelFactory.withHiddenStatements( m ).getGraph();
return L.isIsomorphicWith( R );
}
public synchronized ModelLock getModelLock()
{
if ( modelLock == null )
modelLock = new ModelLockImpl() ;
return modelLock ;
}
public synchronized Lock getLock()
{
return getModelLock() ;
}
public void enterCriticalSection(boolean requestReadLock)
{
this.getModelLock().enterCriticalSection(requestReadLock) ;
}
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
*/
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
*/
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 ); }
public Model notifyEvent( Object e )
{
getGraph().getEventManager().notifyEvent( getGraph(), e );
return this;
}
}
/*
* (c) Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Model.java
*
* Created on 11 March 2001, 16:07
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -