Examples of RdfList


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

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

  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

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

  }

  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

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

    // 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

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

  public void testMap1()
  {
    model.read(getFileName("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

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

  public void testReduce()
  {
    model.read(getFileName("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

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

  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

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

    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

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

    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

Examples of edu.mit.simile.fresnel.util.RDFList

      if (facetI.hasNext()) {
        Statement facetStmt = (Statement) facetI.next();
        Value facetsNode = facetStmt.getObject();
        if (facetI.hasNext()) throw new UnresolvableException("More than one :facets value available");
        if (facetsNode instanceof Resource && RDFList.isRDFList(source, (Resource) facetsNode)) {
          RDFList facetRDFList = new RDFList(source, (Resource) facetsNode);
          if (facetRDFList.isValid()) {
            for (Iterator listI = facetRDFList.iterator(); listI.hasNext(); ) {
              Resource facetNode = (Resource) listI.next();
              Facet facet = new Facet(facetNode);
              out.addFacet(facet);
            }
          } else {
            throw new ParsingException(facetsNode.toString() + "is not a valid rdf:List");
          }
        }
      }
      facetI.close();

            RepositoryResult<Statement> hidesI = conn.getStatements(focus, Facets.hides, (Value) null, false);
      if (hidesI.hasNext()) {
        Statement facetStmt = hidesI.next();
        Value facetsNode = facetStmt.getObject();
        if (hidesI.hasNext()) throw new UnresolvableException("More than one :hides value available");
        if (facetsNode instanceof Resource && RDFList.isRDFList(source, (Resource) facetsNode)) {
          RDFList facetRDFList = new RDFList(source, (Resource) facetsNode);
          if (facetRDFList.isValid()) {
            for (Iterator listI = facetRDFList.iterator(); listI.hasNext(); ) {
              Resource facetNode = (Resource) listI.next();
              Facet facet = new Facet(facetNode);
              out.addHide(facet);
            }
          } else {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.