Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.RDFList


        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "e"), };

    final RDFList l1 = getListRoot(model);

    // check the indexes are correct
    for (int i = 0; i < toGet.length; i++)
    {
      Assert.assertTrue("list should contain element " + i,
          l1.contains(toGet[i]));
      Assert.assertEquals("list element " + i + " is not correct", i,
          l1.indexOf(toGet[i]));
    }
  }
View Full Code Here


  public void testIndex2()
  {

    final Resource nil = model.getResource(RDF.nil.getURI());
    RDFList list = nil.as(RDFList.class);

    final Resource r = model.createResource(TestList.NS + "a");

    // cons each a's onto the front of the list
    for (int i = 0; i < 10; i++)
    {
      list = list.cons(r);
    }

    // now index them back again
    for (int j = 0; j < 10; j++)
    {
      Assert.assertEquals("index of j'th item should be j", j,
          list.indexOf(r, j));
    }

  }
View Full Code Here

  }

  public void testListEquals()
  {
    final Resource nil = model.getResource(RDF.nil.getURI());
    final RDFList nilList = nil.as(RDFList.class);

    // create a list of foos
    final Resource[] r0 = new Resource[] {
        model.createResource(TestList.NS + "a"), // canonical
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "e") };
    final Resource[] r1 = new Resource[] {
        model.createResource(TestList.NS + "a"), // same
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "e") };
    final Resource[] r2 = new Resource[] {
        model.createResource(TestList.NS + "a"), // one shorter
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "d") };
    final Resource[] r3 = new Resource[] {
        model.createResource(TestList.NS + "a"), // elements
        // swapped
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "e") };
    final Resource[] r4 = new Resource[] {
        model.createResource(TestList.NS + "a"), // different
        // name
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "D"),
        model.createResource(TestList.NS + "e") };

    final Object[][] testSpec = new Object[][] { { r0, r1, Boolean.TRUE },
        { r0, r2, Boolean.FALSE }, { r0, r3, Boolean.FALSE },
        { r0, r4, Boolean.FALSE }, { r1, r2, Boolean.FALSE },
        { r1, r3, Boolean.FALSE }, { r1, r4, Boolean.FALSE },
        { r2, r3, Boolean.FALSE }, { r2, r4, Boolean.FALSE }, };

    for (int i = 0; i < testSpec.length; i++)
    {
      final RDFList l0 = nilList.append(Arrays.asList(
          (Resource[]) testSpec[i][0]).iterator());
      final RDFList l1 = nilList.append(Arrays.asList(
          (Resource[]) testSpec[i][1]).iterator());
      final boolean expected = ((Boolean) testSpec[i][2]).booleanValue();

      Assert.assertEquals("sameListAs testSpec[" + i + "] incorrect",
          expected, l0.sameListAs(l1));
      Assert.assertEquals("sameListAs testSpec[" + i
          + "] (swapped) incorrect", expected, l1.sameListAs(l0));
    }
  }
View Full Code Here

        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "e"), };

    final RDFList l1 = getListRoot(model);

    // test normal gets
    for (int i = 0; i < toGet.length; i++)
    {
      Assert.assertEquals("list element " + i + " is not correct",
          toGet[i], l1.get(i));
    }

    // now test we get an exception for going beyong the end of the list
    boolean gotEx = false;
    try
    {
      l1.get(toGet.length + 1);
    }
    catch (final ListIndexException e)
    {
      gotEx = true;
    }
View Full Code Here

  public void testMap1()
  {
    model.read("file:testing/ontology/list5.rdf");

    final RDFList root = getListRoot(model);
    TestList.iteratorTest(root.mapWith(new Map1<RDFNode, String>() {
      @Override
      public String map1( final RDFNode x )
      {
        return ((Resource) x).getLocalName();
      }
View Full Code Here

  public void testReduce()
  {
    model.read("file:testing/ontology/list5.rdf");

    final RDFList root = getListRoot(model);

    final RDFList.ReduceFn f = new RDFList.ReduceFn() {
      @Override
      public Object reduce( final RDFNode n, final Object acc )
      {
        return ((String) acc) + ((Resource) n).getLocalName();
      }
    };

    Assert.assertEquals(
        "Result of reduce should be concatentation of local names",
        "abcde", root.reduce(f, ""));
  }
View Full Code Here

  public void testRemove()
  {

    final Resource nil = model.getResource(RDF.nil.getURI());
    RDFList list0 = nil.as(RDFList.class);
    RDFList list1 = nil.as(RDFList.class);

    final Resource r0 = model.createResource(TestList.NS + "x");
    final Resource r1 = model.createResource(TestList.NS + "y");
    final Resource r2 = model.createResource(TestList.NS + "z");

    for (int i = 0; i < 10; i++)
    {
      list0 = list0.cons(r0);
      list1 = list1.cons(r1);
    }

    // delete the elements of list0 one at a time
    while (!list0.isEmpty())
    {
      list0 = list0.removeHead();
      checkValid("removeTest0", list0, true);
    }

    // delete all of list1 in one go
    list1.removeList();

    // model should now be empty
    Assert.assertEquals("Model should be empty after deleting two lists",
        0, model.size());

    // selective remove
    RDFList list2 = (nil.as(RDFList.class)).cons(r2).cons(r1).cons(r0);

    Assert.assertTrue("list should contain x ", list2.contains(r0));
    Assert.assertTrue("list should contain y ", list2.contains(r1));
    Assert.assertTrue("list should contain z ", list2.contains(r2));

    list2 = list2.remove(r1);
    Assert.assertTrue("list should contain x ", list2.contains(r0));
    Assert.assertTrue("list should contain y ", !list2.contains(r1));
    Assert.assertTrue("list should contain z ", list2.contains(r2));

    list2 = list2.remove(r0);
    Assert.assertTrue("list should contain x ", !list2.contains(r0));
    Assert.assertTrue("list should contain y ", !list2.contains(r1));
    Assert.assertTrue("list should contain z ", list2.contains(r2));

    list2 = list2.remove(r2);
    Assert.assertTrue("list should contain x ", !list2.contains(r0));
    Assert.assertTrue("list should contain y ", !list2.contains(r1));
    Assert.assertTrue("list should contain z ", !list2.contains(r2));
    Assert.assertTrue("list should be empty", list2.isEmpty());
  }
View Full Code Here

    final Literal[] toSet = new Literal[] { model.createLiteral("a"),
        model.createLiteral("b"), model.createLiteral("c"),
        model.createLiteral("d"), model.createLiteral("e"), };

    final RDFList l1 = getListRoot(model);

    // change all the values
    for (int i = 0; i < toSet.length; i++)
    {
      l1.replace(i, toSet[i]);
    }

    // then check them
    for (int i = 0; i < toSet.length; i++)
    {
      Assert.assertEquals("list element " + i + " is not correct",
          toSet[i], l1.get(i));
    }

    // now test we get an exception for going beyong the end of the list
    boolean gotEx = false;
    try
    {
      l1.replace(toSet.length + 1, toSet[0]);
    }
    catch (final ListIndexException e)
    {
      gotEx = true;
    }
View Full Code Here

    model.add(list, RDF.type, RDF.List);
    model.add(list, RDF.first, "fred");
    model.add(list, RDF.rest, nil);

    model.add(root, p, list);
    final RDFList l1 = getListRoot(model);
    checkValid("sethead1", l1, true);

    Assert.assertEquals("List head should be 'fred'", "fred",
        ((Literal) l1.getHead()).getString());

    l1.setHead(model.createTypedLiteral(42));
    checkValid("sethead2", l1, true);
    Assert.assertEquals("List head should be '42'", 42,
        ((Literal) l1.getHead()).getInt());

  }
View Full Code Here

    m.add(list0, RDF.type, RDF.List);
    m.add(list0, RDF.first, "fred");
    m.add(list0, RDF.rest, nil);

    m.add(root, p, list0);
    final RDFList l1 = getListRoot(m);
    checkValid("settail1", l1, true);

    final Resource list1 = m.createResource();
    m.add(list1, RDF.type, RDF.List);
    m.add(list1, RDF.first, "george");
    m.add(list1, RDF.rest, nil);

    final RDFList l2 = list1.as(RDFList.class);
    Assert.assertNotNull("as(RDFList) should not return null for root", l2);
    checkValid("settail2", l2, true);

    Assert.assertEquals("l1 should have length 1", 1, l1.size());
    Assert.assertEquals("l2 should have length 1", 1, l2.size());

    // use set tail to join the lists together
    l1.setTail(l2);

    checkValid("settail3", l1, true);
    checkValid("settail4", l2, true);

    Assert.assertEquals("l1 should have length 2", 2, l1.size());
    Assert.assertEquals("l2 should have length 1", 1, l2.size());

  }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.RDFList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.