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

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


 
  private List<String> _getDataRangeElementList(DataRange dataRange) {
    List<String> list = new ArrayList<String>();
    if ( dataRange != null ) {
      RDFList rdfList = dataRange.getOneOf();
      while ( rdfList != null && ! rdfList.isEmpty() ) {
        RDFNode elem = rdfList.getHead();
        Literal obj = (Literal) elem;
        String name = obj.getLexicalForm();
        list.add(name);
        rdfList = rdfList.getTail();
      }
    }
    return list;
  }
View Full Code Here


    Assert.assertNotNull("Root resource should not be null", root);

    final Resource listHead = root.getRequiredProperty(
        m.getProperty(TestList.NS + "p")).getResource();

    final RDFList l = listHead.as(RDFList.class);
    Assert.assertNotNull("as(RDFList) should not return null for root", l);

    return l;
  }
View Full Code Here

    final Resource root = model.createResource(TestList.NS + "root");
    final Property p = model.createProperty(TestList.NS, "p");

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

    final Resource[] toAdd = new Resource[] {
        model.createResource(TestList.NS + "a"),
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "e"), };

    // add each of these resources onto the end of the list
    for (final Resource element : toAdd)
    {
      final RDFList list0 = list.with(element);

      checkValid("addTest0", list0, true);
      Assert.assertTrue("added'ed lists should be equal",
          list.equals(nil) || list0.equals(list));

      list = list0;
    }

    // relate the root to the list
View Full Code Here

  public void testAppend()
  {
    model.read(getFileName("ontology/list5.rdf"));

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

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

    // create a list of foos
    for (int i = 0; i < 5; i++)
    {
      list = list.cons(r);
    }

    final int listLen = list.size();

    // now append foos to the root list
    final RDFList root = getListRoot(model);
    final int rootLen = root.size();

    final RDFList appended = root.append(list);

    // original list should be unchanged
    checkValid("appendTest0", root, true);
    Assert.assertEquals("Original list should be unchanged", rootLen,
        root.size());

    checkValid("appendTest1", list, true);
    Assert.assertEquals("Original list should be unchanged", listLen,
        list.size());

    // new list should be length of combined
    checkValid("appendTest2", appended, true);
    Assert.assertEquals("Appended list not correct length", rootLen
        + listLen, appended.size());
  }
View Full Code Here

  public void testApply()
  {
    model.read(getFileName("ontology/list5.rdf"));

    final RDFList root = getListRoot(model);

    class MyApply implements RDFList.ApplyFn
    {
      String collect = "";

      @Override
      public void apply( final RDFNode n )
      {
        collect = collect + ((Resource) n).getLocalName();
      }
    }

    final MyApply f = new MyApply();
    root.apply(f);

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

  public void testConcatenate()
  {
    model.read(getFileName("ontology/list5.rdf"));

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

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

    // create a list of foos
    for (int i = 0; i < 5; i++)
    {
      list = list.cons(r);
    }

    final int listLen = list.size();

    // now append foos to the root list
    final RDFList root = getListRoot(model);
    final int rootLen = root.size();
    root.concatenate(list);

    // original list should be unchanged
    checkValid("concatTest0", list, true);
    Assert.assertEquals("Original list should be unchanged", listLen,
        list.size());

    // but lhs list has changed
    checkValid("concatTest1", root, true);
    Assert.assertEquals("Root list should be new length",
        rootLen + listLen, root.size());
  }
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 aList = model.createList().cons(a);
    final RDFList rsList = model.createList(rs);

    // concatenate the above resources onto the empty list
    aList.concatenate(rsList);
    checkValid("concatTest3", aList, true);

    final RDFList root = getListRoot(model);
    Assert.assertTrue("Constructed and loaded lists should be the same",
        aList.sameListAs(root));
  }
View Full Code Here

  {
    final Resource root = model.createResource(TestList.NS + "root");
    final Property p = model.createProperty(TestList.NS, "p");

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

    final Resource[] toAdd = new Resource[] {
        model.createResource(TestList.NS + "e"),
        model.createResource(TestList.NS + "d"),
        model.createResource(TestList.NS + "c"),
        model.createResource(TestList.NS + "b"),
        model.createResource(TestList.NS + "a"), };

    // cons each of these resources onto the front of the list
    for (final Resource element : toAdd)
    {
      final RDFList list0 = list.cons(element);

      checkValid("constest1", list0, true);
      Assert.assertTrue("cons'ed lists should not be equal",
          !list0.equals(list));

      list = list0;
    }

    // relate the root to the list
View Full Code Here

    for (int i = 0; i <= 5; i++)
    {
      model.removeAll();
      model.read( getFileName("ontology/list" + i + ".rdf"));

      final RDFList l0 = getListRoot(model);
      Assert.assertEquals("List size should be " + i, i, l0.size());
    }

  }
View Full Code Here

  public void testHead()
  {
    model.read(getFileName("ontology/list5.rdf"));

    RDFList l0 = getListRoot(model);

    final String[] names = { "a", "b", "c", "d", "e" };
    for (final String name : names)
    {
      Assert.assertEquals("head of list has incorrect URI", TestList.NS
          + name, ((Resource) l0.getHead()).getURI());
      l0 = l0.getTail();
    }
  }
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.