Java Code Examples for com.bigdata.rdf.model.StatementEnum#Inferred

The following examples show how to use com.bigdata.rdf.model.StatementEnum#Inferred . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SPO.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
	 * Statement type is hiding in the 0 and 1 bits of the flags.
	 */
	private StatementEnum type() {
		
		// get just the 0 and 1 and 2 bits
//		final byte b = Bits.mask(flags, 0, 1, 2);
		byte b = 0;
		b |= (0x1 << TYPE_BIT);
		b |= (0x1 << (TYPE_BIT+1));
        b |= (0x1 << (TYPE_BIT+2));
		b &= flags;
		
        switch (b) {
        case 0: return null;
        case 1: return StatementEnum.Explicit;
        case 2: return StatementEnum.Axiom;
        case 3: return StatementEnum.Inferred;
        case 4: return StatementEnum.History;
        }
        
        throw new IllegalStateException();
        
	}
 
Example 2
Source File: BackchainTypeResourceIterator.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public BackchainSTypeResourceIterator(
		final IChunkedOrderedIterator<ISPO> _src,
		final IAccessPath<ISPO> accessPath,
		final AbstractTripleStore db, final IV rdfType,
		final IV rdfsResource) {
	this._src = _src;
	this.accessPath = accessPath;
	this.db = db;
	this.rdfType = rdfType;
	this.rdfsResource = rdfsResource;
	this.s = (IV) accessPath.getPredicate().get(0).get();
	SPO spo = new SPO(s, rdfType, rdfsResource, StatementEnum.Inferred);
	this.appender = new ChunkedArrayIterator<ISPO>(1,
			new SPO[] { spo }, SPOKeyOrder.SPO);
}
 
Example 3
Source File: TestSPOValueCoders.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Return an array of {@link SPO}s.
     * 
     * @param n
     *            The #of elements in the array.
     * @param SIDs
     *            If statement identifiers should be generated.
     * @param inference
     *            if {@link StatementEnum}s should be assigned.
     * 
     * @return The array.
     */
    protected SPO[] getData(final int n, final boolean SIDs,
            final boolean inference) {

        final SPO[] a = new SPO[n];

        for (int i = 0; i < n; i++) {

            /*
             * Note: Only the {s,p,o} are assigned. The statement type and the
             * statement identifier are not part of the key for the statement
             * indices.
             */
            final SPO spo;
            
            if (SIDs && !inference) {
            
                // only explicit statements can have SIDs.
                spo = new SPO(getTermId(), getTermId(), getTermId(),
                        StatementEnum.Explicit);
                
//                spo.setStatementIdentifier(getSID());
//                spo.setStatementIdentifier(true);
                
            } else if (inference) {
               
                final int tmp = r.nextInt(100);
                final StatementEnum type;
                if (tmp < 4) {
                    type = StatementEnum.Axiom;
                } else if (tmp < 60) {
                    type = StatementEnum.Explicit;
                } else {
                    type = StatementEnum.Inferred;
                }

                spo = new SPO(getTermId(), getTermId(), getTermId(), type);

                if (SIDs && type == StatementEnum.Explicit
                        && r.nextInt(100) < 20) {

                    // explicit statement with SID.
//                    spo.setStatementIdentifier(getSID());
//                	spo.setStatementIdentifier(true);

                }
                
            } else {

                // Explicit statement (no inference, no SIDs).
                spo = new SPO(getTermId(), getTermId(), getTermId(),
                        StatementEnum.Explicit);

            }
            
            a[i] = spo;
            
        }
        
        return a;
        
    }
 
Example 4
Source File: TestBulkFilter.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Simple test of bulk SPO completion (value lookup).
     */
    public void testCompletion() {

        AbstractTripleStore store = getStore();
        
        try {

            final URI A = new URIImpl("http://www.bigdata.com/A");
//            final URI B = new URIImpl("http://www.bigdata.com/B");
//            final URI C = new URIImpl("http://www.bigdata.com/C");
//            final URI D = new URIImpl("http://www.bigdata.com/D");
//            final URI E = new URIImpl("http://www.bigdata.com/E");

            final URI V = new URIImpl("http://www.bigdata.com/V");
            final URI W = new URIImpl("http://www.bigdata.com/W");
            final URI X = new URIImpl("http://www.bigdata.com/X");
            final URI Y = new URIImpl("http://www.bigdata.com/Y");
            final URI Z = new URIImpl("http://www.bigdata.com/Z");
            
            final IV a = store.addTerm(A);
//            final IV b = store.addTerm(B);
//            final IV c = store.addTerm(C);
//            final IV d = store.addTerm(D);
//            final IV e = store.addTerm(E);
            
            final IV v = store.addTerm(V);
            final IV w = store.addTerm(W);
            final IV x = store.addTerm(X);
            final IV y = store.addTerm(Y);
            final IV z = store.addTerm(Z);
            
            SPO[] stmts = new SPO[] {
                new SPO(x,a,y,StatementEnum.Explicit),
                new SPO(x,a,z,StatementEnum.Inferred)
            };
            int numStmts = stmts.length;
                
            store.addStatements(stmts, numStmts);
            
//            store.commit();
    
            if (log.isInfoEnabled())
                log.info("\n" + store.dumpStore(true, true, false));

            stmts = new SPO[] {
                new SPO(x,a,y),
                new SPO(x,a,z),
                new SPO(x,a,v),
                new SPO(x,a,w)
            };
            numStmts = stmts.length;

            { // filter out and complete
                
                final IChunkedOrderedIterator<ISPO> itr = store
                        .bulkCompleteStatements(stmts, numStmts);
                
                assertSameSPOsAnyOrder(store,
                    
                    new SPO[]{
                        new SPO(x,a,y,
                                StatementEnum.Explicit),
                        new SPO(x,a,z,
                                StatementEnum.Inferred),
                        new SPO(x,a,v,
                                StatementEnum.Inferred),
                        new SPO(x,a,w,
                                StatementEnum.Inferred)
                    },
                    
                    itr,
                    true // ignore axioms
                    
                );
/*            
                while(itr.hasNext()) {
                    SPO spo = itr.next();
                    System.err.println(spo.toString(store));
                }
*/
            }
        
        } finally {
            
            store.__tearDownUnitTest();

        }

    }
 
Example 5
Source File: SPORelation.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @todo This works for creating new SPOs licensed by inference against a
 *       triple store. However, it does not allow us to specify the
 *       statement type, which is always set to [inferred]. It also does not
 *       capture the context if one exists, but that could be done by
 *       inspection of the arity of the predicate. It might be better to
 *       have an explicit "CONSTRUCT" operator rather than having this
 *       implicit relationship between the head of a rule and the element
 *       created from that rule. For example, that might let us capture the
 *       distinction of inferred versus explicit within the CONSTRUCT
 *       operator.
 */
@SuppressWarnings("unchecked")
public SPO newElement(final List<BOp> a, final IBindingSet bindingSet) {

    if (a == null)
        throw new IllegalArgumentException();
    
    if (bindingSet == null)
        throw new IllegalArgumentException();

    final IV s = (IV) ((IVariableOrConstant<?>) a.get(0)).get(bindingSet);

    final IV p = (IV) ((IVariableOrConstant<?>) a.get(1)).get(bindingSet);

    final IV o = (IV) ((IVariableOrConstant<?>) a.get(2)).get(bindingSet);

    final SPO spo = new SPO(s, p, o, StatementEnum.Inferred);
    
    if(log.isDebugEnabled())
        log.debug(spo.toString());
    
    return spo;
    
}
 
Example 6
Source File: Justification.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the tail as an {@link SPO}[].
 * <p>
 * Note: The {@link StatementEnum} associated triple patterns in the tail is
 * actually unknown, but it is marked as {@link StatementEnum#Inferred} in
 * the returned object. In fact, since the tail consists of triple patterns
 * and not necessarily fully bound triples, the concept of a
 * {@link StatementEnum} is not even defined.
 * 
 * @return
 */
public SPO[] getTail() {
    
    // #of triple patterns in the tail.
    final int m = (ivs.length / N) - 1;

    SPO[] tail = new SPO[m];
    
    // for each triple pattern in the tail.
    int j = N;
    for(int i=0; i<m; i++, j+=N) {
    
        tail[i] = new SPO(ivs[j], ivs[j + 1], ivs[j + 2],
                StatementEnum.Inferred);
        
    }

    return tail;
    
}
 
Example 7
Source File: SPO.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return <code>true</code> IFF the {@link SPO} is marked as {@link StatementEnum#Inferred}. 
 */
@Override
public final boolean isInferred() {
    
    return type() == StatementEnum.Inferred;
    
}
 
Example 8
Source File: InferredSPOFilter.java    From database with GNU General Public License v2.0 3 votes vote down vote up
private boolean accept(final ISPO o) {
    
    final ISPO spo = (ISPO) o;
    
    return spo.getStatementType() == StatementEnum.Inferred;

}
 
Example 9
Source File: Justification.java    From database with GNU General Public License v2.0 votes vote down vote up
/**
 * Returns the head as an {@link SPO}.
 * <p>
 * Note: The {@link StatementEnum} associated with the head is actually
 * unknown, but it is marked as {@link StatementEnum#Inferred} in the
 * returned object. In order to discover the {@link StatementEnum} for the
 * head you MUST either already know it (this is not uncommon) or you MUST
 * read one of the statement indices.
 * 
 * @return
 */
public SPO getHead() {

    return new SPO(ivs[0], ivs[1], ivs[2], StatementEnum.Inferred);
    
}