Пример #1
0
  /**
   * Test that can be used to verify that we are doing an efficient scan for the distinct predicates
   * (distinct key prefix scan).
   */
  public void test_rdf01_distinctPrefixScan() throws Exception {

    final Properties properties = super.getProperties();

    // override the default axiom model.
    properties.setProperty(
        com.bigdata.rdf.store.AbstractTripleStore.Options.AXIOMS_CLASS, NoAxioms.class.getName());

    final AbstractTripleStore store = getStore(properties);

    try {

      final BigdataValueFactory f = store.getValueFactory();

      final URI A = f.createURI("http://www.foo.org/A");
      final URI B = f.createURI("http://www.foo.org/B");
      final URI C = f.createURI("http://www.foo.org/C");
      final URI D = f.createURI("http://www.foo.org/D");
      final URI E = f.createURI("http://www.foo.org/E");

      final URI rdfType = RDF.TYPE;
      final URI rdfProperty = RDF.PROPERTY;

      /*
       * Three statements that will trigger the rule, but two statements
       * share the same predicate. When it does the minimum amount of
       * work, the rule will fire for each distinct predicate in the KB --
       * for this KB that is only twice.
       */
      store.addStatement(A, B, C);
      store.addStatement(C, B, D);
      store.addStatement(A, E, C);

      assertTrue(store.hasStatement(A, B, C));
      assertTrue(store.hasStatement(C, B, D));
      assertTrue(store.hasStatement(A, E, C));
      assertFalse(store.hasStatement(B, rdfType, rdfProperty));
      assertFalse(store.hasStatement(E, rdfType, rdfProperty));
      assertEquals(3, store.getStatementCount());

      final Rule r = new RuleRdf01(store.getSPORelation().getNamespace(), store.getVocabulary());

      applyRule(store, r, 2 /* solutionCount */, 2 /* mutationCount */);

      /*
       * validate the state of the primary store.
       */
      assertTrue(store.hasStatement(A, B, C));
      assertTrue(store.hasStatement(C, B, D));
      assertTrue(store.hasStatement(A, E, C));
      assertTrue(store.hasStatement(B, rdfType, rdfProperty));
      assertTrue(store.hasStatement(E, rdfType, rdfProperty));
      assertEquals(5, store.getStatementCount());

    } finally {

      store.__tearDownUnitTest();
    }
  }
Пример #2
0
 @SuppressWarnings("unchecked")
 public V asValue(final LexiconRelation lex) {
   V v = getValueCache();
   if (v == null) {
     final BigdataValueFactory f = lex.getValueFactory();
     v = (V) f.createURI(uri.stringValue());
     v.setIV(this);
     setValue(v);
   }
   return v;
 }
Пример #3
0
  private void writeVersion2(final ObjectOutput out) throws IOException {

    assert iv2val.size() == val2iv.size();

    // compute a checksum on the hash codes of the URIs.
    long checksum = 0;
    for (Value value : val2iv.keySet()) {
      checksum += value.hashCode();
    }

    // write on the #of declarations.
    LongPacker.packLong(out, decls.size());

    // write on the #of values.
    LongPacker.packLong(out, val2iv.size());

    // write out the checksum.
    out.writeLong(checksum);

    // The namespace of the KB instance.
    out.writeUTF(valueFactory.getNamespace());

    //        for (VocabularyDecl decl : decls) {
    //
    //            // The class name of the vocabulary declaration.
    //            out.writeUTF(decl.getClass().getName());
    //
    //        }

  }
Пример #4
0
  /** Add all vocabulary items from all declaring classes. */
  private void addAllDecls() {

    for (VocabularyDecl decl : decls) {

      final Iterator<URI> itr = decl.values();

      while (itr.hasNext()) {

        // Convert to BigdataValues when adding to the collection.
        final BigdataValue value = valueFactory.asValue(itr.next());

        // Add to the collection.
        if (val2iv.put(value, value) != null) {

          /*
           * This has already been declared by some vocabulary. There
           * is no harm in this, but the vocabularies should be
           * distinct.
           */

          log.warn("Duplicate declaration: " + value);

        } else {

          if (log.isDebugEnabled()) log.debug(decl.getClass().getName() + ":" + value);
        }
      }
    }
  }
Пример #5
0
  /** Basic test of rule semantics. */
  public void test_rdf01() throws Exception {

    final Properties properties = super.getProperties();

    // override the default axiom model.
    properties.setProperty(
        com.bigdata.rdf.store.AbstractTripleStore.Options.AXIOMS_CLASS, NoAxioms.class.getName());

    final AbstractTripleStore store = getStore(properties);

    try {

      final BigdataValueFactory f = store.getValueFactory();

      final URI A = f.createURI("http://www.foo.org/A");
      final URI B = f.createURI("http://www.foo.org/B");
      final URI C = f.createURI("http://www.foo.org/C");

      final URI rdfType = RDF.TYPE;
      final URI rdfProperty = RDF.PROPERTY;

      store.addStatement(A, B, C);

      assertTrue(store.hasStatement(A, B, C));
      assertFalse(store.hasStatement(B, rdfType, rdfProperty));
      assertEquals(1, store.getStatementCount());

      final Rule r = new RuleRdf01(store.getSPORelation().getNamespace(), store.getVocabulary());

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

      /*
       * validate the state of the primary store.
       */
      assertTrue(store.hasStatement(A, B, C));
      assertTrue(store.hasStatement(B, rdfType, rdfProperty));
      assertEquals(2, store.getStatementCount());

    } finally {

      store.__tearDownUnitTest();
    }
  }
Пример #6
0
  /** Test math operations such as +, -, *, /, MIN and MAX over the datatype. */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public void testMath() {

    final BigdataValueFactory vf =
        BigdataValueFactoryImpl.getInstance(getName() + UUID.randomUUID());

    final MockTermIdFactory termIdFactory = new MockTermIdFactory();

    final CompressedTimestampExtension<BigdataValue> ext =
        new CompressedTimestampExtension<BigdataValue>(
            new IDatatypeURIResolver() {
              @Override
              public BigdataURI resolve(final URI uri) {
                final BigdataURI buri = vf.createURI(uri.stringValue());
                buri.setIV(termIdFactory.newTermId(VTE.URI));
                return buri;
              }
            });

    final BigdataValue bvZero =
        vf.createLiteral("0", CompressedTimestampExtension.COMPRESSED_TIMESTAMP);
    final LiteralExtensionIV zero = ext.createIV(bvZero);
    zero.setValue(bvZero);

    final BigdataValue bfOne =
        vf.createLiteral("1", CompressedTimestampExtension.COMPRESSED_TIMESTAMP);
    final LiteralExtensionIV one = ext.createIV(bfOne);
    one.setValue(bfOne);

    final BigdataValue bfTen =
        vf.createLiteral("10", CompressedTimestampExtension.COMPRESSED_TIMESTAMP);
    final LiteralExtensionIV ten = ext.createIV(bfTen);
    ten.setValue(bfTen);

    final BigdataValue bfTwenty =
        vf.createLiteral("20", CompressedTimestampExtension.COMPRESSED_TIMESTAMP);
    final LiteralExtensionIV twenty = ext.createIV(bfTwenty);
    twenty.setValue(bfTwenty);

    final NumericIV<BigdataLiteral, ?> result10a_int_act =
        MathUtility.literalMath(zero, ten, MathOp.PLUS);
    final NumericIV<BigdataLiteral, ?> result10b_int_act =
        MathUtility.literalMath(twenty, ten, MathOp.MINUS);
    final NumericIV<BigdataLiteral, ?> result10c_int_act =
        MathUtility.literalMath(ten, one, MathOp.MULTIPLY);
    final NumericIV<BigdataLiteral, ?> result10d_dec_act =
        MathUtility.literalMath(ten, one, MathOp.DIVIDE);
    final NumericIV<BigdataLiteral, ?> result10e_int_act =
        MathUtility.literalMath(ten, twenty, MathOp.MIN);
    final NumericIV<BigdataLiteral, ?> result10f_int_act =
        MathUtility.literalMath(twenty, ten, MathOp.MIN);
    final NumericIV<BigdataLiteral, ?> result20a_int_act =
        MathUtility.literalMath(ten, ten, MathOp.PLUS);
    final NumericIV<BigdataLiteral, ?> result20b_int_act =
        MathUtility.literalMath(ten, twenty, MathOp.MAX);
    final NumericIV<BigdataLiteral, ?> result20c_int_act =
        MathUtility.literalMath(twenty, ten, MathOp.MAX);

    final XSDIntegerIV<?> result10_int = new XSDIntegerIV<>(new BigInteger("10"));
    final XSDDecimalIV<?> result10_dec = new XSDDecimalIV<>(new BigDecimal(new BigInteger("10")));
    final XSDIntegerIV<?> result20_int = new XSDIntegerIV<>(new BigInteger("20"));

    assertEquals(result10_int, result10a_int_act);
    assertEquals(result10_int, result10b_int_act);
    assertEquals(result10_int, result10c_int_act);
    assertEquals(result10_dec, result10d_dec_act);
    assertEquals(result10_int, result10e_int_act);
    assertEquals(result10_int, result10f_int_act);
    assertEquals(result20_int, result20a_int_act);
    assertEquals(result20_int, result20b_int_act);
    assertEquals(result20_int, result20c_int_act);
  }
Пример #7
0
  public final String getNamespace() {

    return valueFactory.getNamespace();
  }