Java Code Examples for com.bigdata.rdf.store.AbstractTripleStore#__tearDownUnitTest

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore#__tearDownUnitTest . 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: TestDatabaseAtOnceClosure.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void test_fixedPoint_LUBM_U1_As_Full_PipelineJoins()
        throws Exception {

    final String[] dataFiles = readFiles(new File(
    "src/test/resources/data/lehigh/U1"),
    new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.endsWith(".owl");
        }
    });

    // And add in the ontology.
    final List<String> tmp = new LinkedList<String>();
    tmp.add("src/test/resources/data/lehigh/univ-bench-modified-no-bnodes.owl");
    tmp.addAll(Arrays.asList(dataFiles));
    final String[] resources = tmp.toArray(new String[tmp.size()]);

    final Properties properties = getProperties(FullClosure.class, false/* nestedSubquery */);

    final AbstractTripleStore store = getStore(properties);

    try {

        doFixedPointTest(resources, store);

    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example 2
Source File: TestRuleFastClosure_11_13.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Tests {@link RuleFastClosure11} with the minimum data required to compute
     * a single entailment.
     */
    public void test_RuleFastForwardClosure11() throws Exception {
        
        AbstractTripleStore store = getStore();

        try {

            final BigdataValueFactory f = store.getValueFactory();
            
            final IV a = store.addTerm(f.createURI("http://www.bigdata.com/a"));
            final IV b = store.addTerm(f.createURI("http://www.bigdata.com/b"));
            final IV y = store.addTerm(f.createURI("http://www.bigdata.com/y"));
            final IV x = store.addTerm(f.createURI("http://www.bigdata.com/x"));
            final IV z = store.addTerm(f.createURI("http://www.bigdata.com/z"));

            final Vocabulary vocab = store.getVocabulary();

            // told:
            {

                SPO[] told = new SPO[] {
                        //
                        new SPO(x, y, z, StatementEnum.Explicit),
                        //
                        new SPO(y, vocab.get(RDFS.SUBPROPERTYOF), a,
                                StatementEnum.Explicit),
                        //
                        new SPO(a, vocab.get(RDFS.DOMAIN), b,
                                StatementEnum.Explicit) };

                store.addStatements(told, told.length);

            }

            // entails:
            // store.addStatement(x, inf.rdfType.get(), b);

//            store.commit();

            if (log.isInfoEnabled())
                log.info("\n" + store.dumpStore());

            /*
             * (?x, ?y, ?z), (?y, rdfs:subPropertyOf, ?a), (?a, rdfs:domain, ?b) ->
             * (?x, rdf:type, ?b).
             */
            RuleFastClosure11 rule = new RuleFastClosure11(store
                    .getSPORelation().getNamespace(), vocab);

            /*
             * Test run the rule.
             */

            applyRule(store, rule, 1/*solutionCount*/, 1/*mutationCount*/);
            
            // check entailments.
            assertTrue(store.hasStatement(x, vocab.get(RDF.TYPE), b));

//            store.commit();

        } finally {

            store.__tearDownUnitTest();

        }
        
    }
 
Example 3
Source File: TestDatabaseAtOnceClosure.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void test_fixedPoint_Small_Full_PipelineJoins() throws Exception {

        final Properties properties = getProperties(FullClosure.class, false/* nestedSubquery */);

        final AbstractTripleStore store = getStore(properties);

        try {

            doFixedPointTest(new String[] { "small.rdf" }, store);

        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 4
Source File: TestDatabaseAtOnceClosure.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void test_fixedPoint_Small_Fast_PipelineJoins() throws Exception {

        final Properties properties = getProperties(FastClosure.class, false/* nestedSubquery */);

        final AbstractTripleStore store = getStore(properties);

        try {

            doFixedPointTest(new String[] { "small.rdf" }, store);

        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 5
Source File: TestRuleOwlFunctionalProperty.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void test_RuleOwlInverseFunctionalProperty() throws Exception {

        AbstractTripleStore store = getStore();

        try {

            URI john = new URIImpl("http://www.foo.org/john");
            URI paul = new URIImpl("http://www.foo.org/paul");
            URI mary = new URIImpl("http://www.foo.org/mary");
            URI wife = new URIImpl("http://www.foo.org/wife");

            IStatementBuffer buffer = new StatementBuffer(store, 100/* capacity */);
            
            buffer.add(wife, RDF.TYPE, OWL.INVERSEFUNCTIONALPROPERTY);
            buffer.add(john, wife, mary);

            // write on the store.
            buffer.flush();

            // verify statement(s).
            assertTrue(store.hasStatement(wife, RDF.TYPE, OWL.INVERSEFUNCTIONALPROPERTY));
            assertTrue(store.hasStatement(john, wife, mary));
            final long nbefore = store.getStatementCount();

            final Vocabulary vocab = store.getVocabulary();

            final Rule r = new RuleOwlInverseFunctionalProperty(store.getSPORelation()
                    .getNamespace(), vocab);

            // apply the rule.
            applyRule(store, r, -1/*solutionCount*/,0/*mutationCount*/);

            /*
             * validate the state of the primary store.
             */

            // told
            assertTrue(store.hasStatement(wife, RDF.TYPE, OWL.INVERSEFUNCTIONALPROPERTY));
            assertTrue(store.hasStatement(john, wife, mary));

            // final #of statements in the store.
            assertEquals(nbefore, store.getStatementCount());

            // add another S for the inverse functional property
            buffer.add(paul, wife, mary);
            buffer.flush();

            applyRule(store, r, -1/*solutionCount*/, 2/*mutationCount*/);
            
            assertTrue(store.hasStatement(john, OWL.SAMEAS, paul));
            assertTrue(store.hasStatement(paul, OWL.SAMEAS, john));

            // final #of statements in the store.
            assertEquals(nbefore+3, store.getStatementCount());
            
//            try {
//            	
//	            // apply the rule.
//	            applyRule(store, r, -1/*solutionCount*/,0/*mutationCount*/);
//	            
//	            fail("should have violated the inverse functional property");
//	            
//            } catch (Exception ex) {
//            	
//                if (!InnerCause.isInnerCause(ex,
//                        ConstraintViolationException.class)) {
//                    fail("Expected: " + ConstraintViolationException.class);
//                }
////            	final ExecutionExceptions ex2 = (ExecutionExceptions)
////            			InnerCause.getInnerCause(ex, ExecutionExceptions.class);
////            	
////            	Throwable t = ex2.causes().get(0);
////            	while (t.getCause() != null)
////            		t = t.getCause();
////            	
////            	if (!(t instanceof ConstraintViolationException))
////            		fail("inner cause should be a ConstraintViolationException");
//            	
//            }

        } finally {

            store.__tearDownUnitTest();

        }
        
    }
 
Example 6
Source File: TestDatabaseAtOnceClosure.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public void test_fixedPoint_SampleData_Fast_PipelineJoins()
        throws Exception {

    final Properties properties = getProperties(FastClosure.class, false/* nextedSubquery */);

    final AbstractTripleStore store = getStore(properties);

    try {

        doFixedPointTest(new String[] { "sample data.rdf" }, store);

    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example 7
Source File: TestTruthMaintenance.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * This test demonstrates an infinite loop in TM arising from owl:sameAs.
     */
    public void test_infiniteloop() {
     
//        if(true) fail("re-enable this test");
        
        final URI a = new URIImpl("http://www.bigdata.com/a");
        final URI b = new URIImpl("http://www.bigdata.com/b");
        final URI entity = new URIImpl("http://www.bigdata.com/Entity");
        final URI sameAs = OWL.SAMEAS;
//        /*
//         * Note: not using rdf:type to avoid entailments about (x rdf:type
//         * Class) and (x rdfs:subClassOf y) that are not required by this test.
//         */
//      URI rdfType = new URIImpl("http://www.bigdata.com/type");
        final URI rdfType = RDF.TYPE;

        final AbstractTripleStore store = getStore();
        
        try {
            
            final InferenceEngine inf = store.getInferenceEngine();

            final TruthMaintenance tm = new TruthMaintenance(inf);
            
            // add some assertions and verify aspects of their closure.
            {

                final StatementBuffer assertionBuffer = new StatementBuffer(tm
                        .newTempTripleStore(), store, 100/* capacity */, 10/*queueCapacity*/);

                // stmt a
                assertionBuffer.add(a, rdfType, entity );
                // assertionBuffer.add(a, x, y );
                
                // stmt b
                assertionBuffer.add(b, rdfType, entity );
                
                // assert the sameas
                assertionBuffer.add(a, sameAs, b );

                // flush statements to the tempStore.
                assertionBuffer.flush();

                // perform closure and write on the database.
                tm.assertAll((TempTripleStore) assertionBuffer
                        .getStatementStore());

                // dump after closure.
                if (log.isInfoEnabled())
                    log.info("\ndump after closure:\n"
                            + store.dumpStore(store, true, true, false, true));

            }

            /*
             * retract stmt A and update the closure.
             * 
             * then verify that the retracted statement is gone and that the
             * other explicit statements were not touched.
             */
            {

                final StatementBuffer retractionBuffer = new StatementBuffer(tm
                        .newTempTripleStore(), store, 100/* capacity */, 10/*queueCapacity*/);

                // retract the sameas
                retractionBuffer.add(a, sameAs, b);

                // flush statements to the tempStore.
                retractionBuffer.flush();

                // update the closure.
                tm.retractAll((TempTripleStore) retractionBuffer
                        .getStatementStore());

                // dump after re-closure.
                if (log.isInfoEnabled())
                    log.info("\ndump after re-closure:\n"
                            + store.dumpStore(store, true, true, false, true));

            }

        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 8
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 9
Source File: TestStatementBuffer.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void test_ctor02() {
        
    	final int capacity = 27;
    	
    	final int queueCapacity = 10;
        
        final AbstractTripleStore store = getStore();
        
        try {

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

            assertEquals(store, buffer.getDatabase());
//            assertTrue(buffer.distinct);
            assertEquals(capacity, buffer.getCapacity());
            assertEquals(capacity * store.getSPOKeyArity() + 5, buffer.values.length);
            assertEquals(capacity, buffer.stmts.length);
            assertEquals(5, buffer.numURIs);
            assertEquals(0, buffer.numLiterals);
            assertEquals(0, buffer.numBNodes);
            assertEquals(0, buffer.numStmts);

        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 10
Source File: TestMappedProgram.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void testMappedRuleWithTwoTails() {

        final AbstractTripleStore store = getStore();

        try {

            final Vocabulary vocab = store.getVocabulary();

            final boolean parallel = false; // actual value should not matter.

            final boolean closure = false; // actual value should not matter,

            // will map the rule across the database and the focusStore.
            final MappedProgram program = new MappedProgram(getName(),
                    focusStore, parallel, closure);

            final IRule rule = new RuleRdfs09(database,vocab);

            log.info("\n"+rule);
            
            program.addStep(rule);

            log.info("\n"+program);
            
        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 11
Source File: TestMappedProgram.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 
 */
public void testClosureOfMappedRuleWithOneTail() {

    final AbstractTripleStore store = getStore();

    try {

        final Vocabulary vocab = store.getVocabulary();

        final boolean parallel = false; // actual value should not matter.

        final boolean closure = false; // actual value should not matter,

        // will map the rule across the database and the focusStore.
        final MappedProgram program = new MappedProgram(getName(),
                focusStore, parallel, closure);

        final IRule rule = new RuleOwlEquivalentProperty(database, vocab);

        log.info("\n"+rule);
        
        program.addClosureOf(rule);

        log.info("\n"+program);
        
    } finally {

        store.__tearDownUnitTest();

    }

}
 
Example 12
Source File: TestMappedProgram.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void testClosureOfMappedRuleWithTwoTails() {

        final AbstractTripleStore store = getStore();

        try {

            final Vocabulary vocab = store.getVocabulary();

            final boolean parallel = false; // actual value should not matter.

            final boolean closure = false; // actual value should not matter,

            // will map the rule across the database and the focusStore.
            final MappedProgram program = new MappedProgram(getName(),
                    focusStore, parallel, closure);

            final IRule rule = new RuleRdfs09(database,vocab);

            log.info("\n"+rule);
            
            program.addClosureOf(rule);

            log.info("\n"+program);
            
        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 13
Source File: TestDatabaseAtOnceClosure.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void test_fixedPoint_LUBM_U1_As_Fast_PipelineJoins() throws Exception {

        final String[] dataFiles = readFiles(new File("src/test/resources/data/lehigh/U1"),
                new FilenameFilter() {
                    public boolean accept(File dir, String name) {
                        return name.endsWith(".owl");
                    }
                });

        // And add in the ontology.
        final List<String> tmp = new LinkedList<String>();
        tmp.add("src/test/resources/data/lehigh/univ-bench-modified-no-bnodes.owl");
        tmp.addAll(Arrays.asList(dataFiles));
        final String[] resources = tmp.toArray(new String[tmp.size()]);
        
        final Properties properties = getProperties(FastClosure.class, false/* nestedSubquery */);

        final AbstractTripleStore store = getStore(properties);

        try {

            doFixedPointTest(resources, store);

        } finally {

            store.__tearDownUnitTest();

        }

    }
 
Example 14
Source File: TestStatementBuffer.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
* Test verifies interpretation of triples by the {@link StatementBuffer} by
* validating how the triples written onto the statement buffer are loaded
* into the {@link AbstractTripleStore}.
*/
  public void test_statementBuffer() {

      final int capacity = 5;

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

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

      final AbstractTripleStore store = getStore(properties);

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

      		final BigdataValueFactory vf = store.getValueFactory();
      	
	final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>(
			store, capacity);

          /*
           * 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.add(vf.createStatement(s1, p1, o1, c1, StatementEnum.Explicit));

          /*
           * 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.add(vf.createStatement(s2, p2, o2, c2, StatementEnum.Explicit));

          /*
           * 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);

          // store is still empty (statements are buffered).
          assertEquals(0,store.getStatementCount());

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

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

	assertTrue(store.hasStatement(s1, p1, o1));
	assertTrue(store.hasStatement(s2, p2, o2));
	assertFalse(store.hasStatement(s1, p2, o1));

      } finally {

          store.__tearDownUnitTest();

      }

  }
 
Example 15
Source File: TestTruthMaintenance.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
     * A simple test of {@link TruthMaintenance} in which some statements are
     * asserted and their closure is computed and aspects of that closure are
     * verified (this is based on rdfs11).
     */
    public void test_assertAll_01() {

        TempTripleStore tempStore = null;
        final AbstractTripleStore store = getStore();
        
        try {
            
            final TruthMaintenance tm = new TruthMaintenance(store.getInferenceEngine());
            
            final BigdataValueFactory f = store.getValueFactory();
            
            final BigdataURI U = f.createURI("http://www.bigdata.com/U");
            final BigdataURI V = f.createURI("http://www.bigdata.com/V");
            final BigdataURI X = f.createURI("http://www.bigdata.com/X");

            final BigdataURI rdfsSubClassOf = f.asValue(RDFS.SUBCLASSOF);

            tempStore = tm.newTempTripleStore();

            // buffer writes on the tempStore.
            {

                final StatementBuffer assertionBuffer = new StatementBuffer(
                        tempStore, store, 10/* capacity */, 10/*queueCapacity*/);

                assertTrue(tempStore == assertionBuffer.getStatementStore());
                
                assertionBuffer.add(U, rdfsSubClassOf, V);
                assertionBuffer.add(V, rdfsSubClassOf, X);

                // flush to the temp store.
                assertionBuffer.flush();
                
            }

            if (log.isInfoEnabled())
                log.info("\n\ntempStore:\n"
                        + tempStore.dumpStore(store,
                                true, true, false, true));

            // perform closure and write on the database.
            tm.assertAll(tempStore);

            if (log.isInfoEnabled())
                log.info("\n\ndatabase:\n"
                        + store.dumpStore(store, true, true, false, true));
            
            // explicit.
            assertTrue(store.hasStatement(U, rdfsSubClassOf, V));
            assertTrue(store.hasStatement(V, rdfsSubClassOf, X));

            // inferred.
            assertTrue(store.hasStatement(U, rdfsSubClassOf, X));
            
        } finally {
        // Note: This will be torn down with the [store].
//            if (tempStore != null)
//                tempStore.__tearDownUnitTest();
            
            store.__tearDownUnitTest();
            
        }
        
    }
 
Example 16
Source File: TestRuleOwlInverseOf.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Test where the data satisifies the rule exactly once.
 * 
 * <pre>
 *   owl:InverseOf2 : (a owl:inverseOf b), (x a z) -&gt; (z b x).
 * </pre>
 * @throws Exception 
 */
public void test_owlInverseOf2() throws Exception {

    AbstractTripleStore store = getStore();

    try {

        URI A = new URIImpl("http://www.foo.org/A");
        URI B = new URIImpl("http://www.foo.org/B");
        URI Z = new URIImpl("http://www.foo.org/Z");
        URI X = new URIImpl("http://www.foo.org/X");
        URI Y = new URIImpl("http://www.foo.org/Y");

        IStatementBuffer buffer = new StatementBuffer(store, 100/* capacity */);
        
        buffer.add(A, OWL.INVERSEOF, B);
        buffer.add(X, A, Z);

        // write on the store.
        buffer.flush();

        // verify statement(s).
        assertTrue(store.hasStatement(A, OWL.INVERSEOF, B));
        assertTrue(store.hasStatement(X, A, Z));
        final long nbefore = store.getStatementCount();

        final Vocabulary vocab = store.getVocabulary();

        final Rule r = new RuleOwlInverseOf2(store.getSPORelation()
                .getNamespace(), vocab);

        // apply the rule.
        applyRule(store, r, -1/* solutionCount */, 1/* mutationCount */);

        /*
         * validate the state of the primary store.
         */

        // told
        assertTrue(store.hasStatement(A, OWL.INVERSEOF, B));
        assertTrue(store.hasStatement(X, A, Z));

        // entailed
        assertTrue(store.hasStatement(Z, B, X));

        // final #of statements in the store.
        assertEquals(nbefore + 1, store.getStatementCount());

    } finally {

        store.__tearDownUnitTest();

    }
    
}
 
Example 17
Source File: TestVocabulary.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void test_RdfsVocabulary() {
        
        final Properties properties = getProperties();
        
        // override the default.
        properties.setProperty(Options.VOCABULARY_CLASS, RDFSVocabulary.class
                .getName());

        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class
                .getName());
        
        AbstractTripleStore store = getStore(properties);
        
        try {

            final Vocabulary vocab = store.getVocabulary();

            assertTrue(vocab instanceof RDFSVocabulary);

            // verify (de-)serialization.
            doRoundTripTest(vocab);

            // lookup/add some values.
            final BigdataValueFactory f = store.getValueFactory();

            final BigdataURI rdfType = f.asValue(RDF.TYPE);
            final BigdataURI rdfProperty = f.asValue(RDF.PROPERTY);
            final BigdataURI unknownURI = f.createURI("http://www.bigdata.com/unknown");
            
            // resolve term ids.
            store.addTerms(new BigdataValue[] { rdfType, rdfProperty, unknownURI });

            // point tests for known values.
            
            assertEquals(rdfType.getIV(), vocab.get(RDF.TYPE));
            
            assertEquals(rdfProperty.getIV(), vocab.get(RDF.PROPERTY));

            // point test for an unknown value.
            assertNull(vocab.get(unknownURI));
            
//            try {
//             
//                vocab.get(unknownURI);
//                
//                fail("Expecting: " + IllegalArgumentException.class);
//                
//            } catch (IllegalArgumentException ex) {
//                
//                log.info("Ignoring expected exception: " + ex);
//                
//            }

            if (store.isStable()) {

                store = reopenStore(store);

                final Vocabulary vocab2 = store.getVocabulary();

                assertSameVocabulary(vocab, vocab2);
                
            }
            
        } finally {
            
            store.__tearDownUnitTest();
            
        }
        
    }
 
Example 18
Source File: TestAddTerms.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void test_addTerms() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
                .getName());

        // test w/o axioms - they imply a predefined vocab.
        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
        
        // test w/o the full text index.
        properties.setProperty(Options.TEXT_INDEX, "false");

        // test w/o inlining
        properties.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");

        AbstractTripleStore store = getStore(properties);
        
        try {

            final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

            // lookup/add some values.
            final BigdataValueFactory f = store.getValueFactory();

            terms.add(f.asValue(RDF.TYPE));
            terms.add(f.asValue(RDF.PROPERTY));
            terms.add(f.createURI(getVeryLargeURI()));
            
            terms.add(f.createLiteral("test"));
            terms.add(f.createLiteral("test", "en"));
            terms.add(f.createLiteral(getVeryLargeLiteral()));

            terms.add(f.createLiteral("10", f
                    .createURI("http://www.w3.org/2001/XMLSchema#int")));

            terms.add(f.createLiteral("12", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

            terms.add(f.createLiteral("12.", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

            terms.add(f.createLiteral("12.0", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

            terms.add(f.createLiteral("12.00", f
                    .createURI("http://www.w3.org/2001/XMLSchema#float")));

			if (store.getLexiconRelation().isStoreBlankNodes()) {
	            /*
	             * Note: Blank nodes will not round trip through the lexicon unless
	             * the "told bnodes" is enabled.
	             */
				terms.add(f.createBNode());
				terms.add(f.createBNode("a"));
	            terms.add(f.createBNode(getVeryLargeLiteral()));

			}

			final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

			if (store.isStable()) {

				store.commit();

				store = reopenStore(store);

				// verify same reverse mappings.

                final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                        .getTerms(ids.keySet());

                assertEquals(ids.size(), ids2.size());

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

                    final IV<?,?> id = e.getKey();
                    
                    assertEquals("Id mapped to a different term? : termId="
                            + id, ids.get(id), ids2.get(id));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 19
Source File: TestAccessPaths.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
* 
*/
  public void test_TERMS_accessPaths() {
  
      final Properties properties = getProperties();
      
      // test w/o predefined vocab.
      properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
              .getName());

      // test w/o the full text index.
      properties.setProperty(Options.TEXT_INDEX, "false");

      final AbstractTripleStore store = getStore(properties);
      
      try {

          final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

          // lookup/add some values.
          final BigdataValueFactory f = store.getValueFactory();

          final BigdataValue rdfType;
          final BigdataValue largeLiteral;
          terms.add(rdfType=f.asValue(RDF.TYPE));
          terms.add(f.asValue(RDF.PROPERTY));
          terms.add(f.createLiteral("test"));
          terms.add(f.createLiteral("test", "en"));
          terms.add(f.createLiteral("10", f
                  .createURI("http://www.w3.org/2001/XMLSchema#int")));

          terms.add(f.createLiteral("12", f
                  .createURI("http://www.w3.org/2001/XMLSchema#float")));

          terms.add(f.createLiteral("12.", f
                  .createURI("http://www.w3.org/2001/XMLSchema#float")));

          terms.add(f.createLiteral("12.0", f
                  .createURI("http://www.w3.org/2001/XMLSchema#float")));

          terms.add(f.createLiteral("12.00", f
                  .createURI("http://www.w3.org/2001/XMLSchema#float")));
          
          terms.add(largeLiteral=f.createLiteral(TestAddTerms.getVeryLargeLiteral()));

          if (store.getLexiconRelation().isStoreBlankNodes()) {
              /*
               * Note: Blank nodes will not round trip through the lexicon
               * unless the "told bnodes" is enabled.
               */
              terms.add(f.createBNode());
              terms.add(f.createBNode("a"));
          }

          final int size = terms.size();

          final BigdataValue[] a = terms.toArray(new BigdataValue[size]);

          // resolve term ids.
          store.getLexiconRelation().addTerms(a, size, false/* readOnly */);

          // populate map w/ the assigned term identifiers.
          final Collection<IV> ids = new ArrayList<IV>();

          for (BigdataValue t : a) {

              ids.add(t.getIV());

          }

          // Test id2terms for reverse lookup.

          doAccessPathTest(rdfType, LexiconKeyOrder.ID2TERM, store);
          
          doAccessPathTest(largeLiteral, LexiconKeyOrder.BLOBS, store);
	
      } finally {

          store.__tearDownUnitTest();

      }

  }
 
Example 20
Source File: TestInlining.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
     * Unsigned numerics should not be inlined at this time.
     */
    public void test_unsigned() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, NoVocabulary.class
                .getName());

        // test w/o axioms - they imply a predefined vocab.
        properties.setProperty(Options.AXIOMS_CLASS, NoAxioms.class.getName());
        
        // test w/o the full text index.
        properties.setProperty(Options.TEXT_INDEX, "false");

        AbstractTripleStore store = getStore(properties);
        
        try {

            final Collection<BigdataValue> terms = new HashSet<BigdataValue>();

            // lookup/add some values, ensure range is beyond max signed values.
            final BigdataValueFactory f = store.getValueFactory();
            
            terms.add(f.createLiteral("135", f
                    .createURI(XSD.UNSIGNED_BYTE.toString())));

            terms.add(f.createLiteral(""+ (10L + Integer.MAX_VALUE), f
                    .createURI(XSD.UNSIGNED_INT.toString())));

            terms.add(f.createLiteral("" + (Short.MAX_VALUE + 10), f
                    .createURI(XSD.UNSIGNED_SHORT.toString())));

            terms.add(f.createLiteral(BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(10)).toString(), f
                    .createURI(XSD.UNSIGNED_LONG.toString())));

            /*
             * Note: Blank nodes will not round trip through the lexicon unless
             * the "told bnodes" is enabled.
             */
//            terms.add(f.createBNode());
//            terms.add(f.createBNode("a"));

            final Map<IV<?,?>, BigdataValue> ids = doAddTermsTest(store, terms);

            if (store.isStable()) {
                
                store.commit();
                
                store = reopenStore(store);

                // verify same reverse mappings.

                final Map<IV<?,?>, BigdataValue> ids2 = store.getLexiconRelation()
                        .getTerms(ids.keySet());

                assertEquals(ids.size(),ids2.size());
                
                for (Map.Entry<IV<?, ?>, BigdataValue> e : ids.entrySet()) {

                    final IV<?, ?> id = e.getKey();

                    // Should be inlined
                    assertTrue(store.isInlineLiterals() == id.isInline());
                    
                    assertEquals("Id mapped to a different term? : termId="
                            + id, ids.get(id), ids2.get(id));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }