コード例 #1
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst5() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    std::cout.flush();
    d1 = m.mk_empty(3);
    add_triple(m, d1, 5, 100, 10, 20, 3, 10);
    std::cout << mk_ll_pp(d1,m) << std::endl;
    add_triple(m, d1, 5, 100, 34, 50, 98, 110);
    std::cout << mk_ll_pp(d1,m) << std::endl;
    unsigned vals[3] = {6, 8, 3};
    SASSERT(!m.contains(d1, 3, vals));
    add_triple(m, d1, 6, 25, 8, 30, 14, 50);
    std::cout << mk_ll_pp(d1,m) << std::endl;
    SASSERT(!m.contains(d1, 3, vals));
    unsigned vars[2] = {0, 2};
    d2 = d1;
    d3 = d1;
    m.mk_filter_identical(d1, d1, 2, vars);
    vars[1] = 1;
    std::cout << "d1:\n" << mk_ll_pp(d1,m) << "\n";
    m.mk_filter_identical(d2, d2, 2, vars);
    std::cout << "d2:\n" << mk_ll_pp(d2,m) << "\n";
    vars[0] = 1;
    vars[1] = 2;
    m.mk_filter_identical(d3, d3, 2, vars);
    std::cout << "d3:\n" << mk_ll_pp(d3,m) << "\n";
}
コード例 #2
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst13() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 5, 25, 1, 10, 10, 13);
    add_triple(m, d1, 5, 25, 20, 30, 10, 13);
    m.mk_filter_distinct(d1, d2, 0, 2);
    std::cout << mk_ll_pp(d1, m) << "\n";
    std::cout << "filter_distinct(0,2):\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
}
コード例 #3
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst14() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 5, 25, 1, 10, 10, 13);
    add_triple(m, d1, 5, 25, 20, 30, 15, 18);
    std::cout << "destructive version\n";
    std::cout << mk_ll_pp(d1, m) << "\n";
    m.mk_filter_distinct_dupdt(d1, 0, 2);
    std::cout << "filter_distinct(0,2):\n";
    std::cout << mk_ll_pp(d1, m) << "\n";
}
コード例 #4
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst10() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 5, 100, 10, 20, 3, 10);
    add_triple(m, d1, 5, 100, 34, 50, 98, 110);
    m.add_bounded_var(d1, d2, 0, 66, 72);
    std::cout << mk_ll_pp(d1, m) << "\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
    m.add_bounded_var(d1, d3, 1, 64, 73);
    std::cout << mk_ll_pp(d3, m) << "\n";
}
コード例 #5
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst7() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d2(m), d3(m);
    d2 = m.mk_empty(3);
    add_triple(m, d2, 15, 22, 15, 23, 7, 18);
    add_triple(m, d2, 28, 42, 29, 39, 34, 46);
    add_triple(m, d2, 28, 42, 29, 39, 100, 200);
    add_triple(m, d2, 28, 42, 50, 60, 100, 200);
    std::cout << "mk_project\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
    unsigned vars[1] = {1};
    m.mk_project(d2, d3, 1, vars);
    std::cout << mk_ll_pp(d3, m) << "\n";
}
コード例 #6
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst8() {
    std::cout << "--------------------------------\n";    
    // enable_trace("mk_swap_bug");
    imdd_manager m;
    imdd_ref d2(m), d3(m);
    d2 = m.mk_empty(3);
    add_triple(m, d2, 15, 22, 15, 23, 7, 18);
    add_triple(m, d2, 28, 42, 29, 39, 34, 46);
    add_triple(m, d2, 28, 42, 29, 39, 100, 200);
    add_triple(m, d2, 28, 42, 50, 60, 100, 200);
    std::cout << mk_ll_pp(d2, m) << "\n";
    m.mk_swap(d2, d3, 0);
    std::cout << "after swap 0<->1\n";    
    std::cout << mk_ll_pp(d3, m) << "\n";
    m.mk_swap(d2, d3, 1);
    std::cout << "after swap 1<->2\n";    
    std::cout << mk_ll_pp(d3, m) << "\n";
}
コード例 #7
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst17() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 5, 15, 10, 10, 50, 500);
    std::cout << mk_ll_pp(d1, m) << "\n";
    m.mk_filter_disequal(d1, d2, 1, 10);
    std::cout << "filter_disequal(var1,10):\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
}
コード例 #8
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst4() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 1, 2, 2, 5, 4, 4);
    add_triple(m, d1, 3, 4, 3, 4, 2, 5);
    std::cout << "testing iterator:\n";
    imdd_manager::iterator it  = m.begin(d1);
    imdd_manager::iterator end = m.end(d1);
    for (; it != end; ++it) {
        unsigned * tuple = *it;
        std::cout << "[";
        for (unsigned i = 0; i < d1->get_arity(); i++) {
            if (i > 0)
                std::cout << ", ";
            std::cout << tuple[i];
        }
        std::cout << "]\n";
    }
}
コード例 #9
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst2() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m), d2(m), d3(m);
    d1 = m.mk_empty(3);
    add_triple(m, d1, 10, 20, 11, 21, 12, 22);
    add_triple(m, d1, 30, 40, 31, 41, 32, 42);
    d2 = m.mk_empty(3);
    add_triple(m, d2, 15, 22, 15, 23, 7, 18);
    add_triple(m, d2, 28, 42, 29, 39, 34, 46);
    add_triple(m, d2, 28, 42, 29, 39, 100, 200);
    add_triple(m, d2, 28, 42, 50, 60, 100, 200);
    std::cout << mk_ll_pp(d1, m) << "\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
    m.mk_union(d1, d2, d3);
    SASSERT(m.subsumes(d3, d1));
    SASSERT(m.subsumes(d3, d2));
    SASSERT(!m.subsumes(d1, d3));
    SASSERT(!m.subsumes(d2, d3));
    std::cout << "d3: " << d3.get() << "\n" << mk_ll_pp(d3, m) << "\n";
    m.mk_union_dupdt(d1, d2, false);
    std::cout << "d1: " << d1.get() << "\n" << mk_ll_pp(d1, m) << "\n";
    SASSERT(m.is_equal(d1, d3));
    SASSERT(!m.is_equal(d2, d3));
    SASSERT(!m.is_equal(d2, d1));
    std::cout << "memory(d1): " << m.memory(d1) << "\n";
}
コード例 #10
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void add_some_facts(imdd_manager & m, imdd_ref & d, bool destructive = false, bool memoize = true) {
    std::cout << "destructive: " << destructive << ", memoize: " << memoize << std::endl;
    add_triple(m, d, 1, 10,  3, 3,  0, 100, destructive, memoize);
    std::cout << mk_ll_pp(d, m) << std::endl;
    SASSERT(m.contains(d, 2, 3, 20));
    SASSERT(!m.contains(d, 2, 4, 20));
    SASSERT(!m.contains(d, 2, 3, 200));
    SASSERT(!m.contains(d, 0, 3, 200));
    SASSERT(m.contains(d,1,3,0));
    add_triple(m, d, 3, 6,   3, 4,  7, 101, destructive, memoize);
    std::cout << mk_ll_pp(d, m) << std::endl;
    add_triple(m, d, 3, 6,   2, 2,  7, 101, destructive, memoize);
    std::cout << mk_ll_pp(d, m) << std::endl;
    add_triple(m, d, 3, 6,   5, 6,  7, 101, destructive, memoize);
    SASSERT(m.contains(d, 2, 3, 20));
    std::cout << mk_ll_pp(d, m) << std::endl;
    SASSERT(!m.contains(d, 2, 4, 20));
    SASSERT(m.contains(d, 3, 4, 20));
    SASSERT(!m.contains(d, 2, 3, 200));
    SASSERT(!m.contains(d, 0, 3, 200));
    SASSERT(m.contains(d,1,3,0));
}
コード例 #11
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst3() {
    std::cout << "--------------------------------\n";    
    imdd_manager m;
    imdd_ref d1(m);
    d1 = m.mk_empty(3);
    unsigned mins[3] = {0,0,0};
    unsigned maxs[3] = {127, 511, 255};
    
    m.mk_complement(d1, d1, 3, mins, maxs);
    std::cout << d1 << "\n";
    m.mk_complement(d1, d1, 3, mins, maxs);
    std::cout << d1 << "\n";
    SASSERT(d1->empty());

    d1 = m.mk_empty(3);
    add_triple(m, d1, 10, 20, 11, 21, 12, 22);
    add_triple(m, d1, 30, 40, 31, 41, 32, 42);
    std::cout << d1 << "\n";
    m.mk_complement(d1, d1, 3, mins, maxs);
    std::cout << mk_ll_pp(d1,m) << "\n";
    m.mk_filter_equal(d1, d1, 1, 15);
    std::cout << "after selecting second column = 15\n" << mk_ll_pp(d1,m) << "\n";
}
コード例 #12
0
ファイル: imdd.cpp プロジェクト: Moondee/Artemis
static void tst21() {
    std::cout << "--------------------------------\n";
    std::cout << "remove_facts\n";
    imdd_manager m;
    imdd_ref d2(m), d3(m);
    d2 = m.mk_empty(3);
    add_triple(m, d2, 15, 22, 15, 23, 7, 18);
    add_triple(m, d2, 28, 42, 29, 39, 34, 46);
    add_triple(m, d2, 28, 42, 29, 39, 100, 200);
    add_triple(m, d2, 28, 42, 50, 60, 100, 200);
    std::cout << mk_ll_pp(d2, m) << "\n";
    //
    // [15, 22] -> #1:{
    //     [15, 23] -> {[7, 18]}*$80}*$80
    // [28, 42] -> #2:{
    //     [29, 39] -> {[34, 46], [100, 200]}*$160
    //     [50, 60] -> {[100, 200]}*$80}*$80}$80
    //
    unsigned lowers[3] = {23,1,1};
    unsigned uppers[3] = {24,1,1};

    d3 = d2;
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (no change)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";
    d2 = d3;

    lowers[0] = 22;
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (no change)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";

    init(lowers, 22, 15, 0);
    init(uppers, 24, 23, 0);
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (no change)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";

    init(lowers, 22, 15, 7);
    init(uppers, 24, 23, 18);
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (narrow first interval)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";

    init(lowers, 22, 15, 8);
    init(uppers, 24, 23, 18);
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (split first interval)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";

    init(lowers, 22, 15, 8);
    init(uppers, 24, 23, 17);
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (split first interval)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";

    init(lowers, 22, 15, 8);
    init(uppers, 24, 23, 19);
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (split first interval)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";

    init(lowers, 30, 20, 120);
    init(uppers, 40, 60, 140);
    m.remove_facts_dupdt(d2, 3, lowers, uppers);
    std::cout << "new table (split second interval)\n";
    std::cout << mk_ll_pp(d2, m) << "\n";       
}
コード例 #13
0
ファイル: redland-virtuoso-test.c プロジェクト: njh/librdf
int
main(int argc, char *argv[])
{
  librdf_world* world;
  librdf_parser* parser;
  librdf_serializer* serializer;
  librdf_storage *storage;
  librdf_model* model;
  librdf_node *source, *arc, *target, *node;
  librdf_node *subject, *predicate, *object;
  librdf_node* context_node=NULL;
  librdf_stream* stream;
  librdf_iterator* iterator;
  librdf_uri *uri;
  librdf_uri *base_uri=NULL;
  librdf_query *query;
  librdf_query_results *results;
  librdf_hash *options;
  int count;
  int rc;
  int transactions=0;
  const char* storage_name;
  const char* storage_options;
  const char* context;
  const char* identifier;
  const char* results_format;
  librdf_statement* statement=NULL;
  char* query_cmd=NULL;
  char* s;


  /*
   * Initialize
   */
  storage_name="virtuoso";
  results_format="xml";
  context=DEFAULT_CONTEXT;
  identifier=DEFAULT_IDENTIFIER;


  /*
   * Get connection options
   */
  if(argc == 2 && argv[1][0] != '\0')
    storage_options=argv[1];
  else if((s=getenv ("VIRTUOSO_STORAGE_OPTIONS")) != NULL)
    storage_options=s;
  else
    storage_options=DEFAULT_STORAGE_OPTIONS;


  world=librdf_new_world();

  librdf_world_set_logger(world, world, log_handler);

  librdf_world_open(world);

  options=librdf_new_hash(world, NULL);
  librdf_hash_open(options, NULL, 0, 1, 1, NULL);

  librdf_hash_put_strings(options, "contexts", "yes");
  transactions=1;

  librdf_hash_from_string(options, storage_options);

  storage=librdf_new_storage_with_options(world, storage_name, identifier, options);

  if(!storage) {
    fprintf(stderr, ": Failed to open %s storage '%s'\n", storage_name, identifier);
    return(1);
  }

  model=librdf_new_model(world, storage, NULL);
  if(!model) {
    fprintf(stderr, ": Failed to create model\n");
    return(1);
  }

  if(transactions)
    librdf_model_transaction_start(model);

  /* Do this or gcc moans */
  stream=NULL;
  iterator=NULL;
  parser=NULL;
  serializer=NULL;
  source=NULL;
  arc=NULL;
  target=NULL;
  subject=NULL;
  predicate=NULL;
  object=NULL;
  uri=NULL;
  node=NULL;
  query=NULL;
  results=NULL;
  context_node=librdf_new_node_from_uri_string(world, (const unsigned char *)context);


  /**** Test 1 *******/
  startTest(1, " Remove all triples in <%s> context\n", context);
  {
    rc=librdf_model_context_remove_statements(model, context_node);

    if(rc)
      endTest(0, " failed to remove context triples from the graph\n");
    else
      endTest(1, " removed context triples from the graph\n");
  }


  /**** Test 2 *******/
  startTest(2, " Add triples to <%s> context\n", context);
  {
    rc=0;
    rc |= add_triple(world, context_node, model, "aa", "bb", "cc");
    rc |= add_triple(world, context_node, model, "aa", "bb1", "cc");
    rc |= add_triple(world, context_node, model, "aa", "a2", "_:cc");
    rc |= add_triple_typed(world, context_node, model, "aa", "a2", "cc");
    rc |= add_triple_typed(world, context_node, model, "mm", "nn", "Some long literal with language@en");
    rc |= add_triple_typed(world, context_node, model, "oo", "pp", "12345^^<http://www.w3.org/2001/XMLSchema#int>");
    if(rc)
      endTest(0, " failed add triple\n");
    else
      endTest(1, " add triple to context\n");
  }


  /**** Test 3 *******/
  startTest(3, " Print all triples in <%s> context\n", context);
  {
    raptor_iostream* iostr = raptor_new_iostream_to_file_handle(librdf_world_get_raptor(world), stdout);
    librdf_model_write(model, iostr);
    raptor_free_iostream(iostr);
    endTest(1, "\n");
  }


  /***** Test 4 *****/
  startTest(4, " Count of triples in <%s> context\n", context);
  {
    count=librdf_model_size(model);
    if(count >= 0)
      endTest(1, " graph has %d triples\n", count);
    else
      endTest(0, " graph has unknown number of triples\n");
  }


  /***** Test 5 *****/
  startTest(5, " Exec:  ARC  aa bb \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");
    node=librdf_model_get_target(model, subject, predicate);
    librdf_free_node(subject);
    librdf_free_node(predicate);
    if(!node) {
      endTest(0, " Failed to get arc\n");
    } else {
      print_node(stdout, node);
      librdf_free_node(node);
      endTest(1, "\n");
    }
  }


  /***** Test 6 *****/
  startTest(6, " Exec:  ARCS  aa cc \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");
    iterator=librdf_model_get_arcs(model, subject, object);
    librdf_free_node(subject);
    librdf_free_node(object);
    if(!iterator) {
      endTest(0, " Failed to get arcs\n");
    } else {
      print_nodes(stdout, iterator);
      endTest(1, "\n");
    }
  }


  /***** Test 7 *****/
  startTest(7, " Exec:  ARCS-IN  cc \n");
  {
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");
    iterator=librdf_model_get_arcs_in(model, object);
    librdf_free_node(object);
    if(!iterator) {
      endTest(0, " Failed to get arcs in\n");
    } else {
      int ok=1;
      count=0;
      while(!librdf_iterator_end(iterator)) {
        context_node=(librdf_node*)librdf_iterator_get_context(iterator);
        node=(librdf_node*)librdf_iterator_get_object(iterator); /*returns SHARED pointer */
        if(!node) {
          ok=0;
          endTest(ok, " librdf_iterator_get_next returned NULL\n");
          break;
        }

        fputs("Matched arc: ", stdout);
        librdf_node_print(node, stdout);
        if(context_node) {
          fputs(" with context ", stdout);
          librdf_node_print(context_node, stdout);
        }
        fputc('\n', stdout);

        count++;
        librdf_iterator_next(iterator);
      }
      librdf_free_iterator(iterator);
      endTest(ok, " matching arcs: %d\n", count);
    }
  }


  /***** Test 8 *****/
  startTest(8, " Exec:  ARCS-OUT  aa \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    iterator=librdf_model_get_arcs_out(model, subject);
    librdf_free_node(subject);
    if(!iterator)
      endTest(0, " Failed to get arcs out\n");
    else {
      int ok=1;
      count=0;
      while(!librdf_iterator_end(iterator)) {
        context_node=(librdf_node*)librdf_iterator_get_context(iterator);
        node=(librdf_node*)librdf_iterator_get_object(iterator);
        if(!node) {
          ok=0;
          endTest(ok, " librdf_iterator_get_next returned NULL\n");
          break;
        }

        fputs("Matched arc: ", stdout);
        librdf_node_print(node, stdout);
        if(context_node) {
          fputs(" with context ", stdout);
          librdf_node_print(context_node, stdout);
        }
        fputc('\n', stdout);

        count++;
        librdf_iterator_next(iterator);
      }
      librdf_free_iterator(iterator);
      endTest(ok, " matching arcs: %d\n", count);
    }
  }


  /***** Test 9 *****/
  startTest(9, " Exec:  CONTAINS aa bb1 cc \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb1");
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");
    statement=librdf_new_statement(world);
    librdf_statement_set_subject(statement, subject);
    librdf_statement_set_predicate(statement, predicate);
    librdf_statement_set_object(statement, object);

    if(librdf_model_contains_statement(model, statement))
       endTest(1, " the graph contains the triple\n");
    else
       endTest(0, " the graph does not contain the triple\n");

    librdf_free_statement(statement);
  }


  /***** Test 10 *****/
  startTest(10, " Exec:  FIND aa - - \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    statement=librdf_new_statement(world);
    librdf_statement_set_subject(statement, subject);

    stream=librdf_model_find_statements_in_context(model, statement, context_node);

    if(!stream) {
        endTest(0, " FIND returned no results (NULL stream)\n");
    } else {
        librdf_node* ctxt_node=NULL;
        int ok=1;
        count=0;
        while(!librdf_stream_end(stream)) {
          librdf_statement *stmt=librdf_stream_get_object(stream);
          ctxt_node=(librdf_node*)librdf_stream_get_context(stream);
          if(!stmt) {
              ok=0;
              endTest(ok, " librdf_stream_next returned NULL\n");
              break;
          }

          fputs("Matched triple: ", stdout);
          librdf_statement_print(stmt, stdout);
          if(context) {
              fputs(" with context ", stdout);
              librdf_node_print(ctxt_node, stdout);
          }
          fputc('\n', stdout);

          count++;
          librdf_stream_next(stream);
        }
        librdf_free_stream(stream);
        endTest(ok, " matching triples: %d\n", count);
    }

    librdf_free_statement(statement);
  }


  /***** Test 11 *****/
  startTest(11, " Exec:  HAS-ARC-IN cc bb \n");
  {
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");

    if(librdf_model_has_arc_in(model, object, predicate))
        endTest(1, " the graph contains the arc\n");
      else
        endTest(0, " the graph does not contain the arc\n");

    librdf_free_node(predicate);
    librdf_free_node(object);
  }


  /***** Test 12 *****/
  startTest(12, " Exec:  HAS-ARC-OUT aa bb \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");

    if(librdf_model_has_arc_out(model, subject, predicate))
        endTest(1, " the graph contains the arc\n");
      else
        endTest(0, " the graph does not contain the arc\n");

    librdf_free_node(predicate);
    librdf_free_node(subject);
  }


  /***** Test 13 *****/
  startTest(13, " Exec:  SOURCE  aa cc \n");
  {
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");

    node=librdf_model_get_source(model, predicate, object);
    librdf_free_node(predicate);
    librdf_free_node(object);
    if(!node) {
      endTest(0, " Failed to get source\n");
    } else {
      print_node(stdout, node);
      librdf_free_node(node);
      endTest(1, "\n");
    }
  }


  /***** Test 14 *****/
  startTest(14, " Exec:  SOURCES  bb cc \n");
  {
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");

    iterator=librdf_model_get_sources(model, predicate, object);
    librdf_free_node(predicate);
    librdf_free_node(object);
    if(!iterator) {
      endTest(0, " Failed to get sources\n");
    } else {
      print_nodes(stdout, iterator);
      endTest(1, "\n");
    }
  }


  /***** Test 15 *****/
  startTest(15, " Exec:  TARGET  aa bb \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");

    node=librdf_model_get_target(model, subject, predicate);
    librdf_free_node(subject);
    librdf_free_node(predicate);
    if(!node) {
      endTest(0, " Failed to get target\n");
    } else {
      print_node(stdout, node);
      librdf_free_node(node);
      endTest(1, "\n");
    }
  }


  /***** Test 16 *****/
  startTest(16, " Exec:  TARGETS  aa bb \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb");

    iterator=librdf_model_get_targets(model, subject, predicate);
    librdf_free_node(subject);
    librdf_free_node(predicate);
    if(!iterator) {
      endTest(0, " Failed to get targets\n");
    } else {
      print_nodes(stdout, iterator);
      endTest(1, "\n");
    }
  }


  /***** Test 17 *****/
  startTest(17, " Exec:  REMOVE aa bb1 cc \n");
  {
    subject=librdf_new_node_from_uri_string(world, (const unsigned char*)"aa");
    predicate=librdf_new_node_from_uri_string(world, (const unsigned char*)"bb1");
    object=librdf_new_node_from_uri_string(world, (const unsigned char*)"cc");
    statement=librdf_new_statement(world);
    librdf_statement_set_subject(statement, subject);
    librdf_statement_set_predicate(statement, predicate);
    librdf_statement_set_object(statement, object);

    if(librdf_model_context_remove_statement(model, context_node, statement))
       endTest(0, " failed to remove triple from the graph\n");
    else
       endTest(1, " removed triple from the graph\n");

    librdf_free_statement(statement);
  }


  /***** Test 18 *****/
  query_cmd=(char *)"CONSTRUCT {?s ?p ?o} FROM <http://red> WHERE {?s ?p ?o}";
  startTest(18, " Exec:  QUERY \"%s\" \n", query_cmd);
  {
    query=librdf_new_query(world, (char *)"vsparql", NULL, (const unsigned char *)query_cmd, NULL);

    if(!(results=librdf_model_query_execute(model, query))) {
      endTest(0, " Query of model with '%s' failed\n", query_cmd);
      librdf_free_query(query);
      query=NULL;
    } else {
      stream=librdf_query_results_as_stream(results);

      if(!stream) {
        endTest(0, " QUERY returned no results (NULL stream)\n");
      } else {
        librdf_node* ctxt=NULL;
        count=0;
        while(!librdf_stream_end(stream)) {
          librdf_statement *stmt=librdf_stream_get_object(stream);  /*returns SHARED pointer */
          ctxt=(librdf_node*)librdf_stream_get_context(stream);
          if(!stmt) {
              endTest(0, " librdf_stream_next returned NULL\n");
              break;
          }

          fputs("Matched triple: ", stdout);
          librdf_statement_print(stmt, stdout);
          if(ctxt) {
              fputs(" with context ", stdout);
              librdf_node_print(ctxt, stdout);
          }
          fputc('\n', stdout);

          count++;
          librdf_stream_next(stream);
        }
       librdf_free_stream(stream);

        endTest(1, " matching triples: %d\n", count);
        librdf_free_query_results(results);
      }
    }
    librdf_free_query(query);
  }


  /***** Test 19 *****/
  query_cmd=(char *)"SELECT * WHERE {graph <http://red> { ?s ?p ?o }}";
  startTest(19, " Exec1:  QUERY_AS_BINDINGS \"%s\" \n", query_cmd);
  {
    query=librdf_new_query(world, (char *)"vsparql", NULL, (const unsigned char *)query_cmd, NULL);

    if(!(results=librdf_model_query_execute(model, query))) {
        endTest(0, " Query of model with '%s' failed\n", query_cmd);
        librdf_free_query(query);
        query=NULL;
    } else {

        raptor_iostream *iostr;
        librdf_query_results_formatter *formatter;

        fprintf(stderr, "**: Formatting query result as '%s':\n", results_format);

        iostr = raptor_new_iostream_to_file_handle(librdf_world_get_raptor(world), stdout);
        formatter = librdf_new_query_results_formatter2(results, results_format,
                                                        NULL /* mime type */,
                                                        NULL /* format_uri */);

        base_uri = librdf_new_uri(world, (const unsigned char*)"http://example.org/");
        
        librdf_query_results_formatter_write(iostr, formatter, results, base_uri);
        librdf_free_query_results_formatter(formatter);
        raptor_free_iostream(iostr);
        librdf_free_uri(base_uri);

        endTest(1, "\n");
        librdf_free_query_results(results);
    }
    librdf_free_query(query);
  }


  /***** Test 20 *****/
  query_cmd=(char *)"SELECT * WHERE {graph <http://red> { ?s ?p ?o }}";
  startTest(20, " Exec2:  QUERY_AS_BINDINGS \"%s\" \n", query_cmd);
  {
    query=librdf_new_query(world, (char *)"vsparql", NULL, (const unsigned char *)query_cmd, NULL);

    if(!(results=librdf_model_query_execute(model, query))) {
       endTest(0, " Query of model with '%s' failed\n", query_cmd);
       librdf_free_query(query);
       query=NULL;
    } else {
       if(print_query_results(world, model, results))
         endTest(0, "\n");
       else
         endTest(1, "\n");

       librdf_free_query_results(results);
    }
    librdf_free_query(query);
  }

  getTotal();


  if(transactions)
    librdf_model_transaction_commit(model);

  librdf_free_node(context_node);
  librdf_free_node(context_node);
  librdf_free_hash(options);
  librdf_free_model(model);
  librdf_free_storage(storage);

  librdf_free_world(world);

#ifdef LIBRDF_MEMORY_DEBUG
  librdf_memory_report(stderr);
#endif
	
  /* keep gcc -Wall happy */
  return(0);
}