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

The following examples show how to use com.bigdata.rdf.store.AbstractTripleStore#getValueFactory() . 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: GeoSpatialServiceFactory.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * The search function itself, implementing a search request for a single
 * query.
 * 
 * @param query
 *           the geospatial search query
 * @param kb
 *           the triple store to issue search against
 * 
 * @return an iterator over the search results
 */
public ICloseableIterator<IBindingSet> search(
      final GeoSpatialQuery query, final AbstractTripleStore kb) {

   final BOpContextBase context = new BOpContextBase(
      QueryEngineFactory.getInstance().getQueryController(kb.getIndexManager()));
   
   geoSpatialCounters.registerGeoSpatialSearchRequest();

   final GlobalAnnotations globals = new GlobalAnnotations(kb
         .getLexiconRelation().getNamespace(), kb.getSPORelation()
         .getTimestamp());
   
   final BigdataValueFactory vf = kb.getValueFactory();

   final BlockingBuffer<IBindingSet[]> buffer = 
      new BlockingBuffer<IBindingSet[]>(globalBufferChunkOfChunksCapacity);
      
   final FutureTask<Void> ft = 
      new FutureTask<Void>(new GeoSpatialServiceCallTask(
         buffer, query.normalize(), kb, vars, context, globals, vf, geoSpatialCounters, 
         executor, numTasks, minDatapointsPerTask, threadLocalBufferCapacity, stats));
   
   buffer.setFuture(ft); // set the future on the buffer
   kb.getIndexManager().getExecutorService().submit(ft);
   
   return new ChunkConsumerIterator<IBindingSet>(buffer.iterator());

}
 
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: TestRuleFastClosure_11_13.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
     * Tests {@link RuleFastClosure13} with the minimum data required to compute
     * a single entailment.
     * @throws Exception 
     */
    public void test_RuleFastForwardClosure13() 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.RANGE), b,
                                StatementEnum.Explicit) };

                store.addStatements(told, told.length);

            }

            // entails:
            // store.addStatement(z, 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) ->
             * (?z, rdf:type, ?b).
             */
            RuleFastClosure13 rule = new RuleFastClosure13(store
                    .getSPORelation().getNamespace(), vocab);

            /*
             * Test run the rule.
             */

            applyRule(store, rule, 1/*solutionCount*/, 1/*mutationCount*/);

            // check entailments.
            assertTrue(store.hasStatement(z, vocab.get(RDF.TYPE), b));

//            store.commit();

        } finally {

            store.__tearDownUnitTest();

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

		final Properties properties = getProperties();

		AbstractTripleStore store = getStore(properties);

		try {

			final BigdataValueFactory vf = store.getValueFactory();

			final StatementBuffer<BigdataStatement> sb = new StatementBuffer<BigdataStatement>(
					store, 4 /* capacity */);

			BigdataURI pred = vf
					.createURI("http://blazegraph.com/Position#hasMarketValue");
			BigdataValue obj = vf.createLiteral("100.00");

			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E
			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_TaxCost
			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_UnrealizedGain
			// http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_WashSale

			final BigdataURI[] uris = new BigdataURI[] {
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_TaxCost"),
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_UnrealizedGain"),
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E"),
					vf.createURI("http://blazegraph.com/Data#Position_010072F0000038090100000000D56C9E_WashSale") };

			final String[] localNames = new String[] {
					"Position_010072F0000038090100000000D56C9E_TaxCost",
					"Position_010072F0000038090100000000D56C9E_UnrealizedGain",
					"Position_010072F0000038090100000000D56C9E",
					"Position_010072F0000038090100000000D56C9E_WashSale" };


			for (int i = 0; i < uris.length; i++) {
				sb.add(uris[i], pred, obj);
			}

			sb.flush();
			store.commit();

			if (log.isDebugEnabled())
				log.debug(store.dumpStore());

			for (int i = 0; i < uris.length; i++) {

				final BigdataURI uri = uris[i];

				if (log.isDebugEnabled()) {
					log.debug("Checking " + uri.getNamespace() + " "
							+ uri.getLocalName() + " inline: "
							+ uri.getIV().isInline());
					log.debug(localNames[i] + " : " + uri.getLocalName());
				}

				//Check it is inlined
				assertTrue(uri.getIV().isInline());

				//Check the local names are correct
				assertTrue(localNames[i].equals(uri.getLocalName()));
			}

		} finally {
			store.__tearDownUnitTest();
		}

	}
 
Example 5
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 6
Source File: GASService.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 
 * @param outVars
 *            The declared output variables (the ones that the
 *            caller wants to extract). Any position that will not
 *            be extracted is a <code>null</code>.
 */
public BindingSetReducer(//
        final IVariable<?>[] outVars,
        final AbstractTripleStore store,
        final IGASProgram<VS, ES, ST> gasProgram,
        final IGASContext<VS, ES, ST> ctx) {

    this.outVars = outVars;

    this.store = store;

    this.lex = store.getLexiconRelation();
    
    this.vf = store.getValueFactory();
    
    this.binderList = gasProgram.getBinderList();

}
 
Example 7
Source File: TestAddTerms.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Unit test for addTerms() when the {@link BigdataValue}[] contains
 * distinct instances of {@link BigdataValue}s which are equals().
 */
public void test_duplicates_distinct_references() {

    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 xsd inlining
    properties.setProperty(Options.INLINE_XSD_DATATYPE_LITERALS, "false");

    AbstractTripleStore store = getStore(properties);
    
    try {

        // Note: List allows duplicates!
        final Collection<BigdataValue> terms = new LinkedList<BigdataValue>();

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

        // Add two distinct instances of the same Value.
        terms.add(f.asValue(RDF.TYPE));
        terms.add(f.asValue(RDF.TYPE));
        assertEquals(2,terms.size());
        
        // Add two distinct instances of the same Value.
        terms.add(f.createURI(getVeryLargeURI()));
        terms.add(f.createURI(getVeryLargeURI()));
        assertEquals(4,terms.size());

        // Add two distinct instances of the same Value.
        terms.add(f.createLiteral("test"));
        terms.add(f.createLiteral("test"));
        terms.add(f.createLiteral("test","en"));
        terms.add(f.createLiteral("test","en"));
        terms.add(f.createLiteral(getVeryLargeLiteral()));
        terms.add(f.createLiteral(getVeryLargeLiteral()));
        assertEquals(10,terms.size());

        if (store.getLexiconRelation().isStoreBlankNodes()) {

            /*
             * Note: Blank nodes will not round trip through the lexicon unless
             * the "told bnodes" is enabled.
             */

            // Add two distinct instances of the same Value.
            terms.add(f.createBNode());
            terms.add(f.createBNode());
            terms.add(f.createBNode("a"));
            terms.add(f.createBNode("a"));
            terms.add(f.createBNode(getVeryLargeLiteral()));
            terms.add(f.createBNode(getVeryLargeLiteral()));
            assertEquals(16,terms.size());

        }

        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 8
Source File: ASTDeferredIVResolution.java    From database with GNU General Public License v2.0 3 votes vote down vote up
private ASTDeferredIVResolution(AbstractTripleStore store) {

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

//        this.store = store;
        
        this.vf = store.getValueFactory();
        
    }
 
Example 9
Source File: AbstractStatementBuffer.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
     * @param db
     *            The database against which the {@link Value}s will be
     *            resolved (or added). If this database supports statement
     *            identifiers, then statement identifiers for the converted
     *            statements will be resolved (or added) to the lexicon.
     * @param readOnly
     *            When <code>true</code>, {@link Value}s (and statement
     *            identifiers iff enabled) will be resolved against the
     *            {@link LexiconRelation}, but entries WILL NOT be inserted
     *            into the {@link LexiconRelation} for unknown {@link Value}s
     *            (or for statement identifiers for unknown
     *            {@link Statement}s when statement identifiers are
     *            enabled).
     * @param capacity
     *            The capacity of the backing buffer.
     */
    @SuppressWarnings("unchecked")
    public AbstractStatementBuffer(final AbstractTripleStore db,
            final boolean readOnly, final int capacity) {

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

        if (capacity <= 0)
            throw new IllegalArgumentException();
        
        this.capacity = capacity;
        
        this.db = db;
        
        this.readOnly = readOnly;

        this.valueBuffer = new BigdataValue[capacity * 3];

        this.statementBuffer = (G[])new BigdataStatement[capacity];
        
//        this.distinctValues = new HashMap<Value, BigdataValue>(capacity
//                * IRawTripleStore.N);
        this.distinctValues = new HashMap<Value, BigdataValue>(capacity
                * db.getSPOKeyArity());

        this.deferredStatementBuffer = db.getStatementIdentifiers() ? new LinkedList<G>()
                : null;
        
        this.valueFactory = db.getValueFactory();

    }
 
Example 10
Source File: TestStatementBuffer.java    From database with GNU General Public License v2.0 3 votes vote down vote up
public void test_context_stripping() {
    int capacity = 1;

    final AbstractTripleStore store = getStore(getProperties());

    try {

       final BigdataValueFactory vf = store.getValueFactory();

       final BigdataURI s = vf.createURI("http://example.com/s");
       final BigdataURI p = vf.createURI("http://example.com/p");
       final BigdataURI o = vf.createURI("http://example.com/o");
       final BigdataURI c = vf.createURI("http://example.com/c");

       final StatementBuffer<Statement> buffer = new StatementBuffer<Statement>(
             store, capacity);
       buffer.add(vf.createStatement(s, p, o, c, StatementEnum.Explicit));

       // flush the buffer.
       buffer.flush();
       
       assertTrue(store.hasStatement(s, p, o));
       assertFalse(store.hasStatement(s, p, o, c));

    } finally {

       store.__tearDownUnitTest();
       
   }

}
 
Example 11
Source File: TestAddTerms.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * The "told bnodes" mode uses the blank node ID as specified rather than
 * assigning one based on a UUID. For this case, we need to store the blank
 * nodes in the reverse index (T2ID) so we can translate a blank node back
 * to a specific identifier.
 */
public void test_toldBNodes() {

    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");

    // this is the "told bnodes" mode.
    properties.setProperty(Options.STORE_BLANK_NODES, "true");

    AbstractTripleStore store = getStore(properties);
    
    try {

        if (!store.isStable()) {

            /*
             * We need a restart safe store to test this since otherwise a
             * term cache could give us a false positive.
             */

            return;
            
        }

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

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

        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();

                assertEquals("Id mapped to a different term? : termId="
                        + id, ids.get(id), ids2.get(id));

            }

        }

    } finally {
        
        store.__tearDownUnitTest();
        
    }

}
 
Example 12
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 13
Source File: TestCompletionScan.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Unit test for a completion scan.
 */
public void test_completionScan() {
    
    final AbstractTripleStore store = getStore();

    try {

        /*
         * Populate the KB with some terms. 
         */
        {
            
            final BigdataValueFactory f = store.getValueFactory();
            
            final BigdataValue[] terms = new BigdataValue[] {
                    
                    f.createLiteral("mingus"),
                    f.createLiteral("minor"),
                    f.createLiteral("minor league"),
                    f.createLiteral("minor threat"),
                    f.createLiteral("minority report"),
                    f.createLiteral("missing report"),
                    
            };
            
            store.addTerms(terms);
            
        }

        /*
         * Do a completion scan on "minor".
         */
        {
            
            final Set<Literal> expected = new HashSet<Literal>();
            
            expected.add(new LiteralImpl("minor"));

            expected.add(new LiteralImpl("minor league"));
            
            expected.add(new LiteralImpl("minor threat"));

            expected.add(new LiteralImpl("minority report"));
            
            final Iterator<IV> itr = store.getLexiconRelation()
                    .prefixScan(new LiteralImpl("minor"));

            while(itr.hasNext()) {
                
                if(expected.isEmpty()) {
                    
                    fail("Nothing else is expected");
                    
                }
                
                final IV tid = itr.next();
                
                final Literal lit = (Literal) store.getLexiconRelation()
                        .getTerm(tid);
                
                if (log.isInfoEnabled())
                    log.info("Found: " + lit);
                
                if(!expected.remove(lit)) {
                    
                    fail("Not expecting: "+lit);
                    
                }
                
            }

            if(!expected.isEmpty()) {
                
                fail("Additional terms were expected: not found="+expected);
                
            }
            
        }
        
    } finally {
        
        store.__tearDownUnitTest();
        
    }
    
}
 
Example 14
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 15
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 16
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 17
Source File: TestInlining.java    From database with GNU General Public License v2.0 2 votes vote down vote up
public void test_epoch() {

        final Properties properties = getProperties();
        
        // test w/o predefined vocab.
        properties.setProperty(Options.VOCABULARY_CLASS, MyVocabulary.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");

        // do not inline unicode data.
        properties.setProperty(Options.MAX_INLINE_TEXT_LENGTH, "0");

        // test with the sample extension factory
        properties.setProperty(Options.EXTENSION_FACTORY_CLASS, 
                SampleExtensionFactory.class.getName());

        AbstractTripleStore store = getStore(properties);
        
        try {

            if (!store.isStable()) {

                /*
                 * We need a restart safe store to test this since otherwise a
                 * term cache could give us a false positive.
                 */

                return;
                
            }

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

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

            final BigdataLiteral l1 = f.createLiteral("1", EpochExtension.EPOCH);
            final BigdataLiteral l2 = f.createLiteral(String.valueOf(System.currentTimeMillis()), EpochExtension.EPOCH);
//            final BigdataLiteral l3 = f.createLiteral("-100", EpochExtension.EPOCH);
            final BigdataURI datatype = f.createURI(EpochExtension.EPOCH.stringValue());

            terms.add(l1);
            terms.add(l2);
//            terms.add(l3);
            terms.add(datatype);

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

            assertTrue(l1.getIV().isInline());
            assertTrue(l2.getIV().isInline());
//            assertFalse(l3.getIV().isInline());
            
            final LiteralExtensionIV iv1 = (LiteralExtensionIV) l1.getIV();
            final LiteralExtensionIV iv2 = (LiteralExtensionIV) l2.getIV();
            
			assertEquals(iv1.getExtensionIV(), datatype.getIV());
			assertEquals(iv2.getExtensionIV(), datatype.getIV());

            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<?, ?> iv = e.getKey();

                    if(log.isInfoEnabled()) log.info(iv);
                    
                    assertEquals("Id mapped to a different term? : iv="
                            + iv, ids.get(iv), ids2.get(iv));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 18
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_badrangeUnsigned() {

        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();
            
            // Out of range values cannot be inlined
            terms.add(f.createLiteral("-12", f
                    .createURI(XSD.UNSIGNED_BYTE.toString())));

            terms.add(f.createLiteral("1024", f
                    .createURI(XSD.UNSIGNED_BYTE.toString())));

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

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

            terms.add(f.createLiteral(BigInteger.valueOf(Long.MAX_VALUE).multiply(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
                    assertFalse(id.isInline());
                    
                    assertEquals("Id mapped to a different term? : termId="
                            + id, ids.get(id), ids2.get(id));

                }

            }

        } finally {
            
            store.__tearDownUnitTest();
            
        }

    }
 
Example 19
Source File: TestInlining.java    From database with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Verify inlined unsigned numeric values
 */
public void test_verifyunsigned() {

    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();
        
        assertTrue(f.createLiteral("198", f
                .createURI(XSD.UNSIGNED_BYTE.toString())).intValue() == 198);

        assertTrue(f.createLiteral("0", f
                .createURI(XSD.UNSIGNED_BYTE.toString())).intValue() == 0);

        assertTrue(f.createLiteral("50", f
                .createURI(XSD.UNSIGNED_BYTE.toString())).intValue() == 50);

        assertTrue(f.createLiteral("" + (Short.MAX_VALUE + 10), f
                .createURI(XSD.UNSIGNED_SHORT.toString())).intValue() == (Short.MAX_VALUE + 10));

        assertTrue(f.createLiteral("0", f
                .createURI(XSD.UNSIGNED_SHORT.toString())).intValue() == 0);

        assertTrue(f.createLiteral(""+ (10L + Integer.MAX_VALUE), f
                .createURI(XSD.UNSIGNED_INT.toString())).longValue() == (10L + Integer.MAX_VALUE));

        assertTrue(f.createLiteral("0", f
                .createURI(XSD.UNSIGNED_INT.toString())).longValue() == 0L);

        BigInteger bi = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.valueOf(10));
        assertTrue(f.createLiteral(bi.toString(), f
                .createURI(XSD.UNSIGNED_LONG.toString())).integerValue().equals(bi));

        BigInteger biz = BigInteger.valueOf(0);
        assertTrue(f.createLiteral("0", f
                .createURI(XSD.UNSIGNED_LONG.toString())).integerValue().equals(biz));
        BigInteger bi100 = BigInteger.valueOf(100);
        assertTrue(f.createLiteral("100", f
                .createURI(XSD.UNSIGNED_LONG.toString())).integerValue().equals(bi100));


    } finally {
        
        store.__tearDownUnitTest();
        
    }

}
 
Example 20
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();
            
        }
        
    }