Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.Triple


    }

    @Test
    public void testGraphIsNotMutable() throws Exception {

        Triple t1 = createTestTriple();
        Set<Triple> t = new HashSet<Triple>();
        t.add(t1);

        TcProvider provider = getInstance();
View Full Code Here


    readLock.lock();
    try {
      Iterator<Triple> typeStmts = contentMGraph.filter(uri, RDF.type, null);

      while (typeStmts.hasNext()) {
        Triple triple = typeStmts.next();
        Resource typeStmtObj = triple.getObject();
        if (!(typeStmtObj instanceof UriRef)) {
          throw new RuntimeException(
              "RDF type is expected to be a URI but is " + typeStmtObj
              + "(in " + triple + ")");
        }
View Full Code Here

    if (uriString.charAt(uriString.length()-1) != '/') {
      uriString += '/';
    }
    UriRef nodeUri = new UriRef(uriString);
    final MGraph mGraph = cgProvider.getContentGraph();
    Triple typeTriple = new TripleImpl(nodeUri, RDF.type, HIERARCHY.Collection);
    if (mGraph.contains(typeTriple)) {
      return Response.status(405) // Method Not Allowed
          .entity("Collection \"" + nodeUri.getUnicodeString()
          + "\" already exists.").build();
    }
View Full Code Here

        return lastReturned;
      }

      @Override
      public void remove() {
        final Triple deleting = lastReturned;
        if (precached == null) {
          final ArrayList<Triple> data = new ArrayList<Triple>();
          while (hasNext()) {
            data.add(next());
          }
View Full Code Here

    while (properties.hasNext()) {
      propertiesSet.add(properties.next());
    }
    properties = propertiesSet.iterator();
    while (properties.hasNext()) {
      Triple triple = properties.next();
      UriRef predicate = triple.getPredicate();
      if (predicate.equals(DISCOBITS.contains)) {
        try {
          GraphNode containedNode = new GraphNode((NonLiteral)triple.getObject(), mGraph);
          //The following includes triple
          containedNode.deleteNodeContext();
        } catch (ClassCastException e) {
          throw new RuntimeException("The value of "+predicate+" is expected not to be a literal");
        }
View Full Code Here

    return wrapped.hasNext();
  }

  @Override
  public Triple next() {
    Triple triple = wrapped.next();

    NonLiteral subject = triple.getSubject();
    if (subject instanceof UriRef) {
      subject = replacePlaceHolder((UriRef) subject);
    }
    UriRef predicate = replacePlaceHolder(triple.getPredicate());

    Resource object = triple.getObject();
    if (object instanceof UriRef) {
      object = replacePlaceHolder((UriRef) object);
    } else if (object instanceof TypedLiteral) {
      TypedLiteral literal = (TypedLiteral) object;
      if (literal.getDataType().equals(XML_LITERAL)) {
View Full Code Here

      return false;
    }
    if (!(obj instanceof Triple)) {
      return false;
    }
    final Triple other = (Triple) obj;
    if (!this.subject.equals(other.getSubject())) {
      return false;
    }
    if (!this.predicate.equals(other.getPredicate())) {
      return false;
    }
    if (!this.object.equals(other.getObject())) {
      return false;
    }
    return true;
  }
View Full Code Here

    final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
    graph.add(triple1);
    Assert.assertEquals(1, graph.size());
    Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, uriRef1);
    Assert.assertTrue(tripleIter.hasNext());
    Triple tripleGot = tripleIter.next();
    Assert.assertEquals(triple1, tripleGot);
    Assert.assertFalse(tripleIter.hasNext());
    BNode bnode = new BNode() {};
    graph.add(new TripleImpl(bnode, uriRef1, uriRef3));
    graph.add(new TripleImpl(bnode, uriRef1, uriRef4));
    tripleIter = graph.filter(null, uriRef1, null);
    Set<NonLiteral> subjectInMatchingTriples = new HashSet<NonLiteral>();
    Set<Resource> objectsInMatchingTriples = new HashSet<Resource>();
    while (tripleIter.hasNext()) {
      Triple triple = tripleIter.next();
      subjectInMatchingTriples.add(triple.getSubject());
      objectsInMatchingTriples.add(triple.getObject());
    }
    Assert.assertEquals(1, subjectInMatchingTriples.size());
    Assert.assertEquals(2, objectsInMatchingTriples.size());
    Set<Resource> expectedObjects = new HashSet<Resource>();
    expectedObjects.add(uriRef3);
    expectedObjects.add(uriRef4);
    Assert.assertEquals(expectedObjects, objectsInMatchingTriples);
    graph.add(new TripleImpl(bnode, uriRef4, bnode));
    tripleIter = graph.filter(null, uriRef4, null);
    Assert.assertTrue(tripleIter.hasNext());
    Triple retrievedTriple = tripleIter.next();
    Assert.assertFalse(tripleIter.hasNext());
    Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
    tripleIter = graph.filter(uriRef1, uriRef2, null);
    Assert.assertTrue(tripleIter.hasNext());
    retrievedTriple = tripleIter.next();
    Assert.assertFalse(tripleIter.hasNext());
    Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
  }
View Full Code Here


  @Test
  public void testAddSingleTriple() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple triple= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    Assert.assertEquals(0, graph.size());
    Assert.assertTrue(graph.add(triple));
View Full Code Here


  @Test
  public void testAddSameTripleTwice() throws Exception {
    MGraph graph = getEmptyMGraph();
    final Triple triple= createTriple(
        "http://example.org/ontology/Person",
        "http://example.org/ontology/hasName",
        "http://example.org/people/alice");
    Assert.assertEquals(0, graph.size());
    Assert.assertTrue(graph.add(triple));
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.Triple

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.