com.bigdata.rdf.store.AbstractTripleStore Java Examples

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore. 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: LexiconRelation.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
   protected Class<BigdataValueFactory> determineValueFactoryClass() {

       final String className = getProperty(
               AbstractTripleStore.Options.VALUE_FACTORY_CLASS,
               AbstractTripleStore.Options.DEFAULT_VALUE_FACTORY_CLASS);
       final Class<?> cls;
       try {
           cls = Class.forName(className);
       } catch (ClassNotFoundException e) {
           throw new RuntimeException("Bad option: "
                   + AbstractTripleStore.Options.VALUE_FACTORY_CLASS, e);
       }

       if (!BigdataValueFactory.class.isAssignableFrom(cls)) {
           throw new RuntimeException(
                   AbstractTripleStore.Options.VALUE_FACTORY_CLASS
                           + ": Must implement: "
                           + BigdataValueFactory.class.getName());
       }

       return (Class<BigdataValueFactory>) cls;

}
 
Example #2
Source File: TripleStoreBlazegraph.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
public TripleStoreBlazegraph() {
    final Properties props = new Properties();
    props.put(Options.BUFFER_MODE, "MemStore");
    props.put(AbstractTripleStore.Options.QUADS_MODE, "true");
    props.put(BigdataSail.Options.TRUTH_MAINTENANCE, "false");

    // Quiet
    System.getProperties().setProperty("com.bigdata.Banner.quiet", "true");
    System.getProperties().setProperty("com.bigdata.util.config.LogUtil.quiet", "true");

    BigdataSail sail = new BigdataSail(props); // instantiate a sail
    repo = new BigdataSailRepository(sail); // create a Sesame repository

    try {
        repo.initialize();
    } catch (RepositoryException x) {
        LOG.error("Repository could not be created {}", x.getMessage());
    }
}
 
Example #3
Source File: RDRHistoryServiceFactory.java    From database with GNU General Public License v2.0 6 votes vote down vote up
public RDRHistoryServiceCall(final AbstractTripleStore database,
        final IServiceOptions options,
        final GraphPatternGroup<IGroupMemberNode> subgroup) {
    this.database = database;
    this.options = options;
    this.subgroup = subgroup;
    
    final List<StatementPatternNode> spNodes =
            subgroup.getChildren(StatementPatternNode.class);
    if (spNodes.size() != 2) {
        throw new IllegalArgumentException();
    }
    if (spNodes.get(0).sid() != null) {
        sidNode = spNodes.get(0);
        historyNode = spNodes.get(1);
    } else {
        sidNode = spNodes.get(1);
        historyNode = spNodes.get(0);
    }
}
 
Example #4
Source File: LexiconRelation.java    From database with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Class<IValueCentricTextIndexer> determineTextIndexerClass() {

    final String className = getProperty(
            AbstractTripleStore.Options.TEXT_INDEXER_CLASS,
            AbstractTripleStore.Options.DEFAULT_TEXT_INDEXER_CLASS);
    
    final Class<?> cls;
    try {
        cls = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Bad option: "
                + AbstractTripleStore.Options.TEXT_INDEXER_CLASS, e);
    }

    if (!IValueCentricTextIndexer.class.isAssignableFrom(cls)) {
        throw new RuntimeException(
                AbstractTripleStore.Options.TEXT_INDEXER_CLASS
                        + ": Must implement: "
                        + IValueCentricTextIndexer.class.getName());
    }

    return (Class<IValueCentricTextIndexer>) cls;

}
 
Example #5
Source File: AST2BOpRTO.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return an execution context that may be used to execute a cutoff join
 * during sampling or the entire join path once it has been identified.
 * 
 * @param queryEngine
 *            The query engine on which the RTO is executing.
 * @param nt
 *            The namespace and timestamp of the KB view against which the
 *            RTO is running.
 * 
 * @throws RuntimeException
 *             if there is no such KB instance.
 */
private static AST2BOpContext getExecutionContext(
        final QueryEngine queryEngine, final NT nt) {

    // The index manager that can be used to resolve the KB view.
    final IIndexManager indexManager = queryEngine.getFederation() == null ? queryEngine
            .getIndexManager() : queryEngine.getFederation();

    // Resolve the KB instance.
    final AbstractTripleStore db = (AbstractTripleStore) indexManager
            .getResourceLocator().locate(nt.getName(), nt.getTimestamp());

    if (db == null)
        throw new RuntimeException("No such KB? " + nt);

    /*
     * An empty container. You can not use any of the top-level SPARQL query
     * conversion routines with this container, but it is enough for the
     * low-level things that we need to run the RTO.
     */
    final ASTContainer astContainer = new ASTContainer(BOp.NOARGS,
            BOp.NOANNS);
    
    return new AST2BOpContext(astContainer, db);

}
 
Example #6
Source File: TestNanoSparqlServer.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Simple start/kill in which we verify that the default KB was NOT created
 * and that the explicitly create KB instance can still be resolved. This is
 * basically a test of the ability to override the init parameters in
 * <code>web.xml</code> to specify the {@link ConfigParams#NAMESPACE} and
 * {@link ConfigParams#CREATE} properties. If those overrides are not
 * applied then the default KB will be created and this test will fail. If
 * the test fails, the place to look is {@link NanoSparqlServer} where it is
 * overriding the init parameters for the {@link WebAppContext}.
 * 
 * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/730" >
 *      Allow configuration of embedded NSS jetty server using jetty-web.xml
 *      </a>
 */
public void test_start_stop() {

    final AbstractTripleStore tripleStore = (AbstractTripleStore) m_indexManager
            .getResourceLocator().locate(namespace, ITx.UNISOLATED);

    assertNotNull("Explicitly create KB not found: namespace=" + namespace,
            tripleStore);

    final AbstractTripleStore tripleStore2 = (AbstractTripleStore) m_indexManager
            .getResourceLocator().locate(
                    BigdataSail.Options.DEFAULT_NAMESPACE, ITx.UNISOLATED);

    /*
     * Note: A failure here means that our override of
     * ConfigParams.NAMESPACE was ignored.
     */
    assertNull("Default KB should not exist.", tripleStore2);

}
 
Example #7
Source File: LexiconRelation.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected Class<IExtensionFactory> determineExtensionFactoryClass() {

    final String defaultClassName;
    if (vocab == null || vocab.getClass() == NoVocabulary.class) {
        /*
         * If there is no vocabulary then you can not use the default
         * extension class (or probably any extension class for that matter
         * since the vocbulary is required in order to be able to resolve
         * the URIs for the extension).
         * 
         * @see https://sourceforge.net/apps/trac/bigdata/ticket/456
         */
        defaultClassName = NoExtensionFactory.class.getName();
    } else {
        defaultClassName = AbstractTripleStore.Options.DEFAULT_EXTENSION_FACTORY_CLASS;
    }

    final String className = getProperty(
            AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS,
            defaultClassName);
    
    final Class<?> cls;
    try {
        cls = Class.forName(className);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Bad option: "
                + AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS, e);
    }

    if (!IExtensionFactory.class.isAssignableFrom(cls)) {
        throw new RuntimeException(
                AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS
                        + ": Must implement: "
                        + IExtensionFactory.class.getName());
    }

    return (Class<IExtensionFactory>) cls;

}
 
Example #8
Source File: HistoryServiceFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
         * Return the revision time that will be used for all changes written
         * onto the history index by this {@link IChangeLog} listener.
         * 
         * @see HistoryChangeRecord#getRevisionTime()
         */
        static private long getRevisionTimestamp(
                final AbstractTripleStore tripleStore) {

            final long revisionTimestamp;
            
            final IIndexManager indexManager = tripleStore.getIndexManager();

            revisionTimestamp = indexManager.getLastCommitTime() + 1;

//            if (indexManager instanceof IJournal) {
//
//                revisionTimestamp = indexManager.getLastCommitTime() + 1;
////                        ((IJournal) indexManager)
////                        .getLocalTransactionManager().nextTimestamp();
//                
//            } else if (indexManager instanceof IBigdataFederation) {
//                
//                try {
//                
//                    revisionTimestamp = ((IBigdataFederation<?>) indexManager)
//                            .getTransactionService().nextTimestamp();
//                    
//                } catch (IOException e) {
//                    
//                    throw new RuntimeException(e);
//                    
//                }
//
//            } else {
//            
//                throw new AssertionError("indexManager="
//                        + indexManager.getClass());
//                
//            }

            return revisionTimestamp;
        }
 
Example #9
Source File: RDRHistory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public RDRHistory(final AbstractTripleStore database) {
    
    if (!database.isStatementIdentifiers()) {
        throw new IllegalArgumentException("database must be in sids mode");
    }
    
    this.database = database;
}
 
Example #10
Source File: TestGeoSpatialQueryIfGeospatialDisabled.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Properties getProperties() {

    // Note: clone to avoid modifying!!!
    final Properties properties = (Properties) super.getProperties().clone();

    // turn on quads.
    properties.setProperty(AbstractTripleStore.Options.QUADS, "false");

    // TM not available with quads.
    properties.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE,"false");

    // turn off axioms.
    properties.setProperty(AbstractTripleStore.Options.AXIOMS_CLASS,
            NoAxioms.class.getName());

    // no persistence.
    properties.setProperty(com.bigdata.journal.Options.BUFFER_MODE,
            BufferMode.Transient.toString());

    // enable GeoSpatial index
    properties.setProperty(
       com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL, "false");

    return properties;

}
 
Example #11
Source File: BigdataGASRunner.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void loadFiles() throws IOException {

    final BigdataOptionData opt = getOptionData();

    final Journal jnl = opt.jnl;
    final String namespace = opt.namespace;
    final String[] loadSet = opt.loadSet.toArray(new String[0]);

    // Load data using the unisolated view.
    final AbstractTripleStore kb = (AbstractTripleStore) jnl
            .getResourceLocator().locate(namespace, ITx.UNISOLATED);

    if (opt.newKB && loadSet.length > 0) {

        final BigdataSail sail = new BigdataSail(kb);
        try {
            try {
                sail.initialize();
                loadFiles(sail, loadSet);
            } finally {
                if (sail.isOpen())
                    sail.shutDown();
            }
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    // total #of edges in that graph.
    opt.nedges = kb.getStatementCount();

}
 
Example #12
Source File: TestInlineConstraints.java    From database with GNU General Public License v2.0 5 votes vote down vote up
private IPredicate toPredicate(final AbstractTripleStore database,
		final AtomicInteger idFactory,
		final IVariableOrConstant<IV> s,
		final IVariableOrConstant<IV> p,
		final IVariableOrConstant<IV> o) {
	
    // The annotations for the predicate.
    final List<NV> anns = new LinkedList<NV>();

    // Decide on the correct arity for the predicate.
    final BOp[] vars = new BOp[] { s, p, o };

    anns.add(new NV(IPredicate.Annotations.RELATION_NAME,
            new String[] { database.getSPORelation().getNamespace() }));//
    

    // timestamp
    anns.add(new NV(Annotations.TIMESTAMP, database
            .getSPORelation().getTimestamp()));

    /*
     * Explicitly set the access path / iterator flags.
     * 
     * Note: High level query generally permits iterator level parallelism.
     * We set the PARALLEL flag here so it can be used if a global index
     * view is chosen for the access path.
     * 
     * Note: High level query for SPARQL always uses read-only access paths.
     * If you are working with a SPARQL extension with UPDATE or INSERT INTO
     * semantics then you will need to remote the READONLY flag for the
     * mutable access paths.
     */
    anns.add(new NV(IPredicate.Annotations.FLAGS, IRangeQuery.DEFAULT
            | IRangeQuery.PARALLEL | IRangeQuery.READONLY));
    
    anns.add(new NV(BOp.Annotations.BOP_ID, idFactory.incrementAndGet()));
    
    return new SPOPredicate(vars, anns.toArray(new NV[anns.size()]));
	
}
 
Example #13
Source File: ExportKB.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Export the configuration properties for the kb.
     * 
     * @throws IOException
     */
    public void exportProperties() throws IOException {
        prepare();
        final AbstractTripleStore kb = conn.getTripleStore();
        // Prepare a comment block for the properties file.
        final StringBuilder comments = new StringBuilder(
                "Configuration properties.\n");
        if (kb.getIndexManager() instanceof IRawStore) {
            comments.append("source="
                    + ((IRawStore) kb.getIndexManager()).getFile() + "\n");
            comments.append("namespace=" + namespace + "\n");
            // The timestamp of the KB view.
            comments.append("timestamp=" + kb.getTimestamp() + "\n");
            // The date and time when the KB export began. (Automatically added by Java).
//            comments.append("exportDate=" + new Date() + "\n");
            // The approximate #of statements (includes axioms, inferences, and
            // deleted statements).
            comments.append("fastStatementCount="
                    + kb.getStatementCount(false/* exact */) + "\n");
            // The #of URIs in the lexicon indices.
            comments.append("uriCount=" + kb.getURICount() + "\n");
            // The #of Literals in the lexicon indices.
            comments.append("literalCount=" + kb.getLiteralCount() + "\n");
            // The #of blank nodes in the lexicon indices.
            comments.append("bnodeCount=" + kb.getBNodeCount() + "\n");
        }
        // Flatten the properties so inherited defaults will also be written
        // out.
        final Properties properties = flatCopy(kb.getProperties());
        // Write the properties file.
        final File file = new File(kbdir, "kb.properties");
        System.out.println("Writing " + file);
        final OutputStream os = new BufferedOutputStream(new FileOutputStream(
                file));
        try {
            properties.store(os, comments.toString());
        } finally {
            os.close();
        }
    }
 
Example #14
Source File: TestStatementBuffer.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * A unit test in which the translation of reified statements into inline
 * statements disabled. This test uses the same data as the test below.
 */
public void test_reificationDoneRight_disabled() {

	if (QueryHints.DEFAULT_REIFICATION_DONE_RIGHT)
		return;
	
       final int capacity = 20;

	final Properties properties = new Properties(getProperties());

	// turn off entailments.
	properties.setProperty(AbstractTripleStore.Options.AXIOMS_CLASS,
			NoAxioms.class.getName());

       final AbstractTripleStore store = getStore(properties);

       try {
      
		// * @prefix : <http://example.com/> .
		// * @prefix news: <http://example.com/news/> .
		// * @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
		// * @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
		// * @prefix dc: <http://purl.org/dc/terms/> .
		// * @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
		// *
		// * :SAP :bought :sybase .
		// * _:s1 rdf:subject :SAP .
		// * _:s1 rdf:predicate :bought .
		// * _:s1 rdf:object :sybase .
		// * _:s1 rdf:type rdf:Statement .
		// * _:s1 dc:source news:us-sybase .
		// * _:s1 dc:created    "2011-04-05T12:00:00Z"^^xsd:dateTime .

		final BigdataValueFactory vf = store.getValueFactory();

		final BigdataURI SAP = vf.createURI("http://example.com/SAP");
		final BigdataURI bought = vf.createURI("http://example.com/bought");
		final BigdataURI sybase = vf.createURI("http://example.com/sybase");
		final BigdataURI dcSource = vf.createURI("http://purl.org/dc/terms/source");
		final BigdataURI dcCreated = vf.createURI("http://purl.org/dc/terms/created");
		final BigdataURI newsSybase = vf.createURI("http://example.com/news/us-sybase");
		final BigdataLiteral createdDate = vf.createLiteral("2011-04-05T12:00:00Z",XSD.DATETIME);
		final BigdataBNode s1 = vf.createBNode("s1");

		// store is empty.
		assertEquals(0, store.getStatementCount());

		final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>(
				store, capacity);

		// ground statement.
		buffer.add(vf.createStatement(SAP, bought, sybase,
				null/* context */, StatementEnum.Explicit));
		
		// model of that statement (RDF reification).
		buffer.add(vf.createStatement(s1, RDF.SUBJECT, SAP,
				null/* context */, StatementEnum.Explicit));

		buffer.add(vf.createStatement(s1, RDF.PREDICATE, bought,
				null/* context */, StatementEnum.Explicit));

		buffer.add(vf.createStatement(s1, RDF.OBJECT, sybase,
				null/* context */, StatementEnum.Explicit));

		buffer.add(vf.createStatement(s1, RDF.TYPE, RDF.STATEMENT,
				null/* context */, StatementEnum.Explicit));

		// metadata statements.
		
		buffer.add(vf.createStatement(s1, dcSource, newsSybase,
				null/* context */, StatementEnum.Explicit));

		buffer.add(vf.createStatement(s1, dcCreated, createdDate,
				null/* context */, StatementEnum.Explicit));

           // flush the buffer.
		buffer.flush();

		// the statements are now in the store.
		assertEquals(7, store.getStatementCount());

		assertTrue(store.hasStatement(SAP, bought, sybase));
		assertTrue(store.hasStatement(s1, RDF.SUBJECT, SAP));
		assertTrue(store.hasStatement(s1, RDF.PREDICATE, bought));
		assertTrue(store.hasStatement(s1, RDF.OBJECT, sybase));
		assertTrue(store.hasStatement(s1, RDF.TYPE, RDF.STATEMENT));
		assertTrue(store.hasStatement(s1, dcSource, newsSybase));
		assertTrue(store.hasStatement(s1, dcCreated, createdDate));

       } finally {

           store.__tearDownUnitTest();

       }

}
 
Example #15
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 #16
Source File: TestRuleRdfs03.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Literals may not appear in the subject position, but an rdfs4b entailment
 * can put them there unless you explicitly filter it out.
 * <P>
 * Note: {@link RuleRdfs04b} is the other way that literals can be entailed
 * into the subject position.
 * 
 * @throws Exception 
 */
public void test_rdfs3_filterLiterals() throws Exception {
    
    final Properties properties = super.getProperties();
    
    // override the default axiom model.
    properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
    
    final AbstractTripleStore store = getStore(properties);

    try {
    
        URI A = new URIImpl("http://www.foo.org/A");
        URI X = new URIImpl("http://www.foo.org/X");
        URI U = new URIImpl("http://www.foo.org/U");
        Literal V1 = new LiteralImpl("V1"); // a literal.
        URI V2 = new URIImpl("http://www.foo.org/V2"); // not a literal.
        URI rdfRange = RDFS.RANGE;
        URI rdfType = RDF.TYPE;

        store.addStatement(A, rdfRange, X);
        store.addStatement(U, A, V1);
        store.addStatement(U, A, V2);

        assertTrue(store.hasStatement(A, rdfRange, X));
        assertTrue(store.hasStatement(U, A, V1));
        assertTrue(store.hasStatement(U, A, V2));
        assertEquals(3,store.getStatementCount());

        /*
         * Note: The rule computes the entailement but it gets whacked by
         * the DoNotAddFilter on the InferenceEngine, so it is counted here
         * but does not show in the database.
         */
        
        final Vocabulary vocab = store.getVocabulary();

        final Rule r = new RuleRdfs03(
                store.getSPORelation().getNamespace(), vocab);
        
        final IElementFilter<ISPO> filter = new DoNotAddFilter(vocab,
                store.getAxioms(), true/* forwardChainRdfTypeRdfsResource */);
        
        applyRule(store, r, filter/* , false justified */,
                -1/* solutionCount */, 1/* mutationCount*/);

        /*
         * validate the state of the primary store.
         */
        assertTrue(store.hasStatement(A, rdfRange, X));
        assertTrue(store.hasStatement(U, A, V1));
        assertTrue(store.hasStatement(U, A, V2));
        assertTrue(store.hasStatement(V2, rdfType, X));
        assertEquals(4,store.getStatementCount());

    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example #17
Source File: AbstractSPOBuffer.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a buffer.
 * 
 * @param store
 *            The database used to resolve term identifiers in log
 *            statements (optional).
 * @param filter
 *            Option filter. When present statements matched by the filter
 *            are NOT retained by the {@link SPOAssertionBuffer} and will
 *            NOT be added to the <i>store</i>.
 * @param capacity
 *            The maximum #of Statements, URIs, Literals, or BNodes that the
 *            buffer can hold.
 */
protected AbstractSPOBuffer(AbstractTripleStore store, IElementFilter<ISPO> filter,
        int capacity) {

    if (capacity <= 0)
        throw new IllegalArgumentException();
    
    this._db = store;

    this.filter = filter;
    
    this.capacity = capacity;

    stmts = new ISPO[capacity];
    
}
 
Example #18
Source File: LexiconRelation.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
    public void create() {
        
        final IResourceLock resourceLock = acquireExclusiveLock();
        
        try {

            super.create();

			if (textIndex && inlineTextLiterals
					&& maxInlineTextLength > (4 * Bytes.kilobyte32)) {
				/*
				 * Log message if full text index is enabled and we are inlining
				 * textual literals and MAX_INLINE_TEXT_LENGTH is GT some
				 * threshold value (e.g., 4096). This combination represents an
				 * unreasonable configuration due to the data duplication in the
				 * full text index. (The large literals will be replicated
				 * within the full text index for each token extracted from the
				 * literal by the text analyzer.)
				 */
				log
						.error("Configuration will duplicate large literals within the full text index"
								+ //
								": "
								+ AbstractTripleStore.Options.TEXT_INDEX
								+ "="
								+ textIndex
								+ //
								", "
								+ AbstractTripleStore.Options.INLINE_TEXT_LITERALS
								+ "="
								+ inlineTextLiterals
								+ //
								", "
								+ AbstractTripleStore.Options.MAX_INLINE_TEXT_LENGTH
								+ "=" + maxInlineTextLength//
						);

			}

            final IIndexManager indexManager = getIndexManager();

            // register the indices.

            indexManager
                    .registerIndex(getTerm2IdIndexMetadata(getFQN(LexiconKeyOrder.TERM2ID)));

            indexManager
                    .registerIndex(getId2TermIndexMetadata(getFQN(LexiconKeyOrder.ID2TERM)));

			if (getLexiconConfiguration().getBlobsThreshold() != Integer.MAX_VALUE) {

				// Do not create the BLOBS index if BLOBS support has been disabled.
				indexManager.registerIndex(getBlobsIndexMetadata(getFQN(LexiconKeyOrder.BLOBS)));
				
			}

            if (textIndex) {

                // Create the full text index

				final IValueCentricTextIndexer<?> tmp = getSearchEngine();

                tmp.create();

            }

            /*
             * Note: defer resolution of the newly created index objects. This
             * is mostly about efficiency since the scale-out API does not
             * return the IIndex object when we register the index. 
             */
            
//            terms = super.getIndex(LexiconKeyOrder.TERMS);
//            assert terms != null;

            /*
    		 * Allow the extensions to resolve their datatype URIs into term
    		 * identifiers.
    		 */
        	lexiconConfiguration.initExtensions(this);
            
        } finally {

            unlock(resourceLock);

        }

    }
 
Example #19
Source File: TestMockUtility.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a mocked local triple (memory) store with the given namespace,
 * with unisolated transactions.
 * 
 * @param namespace
 * @return
 */
public static AbstractTripleStore mockTripleStore(final String namespace) {
   
   final Properties properties = new Properties();
   properties.setProperty(
      com.bigdata.journal.Options.BUFFER_MODE,BufferMode.MemStore.name());
   
   final Journal store = new Journal(properties);

   final AbstractTripleStore kb = new LocalTripleStore(
      store, namespace, ITx.UNISOLATED, properties);
   
   kb.create();
   store.commit();
         
   return kb;
       
}
 
Example #20
Source File: BackchainAccessPath.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 
 * @param database
 *            The database whose entailments will be backchained.
 * @param accessPath
 *            The source {@link IAccessPath}.
 * @param isOwlSameAsUsed
 *            When non-<code>null</code>, this {@link Boolean} indicates
 *            whether the statement pattern <code>(x owl:sameAs y)</code>
 *            is known to be empty in the data. Specify <code>null</code>
 *            if you do not know this up front. This parameter is used to
 *            factor out the test for this statement pattern, but that test
 *            is only performed if {@link Axioms#isOwlSameAs()} is
 *            <code>true</code>.
 */
public BackchainAccessPath(AbstractTripleStore database,
        IAccessPath<ISPO> accessPath, Boolean isOwlSameAsUsed) {

    if (database == null)
        throw new IllegalArgumentException();

    if (accessPath == null)
        throw new IllegalArgumentException();

    this.database = database;
    
    this.accessPath = accessPath;
    
    // MAY be null
    this.isOwlSameAsUsed = isOwlSameAsUsed;
    
}
 
Example #21
Source File: ASTDeferredIVResolution.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Do deferred resolution of IVs, which were left unresolved after execution of each Update in UpdateRoot
     * @param store - triple store, which will be used for values resolution
     * @param ast - AST model of the update, which should be resolved
     * @param bs - binding set, which should be resolved
     * @param dataset 
     * @return 
     * @throws MalformedQueryException
     */
    public static DeferredResolutionResult resolveUpdate(final AbstractTripleStore store, final Update update, final BindingSet bs, final Dataset dataset) throws MalformedQueryException {

        final ASTDeferredIVResolution termsResolver = new ASTDeferredIVResolution(store);

        // process provided binding set
        BindingSet resolvedBindingSet = termsResolver.handleBindingSet(store, bs);

        // process provided dataset
        final Dataset resolvedDataset = termsResolver.handleDataset(store, dataset);

//    	final long beginNanos = System.nanoTime();
    	
        termsResolver.resolve(store, update, null/*datasetClauseLists*/, bs);

//        ast.setResolveValuesTime(System.nanoTime() - beginNanos);

        return new DeferredResolutionResult(resolvedBindingSet, resolvedDataset);

    }
 
Example #22
Source File: ASTEvalHelper.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Evaluate a SELECT query.
 * 
 * @param store
 *            The {@link AbstractTripleStore} having the data.
 * @param queryPlan
 *            The {@link ASTContainer}.
 * @param globallyScopedBS
 *            The initial solution to kick things off.
 *            
 * @return An object from which the solutions may be drained.
 * 
 * @throws QueryEvaluationException
 */
static public TupleQueryResult evaluateTupleQuery(
        final AbstractTripleStore store,
        final ASTContainer astContainer,
        final QueryBindingSet globallyScopedBS,
        final Dataset dataset) throws QueryEvaluationException {

    final AST2BOpContext context = new AST2BOpContext(astContainer, store);

    final QueryRoot optimizedQuery = 
            optimizeQuery(astContainer, context, globallyScopedBS, dataset);
    
    // Get the projection for the query.
    final IVariable<?>[] projected = astContainer.getOptimizedAST()
            .getProjection().getProjectionVars();

    final List<String> projectedSet = new LinkedList<String>();

    for (IVariable<?> var : projected)
        projectedSet.add(var.getName());

    final boolean materializeProjectionInQuery = context.materializeProjectionInQuery
            && !optimizedQuery.hasSlice();

    final CloseableIteration<BindingSet, QueryEvaluationException> itr = ASTEvalHelper
            .evaluateQuery(astContainer, context, 
                    materializeProjectionInQuery, projected);

    TupleQueryResult r = null;
    try {
        r = new TupleQueryResultImpl(projectedSet, itr);
        return r;
    } finally {
        if (r == null) {
            /**
             * Ensure query is terminated if assignment to fails. E.g., if
             * interrupted during the ctor.
             * 
             * @see <a
             *      href="https://sourceforge.net/apps/trac/bigdata/ticket/707">
             *      BlockingBuffer.close() does not unblock threads </a>
             */
            itr.close();
        }
    }

}
 
Example #23
Source File: TestRDRHistory.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public Properties getProperties(final Class<? extends RDRHistory> cls) {
    
    final Properties props = super.getProperties();
    
    // no inference
    props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false");
    props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName());
    props.setProperty(BigdataSail.Options.JUSTIFY, "false");
    props.setProperty(BigdataSail.Options.TEXT_INDEX, "false");
    
    // turn on RDR history
    props.setProperty(AbstractTripleStore.Options.RDR_HISTORY_CLASS, cls.getName());
    
    return props;
    
}
 
Example #24
Source File: TestSubjectCentricFullTextIndex.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertExpectedHits(final AbstractTripleStore store,
        final String query, final String languageCode,
        final float minCosine, final BigdataValue[] expected) {

    final Hiterator hitr = store.getLexiconRelation().getSubjectCentricSearchEngine()
            .search(new FullTextQuery(
            		query, languageCode, false/* prefixMatch */, 
                    null,//regex
                    false/* matchAllTerms */,
                    false, // matchExact
            		minCosine, 1.0d/* maxCosine */,
                    1/* minRank */, Integer.MAX_VALUE/* maxRank */,
                    Long.MAX_VALUE,//2L/* timeout */,
                    TimeUnit.MILLISECONDS// TimeUnit.SECONDS
                    ));

    // assertEquals("#hits", (long) expected.length, itr.size());

    final ICloseableIterator<BigdataValue> itr2 = new BigdataValueIteratorImpl(
            store, new ChunkedWrappedIterator<IV>(new Striterator(hitr)
                    .addFilter(new Resolver() {
                        private static final long serialVersionUID = 1L;

                        @Override
                        protected Object resolve(Object e) {
                        	final Hit hit = (Hit) e;
                        	if (log.isDebugEnabled()) {
                        		log.debug(hit);
                        	}
                            return hit.getDocId();
                        }
                    })));

    try {

        TestSPOKeyOrder.assertSameIteratorAnyOrder(expected, itr2);

    } catch (AssertionFailedError ex) {

        fail("minCosine=" + minCosine + ", expected="
                + Arrays.toString(expected) + ", actual=" + hitr, ex);

    } finally {

        itr2.close();

    }
    
}
 
Example #25
Source File: ASTDeferredIVResolution.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Do deferred resolution of IVs, which were left unresolved while preparing the update
 * @param store - triple store, which will be used for values resolution
 * @param ast - AST model of the update, which should be resolved
 * @param bs - binding set, which should be resolved
 * @param dataset 
 * @return 
 * @throws MalformedQueryException
 */
public static DeferredResolutionResult resolveUpdate(final AbstractTripleStore store, final ASTContainer ast, final BindingSet bs, final Dataset dataset) throws MalformedQueryException {

    final ASTDeferredIVResolution termsResolver = new ASTDeferredIVResolution(store);

    // process provided binding set
    BindingSet resolvedBindingSet = termsResolver.handleBindingSet(store, bs);

    // process provided dataset
    final Dataset resolvedDataset = termsResolver.handleDataset(store, dataset);

    /*
     * Prevent running IV resolution more than once.
     * Property RESOLVED is set after resolution completed,
     * so subsequent repetitive calls to update execute
     * (for example with different bindings) would not result
     * in running resolution again.
     */
    if (Boolean.TRUE.equals(ast.getProperty(Annotations.RESOLVED))) {
        /*
         * Resolve binding set or dataset if there are any values to be processed
         */
        if (!termsResolver.deferred.isEmpty()) {
            termsResolver.resolveIVs(store);
        }
        return new DeferredResolutionResult(resolvedBindingSet, resolvedDataset);
    }
    
    final long beginNanos = System.nanoTime();
    
    final UpdateRoot qc = (UpdateRoot)ast.getProperty(Annotations.ORIGINAL_AST);
    
    /*
     * Handle dataset declaration. It only appears for DELETE/INSERT
     * (aka ASTModify). It is attached to each DeleteInsertNode for
     * which it is given.
     */
    final Map<IDataSetNode, List<ASTDatasetClause>> dcLists = new LinkedHashMap<>();
    for (final Update update: qc.getChildren()) {
        if (update instanceof IDataSetNode) {
            final List<ASTDatasetClause> dcList = new ArrayList();
            dcList.addAll(update.getDatasetClauses());
            dcLists.put((IDataSetNode)update, dcList);
        }
    }
    

    termsResolver.resolve(store, qc, dcLists, bs);

    if (ast.getOriginalUpdateAST().getPrefixDecls()!=null && !ast.getOriginalUpdateAST().getPrefixDecls().isEmpty()) {

        qc.setPrefixDecls(ast.getOriginalUpdateAST().getPrefixDecls());

    }

    ast.setOriginalUpdateAST(qc);

    ast.setResolveValuesTime(System.nanoTime() - beginNanos);

    ast.setProperty(Annotations.RESOLVED, Boolean.TRUE);

    return new DeferredResolutionResult(resolvedBindingSet, resolvedDataset);

}
 
Example #26
Source File: TestGeoSpatialServiceEvaluation.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Properties getProperties() {

    // Note: clone to avoid modifying!!!
    final Properties properties = (Properties) super.getProperties().clone();

    // turn on quads.
    properties.setProperty(AbstractTripleStore.Options.QUADS, "false");

    // TM not available with quads.
    properties.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE,"false");

    // turn off axioms.
    properties.setProperty(AbstractTripleStore.Options.AXIOMS_CLASS,
            NoAxioms.class.getName());

    // no persistence.
    properties.setProperty(com.bigdata.journal.Options.BUFFER_MODE,
            BufferMode.Transient.toString());

    // enable GeoSpatial index
    properties.setProperty(
       com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL, "true");

    properties.setProperty(
            com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL_DATATYPE_CONFIG + ".0",
            "{\"config\": "
            + "{ \"uri\": \"http://www.bigdata.com/rdf/geospatial#geoSpatialLiteral\", "
            + "\"fields\": [ "
            + "{ \"valueType\": \"DOUBLE\", \"multiplier\": \"100000\", \"serviceMapping\": \"LATITUDE\" }, "
            + "{ \"valueType\": \"DOUBLE\", \"multiplier\": \"100000\", \"serviceMapping\": \"LONGITUDE\" }, "
            + "{ \"valueType\": \"LONG\", \"serviceMapping\" : \"TIME\"  } "
            + "]}}");
    
    properties.setProperty(
            com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL_DEFAULT_DATATYPE,
            "http://www.bigdata.com/rdf/geospatial#geoSpatialLiteral");
    
    return properties;

}
 
Example #27
Source File: InsertStatementsOp.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public ChunkTask(final BOpContext<IBindingSet> context,
        final InsertStatementsOp op) {

    this.context = context;

    final String namespace = ((String[]) op
            .getRequiredProperty(Annotations.RELATION_NAME))[0];

    final long timestamp = (Long) op
            .getRequiredProperty(Annotations.TIMESTAMP);

    this.tripleStore = (AbstractTripleStore) context.getResource(
            namespace, timestamp);

    this.sids = tripleStore.isStatementIdentifiers();

    this.quads = tripleStore.isQuads();

}
 
Example #28
Source File: TestStatementBuffer.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Test verifies detection of duplicate terms and their automatic
     * replacement with a canonicalizing term.
     */
    public void test_handleStatement_distinctTerm() {

        final int capacity = 5;

        final AbstractTripleStore store = getStore();

        try {

			final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>(
					store, capacity);

//            assertTrue(buffer.distinct);

            /*
             * add a statement.
             */

            final URI s1 = new URIImpl("http://www.foo.org");
            final URI p1 = RDF.TYPE;
            final URI o1 = RDFS.RESOURCE;
            final URI c1 = null; // no context.

            buffer.handleStatement(s1, p1, o1, c1, StatementEnum.Explicit);

            assertEquals(8, buffer.numURIs);
            assertEquals(0, buffer.numLiterals);
            assertEquals(0, buffer.numBNodes);
            assertEquals(1, buffer.numStmts);

            /*
             * add another statement.
             */

            final URI s2 = new URIImpl("http://www.foo.org"); // duplicate term!
            final URI p2 = RDFS.LABEL;
            final Literal o2 = new LiteralImpl("test lit.");
            final URI c2 = null;

            buffer.handleStatement(s2, p2, o2, c2, StatementEnum.Explicit);

            assertEquals(9, buffer.numURIs); // only 4 since one is duplicate.
            assertEquals(1, buffer.numLiterals);
            assertEquals(0, buffer.numBNodes);
            assertEquals(2, buffer.numStmts);

            /*
             * add a duplicate statement.
             */

            final URI s3 = new URIImpl("http://www.foo.org"); // duplicate term
            final URI p3 = RDFS.LABEL;                        // duplicate term
            final Literal o3 = new LiteralImpl("test lit.");  // duplicate term
            final URI c3 = null;

            buffer.handleStatement(s3, p3, o3, c3, StatementEnum.Explicit);

            assertEquals(9, buffer.numURIs);
            assertEquals(1, buffer.numLiterals);
            assertEquals(0, buffer.numBNodes);
            assertEquals(3, buffer.numStmts);

            /*
             * add a duplicate statement using the _same_ term objects.
             */

            buffer.handleStatement(s3, p3, o3, c3, StatementEnum.Explicit);

            assertEquals(9, buffer.numURIs);
            assertEquals(1, buffer.numLiterals);
            assertEquals(0, buffer.numBNodes);
            assertEquals(4, buffer.numStmts);
            
            buffer.flush();

        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example #29
Source File: TestGeoSpatialServiceEvaluationQuads.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Properties getProperties() {

    // Note: clone to avoid modifying!!!
    final Properties properties = (Properties) super.getProperties().clone();

    // turn on quads.
    properties.setProperty(AbstractTripleStore.Options.QUADS, "true");

    // TM not available with quads.
    properties.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE,"false");

    // turn off axioms.
    properties.setProperty(AbstractTripleStore.Options.AXIOMS_CLASS,
            NoAxioms.class.getName());

    // no persistence.
    properties.setProperty(com.bigdata.journal.Options.BUFFER_MODE,
            BufferMode.Transient.toString());

    // enable GeoSpatial index
    properties.setProperty(
       com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL, "true");

    properties.setProperty(
        com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL_DATATYPE_CONFIG + ".0",
        "{\"config\": "
        + "{ \"uri\": \"http://www.bigdata.com/rdf/geospatial#geoSpatialLiteral\", "
        + "\"fields\": [ "
        + "{ \"valueType\": \"DOUBLE\", \"multiplier\": \"100000\", \"serviceMapping\": \"LATITUDE\" }, "
        + "{ \"valueType\": \"DOUBLE\", \"multiplier\": \"100000\", \"serviceMapping\": \"LONGITUDE\" }, "
        + "{ \"valueType\": \"LONG\", \"serviceMapping\" : \"TIME\"  } "
        + "]}}");
    
    properties.setProperty(
            com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL_DEFAULT_DATATYPE,
            "http://www.bigdata.com/rdf/geospatial#geoSpatialLiteral");
    
    return properties;

}
 
Example #30
Source File: TestGeoSpatialQueryVaryOneDimension.java    From database with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Properties getProperties() {

    // Note: clone to avoid modifying!!!
    final Properties properties = (Properties) super.getProperties().clone();

    // turn on quads.
    properties.setProperty(AbstractTripleStore.Options.QUADS, "false");

    // TM not available with quads.
    properties.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE,"false");

    // turn off axioms.
    properties.setProperty(AbstractTripleStore.Options.AXIOMS_CLASS,
            NoAxioms.class.getName());

    // no persistence.
    properties.setProperty(com.bigdata.journal.Options.BUFFER_MODE,
            BufferMode.Transient.toString());

    // enable GeoSpatial index
    properties.setProperty(
       com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL, "true");

    // set up a datatype containing everything, including a dummy literal serializer
    properties.setProperty(
       com.bigdata.rdf.store.AbstractLocalTripleStore.Options.GEO_SPATIAL_DATATYPE_CONFIG + ".0",
       "{\"config\": "
       + "{ \"uri\": \"http://my.custom.datatype/x-y-z-lat-lon-time-coord\", "
       + "\"fields\": [ "
       + "{ \"valueType\": \"DOUBLE\", \"minVal\" : \"-1000\", \"multiplier\": \"10\", \"serviceMapping\": \"x\" }, "
       + "{ \"valueType\": \"DOUBLE\", \"minVal\" : \"-10\", \"multiplier\": \"100\", \"serviceMapping\": \"y\" }, "
       + "{ \"valueType\": \"DOUBLE\", \"minVal\" : \"-2\", \"multiplier\": \"1000\", \"serviceMapping\": \"z\" }, "
       + "{ \"valueType\": \"DOUBLE\", \"minVal\" : \"0\", \"multiplier\": \"1000000\", \"serviceMapping\": \"LATITUDE\" }, "
       + "{ \"valueType\": \"DOUBLE\", \"minVal\" : \"0\", \"multiplier\": \"100000\", \"serviceMapping\": \"LONGITUDE\" }, "
       + "{ \"valueType\": \"LONG\", \"minVal\" : \"0\", \"multiplier\": \"1\", \"serviceMapping\": \"TIME\" }, "
       + "{ \"valueType\": \"LONG\", \"minVal\" : \"0\", \"multiplier\": \"1\", \"serviceMapping\": \"COORD_SYSTEM\" } "
       + "]}}");
    
    properties.setProperty(
       com.bigdata.rdf.store.AbstractLocalTripleStore.Options.VOCABULARY_CLASS,
       "com.bigdata.rdf.sparql.ast.eval.service.GeoSpatialTestVocabulary");
    
    return properties;

}