📄 specializedgraphreifier_rdb.java
字号:
ResultSetReifIterator it = m_reif.findFrag(stmtURI, frag, fragMask, my_GID);
if ( it.hasNext() ) {
if ( it.getFragCount() == 1 ) {
/* last fragment in this tuple; can just delete it */
m_reif.deleteFrag(frag, fragMask, my_GID);
it.close();
} else {
/* remove fragment from row */
m_reif.nullifyFrag(stmtURI, fragMask, my_GID);
/* compact remaining fragments, if possible */
it.close();
fragCompact(stmtURI);
}
// remove cache entry, if any
ReificationCache cachedFrag = m_reifCache.lookup(stmtURI);
if ( cachedFrag != null ) m_reifCache.flush(cachedFrag);
}
complete.setDone();
}
/* fragCompact
*
* Compact fragments for a given statement URI.
*
* first, find the unique row for stmtURI that with the HasType Statement fragment.
* if no such row exists, we are done. then, get all fragments for stmtURI and
* try to merge them with the hasType fragment, deleting each as they are merged.
*/
protected void fragCompact ( Node stmtURI ) {
ResultSetReifIterator itHasType;
Triple t;
itHasType = m_reif.findReifStmt(stmtURI,true,my_GID, false);
if ( itHasType.hasNext() ) {
/* something to do */
t = (Triple) itHasType.next();
if ( itHasType.hasNext() )
throw new JenaException("Multiple HasType fragments for URI");
ReificationStatementMask htMask = new ReificationStatementMask(t);
itHasType.close();
// now, look at fragments and try to merge them with the hasType fragement
ResultSetReifIterator itFrag = m_reif.findReifStmt(stmtURI,false,my_GID, false);
ReificationStatementMask upMask = new ReificationStatementMask();
while ( itFrag.hasNext() ) {
t = (Triple) itFrag.next();
if ( itFrag.getHasType() ) continue;
ReificationStatementMask fm = new ReificationStatementMask(rowToFrag(stmtURI, t));
if ( htMask.hasIntersect(fm) )
break; // can't merge all fragments
// at this point, we can merge in the current fragment
m_reif.updateFrag(stmtURI, t, fm, my_GID);
htMask.setMerge(fm);
m_reif.deleteFrag(t, fm, my_GID);
}
}
}
protected Triple rowToFrag ( Node stmtURI, Triple row )
{
Node pred = null;
Node obj = null;
int valCnt = 0;
if ( row.getSubject() != null ) {
obj = row.getSubject();
pred = RDF.Nodes.subject;
valCnt++;
}
if ( row.getPredicate() != null ) {
obj = row.getPredicate();
pred = RDF.Nodes.predicate;
valCnt++;
}
if ( row.getObject() != null ) {
obj = row.getObject();
pred = RDF.Nodes.object;
valCnt++;
}
if ( valCnt != 1 )
throw new JenaException("Partially reified row must have exactly one value");
return Triple.create(stmtURI, pred, obj);
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#add(java.util.List, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
*/
public void add(List triples, CompletionFlag complete) {
ArrayList remainingTriples = new ArrayList();
for( int i=0; i< triples.size(); i++) {
CompletionFlag partialResult = newComplete();
add( (Triple)triples.get(i), partialResult);
if( !partialResult.isDone())
remainingTriples.add(triples.get(i));
}
triples.clear();
if( remainingTriples.isEmpty())
complete.setDone();
else
triples.addAll(remainingTriples);
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#delete(java.util.List, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
*/
public void delete(List triples, CompletionFlag complete) {
boolean result = true;
Iterator it = triples.iterator();
while(it.hasNext()) {
CompletionFlag partialResult = newComplete();
delete( (Triple)it.next(), partialResult);
result = result && partialResult.isDone();
}
if( result )
complete.setDone();
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#tripleCount()
*/
public int tripleCount() {
// A very inefficient, but simple implementation
ExtendedIterator it = find( null, null, null, newComplete() );
int count = 0;
while (it.hasNext()) {
it.next(); count++;
}
it.close();
return count;
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#find(com.hp.hpl.jena.graph.TripleMatch, com.hp.hpl.jena.db.impl.SpecializedGraph.CompletionFlag)
*/
public ExtendedIterator find(TripleMatch t, CompletionFlag complete) {
// Node stmtURI = t.getMatchSubject(); // note: can be null
// ResultSetReifIterator it = m_reif.findReifStmt(stmtURI, false, my_GID, true);
// return it.filterKeep( new TripleMatchFilter( t.asTriple() ) );
ResultSetReifIterator it = m_reif.findReifTripleMatch(t, my_GID);
return it;
}
/**
* Tests if a triple is contained in the specialized graph.
* @param t is the triple to be tested
* @param complete is true if the graph can guarantee that
* no other specialized graph could hold any matching triples.
* @return boolean result to indicate if the triple was contained
*/
public boolean contains(Triple t, CompletionFlag complete) {
// A very inefficient, but simple implementation
ExtendedIterator it = find( t, complete );
try { return it.hasNext(); } finally { it.close(); }
}
/*
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#close()
*/
public void close() {
m_reif.close();
}
/*
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#clear()
*/
public void clear() {
m_reif.removeStatementsFromDB(my_GID);
}
static boolean isReifProp ( Node_URI p ) {
return p.equals(RDF.Nodes.subject) ||
p.equals(RDF.Nodes.predicate)||
p.equals(RDF.Nodes.object) ||
p.equals(RDF.Nodes.type);
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#graphIdGet()
*/
public int getGraphId() {
return ((DBIDInt)my_GID).getIntID();
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#PSetGet()
*/
public IPSet getPSet() {
return m_pset;
}
/* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraphReifier#DBPropLSetGet()
*/
public DBPropLSet getDBPropLSet() {
return m_dbPropLSet;
}
/*
* (non-Javadoc)
* @see com.hp.hpl.jena.db.impl.SpecializedGraph#subsumes(com.hp.hpl.jena.graph.Triple, int)
*
* determine if the reifier graph has any triples of the given pattern.
* the table below indicates the return value for each reif style for
* the various types of patterns.
* note: "conc" means the node in the pattern is not a concrete node.
*
* Pattern Minimal Conv Standard
* ANY rdf:subj ANY none none all
* ANY rdf:pred ANY none none all
* ANY rdf:obj ANY none none all
* ANY rdf:type rdf:stmt none none all
* ANY rdf:type conc none none none
* ANY rdf:type !conc none none some
* ANY !conc ANY none none some
* else none none none
*/
public char subsumes ( Triple pattern, int reifBehavior ) {
char res = noTriplesForPattern;
if ( reifBehavior != GraphRDB.OPTIMIZE_ALL_REIFICATIONS_AND_HIDE_NOTHING )
return res;
Node pred = pattern.getPredicate();
if ( pred.isConcrete() ) {
if ( pred.equals(RDF.Nodes.subject) ||
pred.equals(RDF.Nodes.predicate) ||
pred.equals(RDF.Nodes.object) )
res = allTriplesForPattern;
else if ( pred.equals(RDF.Nodes.type) ) {
Node obj = pattern.getObject();
if ( obj.equals(RDF.Nodes.Statement) )
res = allTriplesForPattern;
else if ( !obj.isConcrete() )
res = someTriplesForPattern;
}
} else if ( (pred.isVariable()) || pred.equals(Node.ANY) ) {
res = someTriplesForPattern;
} else
throw new JenaException("Unexpected predicate: " + pred.toString());
return res;
}
}
/*
* (c) Copyright 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.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -