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

The following examples show how to use com.bigdata.rdf.model.StatementEnum#Axiom . 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: 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 3
Source File: BaseAxioms.java    From database with GNU General Public License v2.0 4 votes vote down vote up
final public boolean isAxiom(final IV s, final IV p, final IV o) {

        if (axioms == null)
            throw new IllegalStateException();

        // fast rejection.
        if (s == null || p == null || o == null) {

            return false;
            
        }

        final SPO spo = new SPO(s, p, o, StatementEnum.Axiom);

        if(axioms.contains(spo)) {
            
            return true;
            
        }
        
        return false;
        
    }
 
Example 4
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#Axiom}. 
 */
@Override
public final boolean isAxiom() {
    
    return type() == StatementEnum.Axiom;
    
}
 
Example 5
Source File: NoAxiomFilter.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.Axiom;
    
}
 
Example 6
Source File: BaseAxioms.java    From database with GNU General Public License v2.0 3 votes vote down vote up
private void writeVersion1(final ObjectOutput out) throws IOException {

        out.writeUTF(namespace);

        LongPacker.packLong(out, axioms.size());

        final IKeyBuilder keyBuilder = new KeyBuilder(24/*initialCapacity*/);
        
        for (ISPO spo : axioms) {

            final byte[] key = SPOKeyOrder.SPO.encodeKey(keyBuilder, spo);

            if (true) {
                
                final IV[] ivs = IVUtility.decodeAll(key);
                
                if (ivs.length != 3)
                    throw new IOException("Expecting 3 IVs, not: "
                            + Arrays.toString(ivs) + " for " + spo);

                final IV s = ivs[0];

                final IV p = ivs[1];

                final IV o = ivs[2];

                final SPO spo2 = new SPO(s, p, o, StatementEnum.Axiom);
                if (!spo.equals(spo2))
                    throw new IOException("Expecting: " + spo + ", not " + spo2);
            }

            LongPacker.packLong(out, key.length);

            out.write(key);

        }
        
    }
 
Example 7
Source File: BaseAxioms.java    From database with GNU General Public License v2.0 2 votes vote down vote up
private void readVersion1(final ObjectInput in) throws IOException {

        namespace = in.readUTF();
        
        final int naxioms = LongPacker.unpackInt(in);

//        if (naxioms < 0 || naxioms > Integer.MAX_VALUE)
//            throw new IOException();

        axioms = new LinkedHashSet<SPO>(naxioms);
//        createBTree((int) naxioms);

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

            final int nbytes = LongPacker.unpackInt(in);

            final byte[] key = new byte[nbytes];

            in.readFully(key);

            final IV[] ivs = IVUtility.decodeAll(key);

            if (ivs.length != 3)
                throw new IOException("Expecting 3 IVs, not: "
                        + Arrays.toString(ivs));

            final IV s = ivs[0];

            final IV p = ivs[1];

            final IV o = ivs[2];

            final SPO spo = new SPO(s, p, o, StatementEnum.Axiom);

//            btree.insert(tupleSer.serializeKey(spo), spo.getStatementType()
//                    .serialize());
            axioms.add(spo);

        }

    }