Java Code Examples for com.bigdata.rdf.store.AbstractTripleStore#getSPORelation()

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore#getSPORelation() . 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: TestSPOAccessPath.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * There are 8 distinct triple pattern bindings for a triple store that
 * select among 3 distinct access paths.
 */
public void test_getAccessPath() {
   
    final AbstractTripleStore store = getStore();

    // constants used for s,p,o,c when bound. 0L used when unbound.
    final IV<?,?> S = factory.newTermId(VTE.URI, 1);
    final IV<?,?> P = factory.newTermId(VTE.URI, 2);
    final IV<?,?> O = factory.newTermId(VTE.URI, 3);
    final IV<?,?> C = factory.newTermId(VTE.URI, 4);
    final IV<?,?> _ = factory.newTermId(VTE.URI, 0);

    try {

        final SPORelation r = store.getSPORelation();

        if (store.isQuads()) {

            /*
             * For a quad store there are 16 distinct binding patterns that
             * select among 6 distinct access paths. there are some quad
             * patterns which could be mapped onto more than one access
             * path, but the code here checks the expected mapping. These
             * mappings are similar to those in YARS2, but are the mappings
             * generated by the "Magic" tuple logic.
             */

            // SPOC
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(_, _, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, _, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, O, _).getKeyOrder());
            assertEquals(SPOKeyOrder.SPOC, r.getAccessPath(S, P, O, C).getKeyOrder());
            
            // POCS
            assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, _, _).getKeyOrder());
            assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, O, _).getKeyOrder());
            assertEquals(SPOKeyOrder.POCS, r.getAccessPath(_, P, O, C).getKeyOrder());
            
            // OCSP
            assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(_, _, O, _).getKeyOrder());
            assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(_, _, O, C).getKeyOrder());
            assertEquals(SPOKeyOrder.OCSP, r.getAccessPath(S, _, O, C).getKeyOrder());
            
            // CSPO
            assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(_, _, _, C).getKeyOrder());
            assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(S, _, _, C).getKeyOrder());
            assertEquals(SPOKeyOrder.CSPO, r.getAccessPath(S, P, _, C).getKeyOrder());
            
            // PCSO
            assertEquals(SPOKeyOrder.PCSO, r.getAccessPath(_, P, _, C).getKeyOrder());

            // SOPC
            assertEquals(SPOKeyOrder.SOPC, r.getAccessPath(S, _, O, _).getKeyOrder());

        } else {
            
            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(NULL, NULL, NULL,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, NULL, NULL,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, S, NULL, NULL)
                    .getKeyOrder());

            assertEquals(SPOKeyOrder.SPO, r.getAccessPath(S, S, S, NULL)
                    .getKeyOrder());

            assertEquals(SPOKeyOrder.POS, r.getAccessPath(NULL, S, NULL,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.POS, r.getAccessPath(NULL, S, S, NULL)
                    .getKeyOrder());

            assertEquals(SPOKeyOrder.OSP, r.getAccessPath(NULL, NULL, S,
                    NULL).getKeyOrder());

            assertEquals(SPOKeyOrder.OSP, r.getAccessPath(S, NULL, S, NULL)
                    .getKeyOrder());

        }

    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example 2
Source File: HistoryServiceFactory.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the pre-existing history index.
 * 
 * @param tripleStore
 *            The KB.
 * @return The history index and never <code>null</code>.
 * 
 * @throws IllegalStateException
 *             if the index was not configured / does not exist.
 */
private IIndex getHistoryIndex(final AbstractTripleStore tripleStore) {

    final SPORelation spoRelation = tripleStore.getSPORelation();

    final String fqn = AbstractRelation.getFQN(spoRelation,
            SPORelation.NAME_HISTORY);

    ndx = spoRelation.getIndex(fqn);

    if (ndx == null)
        throw new IllegalStateException("Index not found: " + fqn);
    
    return ndx;

}
 
Example 3
Source File: TestHistoryIndex.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Return the pre-existing history index.
 * 
 * @param tripleStore
 *            The KB.
 * @return The history index -or- <code>null</code> if it was not
 *         configured.
 */
private IIndex getHistoryIndex(final AbstractTripleStore tripleStore) {

    final SPORelation spoRelation = tripleStore.getSPORelation();

    final String fqn = AbstractRelation.getFQN(spoRelation,
            SPORelation.NAME_HISTORY);

    final IIndex ndx = spoRelation.getIndex(fqn);

    return ndx;

}
 
Example 4
Source File: VoID.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return an array of the distinct predicates in the KB ordered by their
 * descending frequency of use. The {@link IV}s in the returned array will
 * have been resolved to the corresponding {@link BigdataURI}s which can be
 * accessed using {@link IV#getValue()}.
 * 
 * @param kb
 *            The KB instance.
 */
protected static IVCount[] predicateUsage(final AbstractTripleStore kb) {

    final SPORelation r = kb.getSPORelation();
    
    if (r.oneAccessPath) {

        // The necessary index (POS or POCS) does not exist.
        throw new UnsupportedOperationException();

    }

    final boolean quads = kb.isQuads();

    // the index to use for distinct predicate scan.
    final SPOKeyOrder keyOrder = quads ? SPOKeyOrder.POCS : SPOKeyOrder.POS;

    // visit distinct term identifiers for predicate position on that index.
    @SuppressWarnings("rawtypes")
    final IChunkedIterator<IV> itr = r.distinctTermScan(keyOrder);

    // resolve term identifiers to terms efficiently during iteration.
    final BigdataValueIterator itr2 = new BigdataValueIteratorImpl(
            kb/* resolveTerms */, itr);

    try {

        final Set<IV<?,?>> ivs = new LinkedHashSet<IV<?,?>>();

        final Map<IV<?, ?>, IVCount> counts = new LinkedHashMap<IV<?, ?>, IVCount>();

        while (itr2.hasNext()) {

            final BigdataValue term = itr2.next();

            final IV<?,?> iv = term.getIV();

            final long n = r.getAccessPath(null, iv, null, null)
                    .rangeCount(false/* exact */);

            ivs.add(iv);
            
            counts.put(iv, new IVCount(iv, n));

        }

        // Batch resolve IVs to Values
        final Map<IV<?, ?>, BigdataValue> x = kb.getLexiconRelation()
                .getTerms(ivs);

        for (Map.Entry<IV<?, ?>, BigdataValue> e : x.entrySet()) {

            final IVCount count = counts.get(e.getKey());

            count.setValue(e.getValue());

        }

        final IVCount[] a = counts.values().toArray(
                new IVCount[counts.size()]);

        // Order by descending count.
        Arrays.sort(a);

        return a;

    } finally {

        itr2.close();

    }

}
 
Example 5
Source File: VoID.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the predicate partition statistics for the named graph.
 * 
 * @param kb
 *            The KB instance.
 * @param civ
 *            The {@link IV} of a named graph (required).
 * 
 * @return The predicate partition statistics for that named graph. Only
 *         predicate partitions which are non-empty are returned.
 */
protected static IVCount[] predicateUsage(final AbstractTripleStore kb,
        final IV<?, ?> civ, final IVCount[] predicatePartitionCounts) {
    
    final SPORelation r = kb.getSPORelation();

    final boolean quads = kb.isQuads();
    
    if (!quads) {
        
        // Named graph only valid in quads mode.
        throw new IllegalArgumentException();
    
    }

    // The non-zero counts.
    final List<IVCount> counts = new LinkedList<IVCount>();

    // Check the known non-empty predicate partitions.
    for(IVCount in : predicatePartitionCounts){

        final long n = r.getAccessPath(null, in.iv, null, civ).rangeCount(
                false/* exact */);

        if (n == 0)
            continue;

        final IVCount out = new IVCount(in.iv, n);

        out.setValue(in.getValue());
        
        counts.add(out);

    }
    

    final IVCount[] a = counts.toArray(new IVCount[counts.size()]);

    // Order by descending count.
    Arrays.sort(a);

    return a;

}
 
Example 6
Source File: VoID.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the class partition statistics for the named graph.
 * 
 * @param kb
 *            The KB instance.
 * @param civ
 *            The {@link IV} of a named graph (required).
 * 
 * @return The class partition statistics for that named graph. Only class
 *         partitions which are non-empty are returned.
 */
protected static IVCount[] classUsage(final AbstractTripleStore kb,
        final IV<?, ?> civ, final IVCount[] classPartitionCounts) {

    final SPORelation r = kb.getSPORelation();

    final boolean quads = kb.isQuads();

    if (!quads) {

        // Named graph only valid in quads mode.
        throw new IllegalArgumentException();

    }

    // Resolve IV for rdf:type
    final BigdataURI rdfType = kb.getValueFactory().asValue(RDF.TYPE);

    kb.getLexiconRelation().addTerms(new BigdataValue[] { rdfType },
            1/* numTerms */, true/* readOnly */);

    if (rdfType.getIV() == null) {

        // No rdf:type assertions since rdf:type is unknown term.
        return new IVCount[0];

    }

    // The non-zero counts.
    final List<IVCount> counts = new LinkedList<IVCount>();

    // Check the known non-empty predicate partitions.
    for (IVCount in : classPartitionCounts) {

        final long n = r.getAccessPath(null, rdfType.getIV()/* p */,
                in.iv/* o */, civ).rangeCount(false/* exact */);

        if (n == 0)
            continue;
        
        final IVCount out = new IVCount(in.iv, n);

        out.setValue(in.getValue());

        counts.add(out);

    }

    final IVCount[] a = counts.toArray(new IVCount[counts.size()]);

    // Order by descending count.
    Arrays.sort(a);

    return a;

}