Package org.apache.clerezza.rdf.core.impl

Examples of org.apache.clerezza.rdf.core.impl.TripleImpl


  }

  @Test
  public void test5() {
    TripleCollection tc1 = new SimpleMGraph();
    tc1.add(new TripleImpl(new BNode(), u1, new BNode()));
    TripleCollection tc2 = new SimpleMGraph();
    tc2.add(new TripleImpl(new BNode(), u1, new BNode()));
    final Map<BNode, BNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
    Assert.assertNotNull(mapping);
    Assert.assertEquals(2, mapping.size());
  }
View Full Code Here


  @Test
  public void test6() {
    TripleCollection tc1 = new SimpleMGraph();
    final BNode b11 = new BNode();
    tc1.add(new TripleImpl(new BNode(), u1,b11));
    tc1.add(new TripleImpl(new BNode(), u1,b11));
    TripleCollection tc2 = new SimpleMGraph();
    tc2.add(new TripleImpl(new BNode(), u1, new BNode()));
    final Map<BNode, BNode> mapping = GraphMatcher.getValidMapping(tc1, tc2);
    Assert.assertNull(mapping);
  }
View Full Code Here

    }
    MGraph result = new SimpleMGraph();
    NonLiteral lastNode = firstNode;
    for (int i = 0; i < (size-1); i++) {
      final BNode newNode = new BNode();
      result.add(new TripleImpl(lastNode, u1, newNode));
      lastNode = newNode;
    }
    result.add(new TripleImpl(lastNode, u1, firstNode));
    return result;
  }
View Full Code Here

      final UriRef predicate, final Resource object,
      final TripleCollection base) {
    if ((subject != null) && (object != null)) {
      if (areSiblings(subject, object, base)) {
        return Collections.singleton(
            (Triple) new TripleImpl(subject, siblingProperty, object)).iterator();
      } else {
        List<Triple> emptyList = Collections.emptyList();
        return emptyList.iterator();
      }
    } else {
      if (subject != null) {
        final Iterator<NonLiteral> siblings =
            getSiblings(subject, base).iterator();
        return new Iterator<Triple>() {

          @Override
          public boolean hasNext() {
            return siblings.hasNext();
          }

          @Override
          public Triple next() {
            return new TripleImpl(subject, siblingProperty, siblings.next());
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException(
                "cannot delete infered triple");
          }
        };
      }
      if (object != null) {
        final Iterator<NonLiteral> siblings =
            getSiblings((NonLiteral) object,base).iterator();
        return new Iterator<Triple>() {

          @Override
          public boolean hasNext() {
            return siblings.hasNext();
          }

          @Override
          public Triple next() {
            return new TripleImpl(siblings.next(), siblingProperty, object);
          }

          @Override
          public void remove() {
            throw new UnsupportedOperationException(
View Full Code Here

    }
    MGraph result = new SimpleMGraph();
    NonLiteral lastNode = firstNode;
    for (int i = 0; i < size; i++) {
      final BNode newNode = new BNode();
      result.add(new TripleImpl(lastNode, u1, newNode));
      lastNode = newNode;
    }
    return result;
  }
View Full Code Here

   * @param bundle
   * @param docMGraph
   */
  private void addAdditionalTriples(Bundle bundle, MGraph docMGraph) {
    UriRef bundleUri = new UriRef(bundle.getLocation());
    Triple triple = new TripleImpl(bundleUri, RDF.type, OSGI.Bundle);
    docMGraph.add(triple);
    Iterator<Triple> titledContents = docMGraph.filter(null, RDF.type,
        DISCOBITS.TitledContent);
    Set<Triple> newTriples = new HashSet<Triple>();
    for (Iterator<Triple> it = titledContents; it.hasNext();) {
      NonLiteral titledContent = it.next().getSubject();
      if (docMGraph.filter(null, DISCOBITS.holds, titledContent).hasNext()) {
        continue;
      }
      triple = new TripleImpl(bundleUri, DOCUMENTATION.documentation,
          titledContent);
      newTriples.add(triple);
    }
    docMGraph.addAll(newTriples);
  }
View Full Code Here

    add(randomTriple);
    return randomTriple;
  }
 
  private Triple createRandomTriple() {
    return new TripleImpl(getSubject(), getPredicate(), getObject());
  }
View Full Code Here

  @Test
  public void listPositionTest() throws Exception {
    MGraph mGraph = new SimpleMGraph();
    CollectionCreator collectionCreator = new CollectionCreator(mGraph);
    collectionCreator.createContainingCollections(fooTestResource4);
    Assert.assertTrue(mGraph.contains(new TripleImpl(fooTest, RDF.type, HIERARCHY.Collection)));
    Assert.assertTrue(mGraph.contains(new TripleImpl(fooTestResource4, HIERARCHY.parent, fooTest)));
    Assert.assertTrue(mGraph.contains(new TripleImpl(foo, HIERARCHY.parent, root)));
    Assert.assertTrue(mGraph.contains(new TripleImpl(root, RDF.type, HIERARCHY.Collection)));
    collectionCreator.createContainingCollections(fooResource);
    Assert.assertTrue(mGraph.contains(new TripleImpl(fooResource, HIERARCHY.parent, foo)));
  }
View Full Code Here

 
  @Test
  public void testAddCountAndGetTriples() {
    MGraph graph = getEmptyMGraph();
    Assert.assertEquals(0, graph.size());
    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());
View Full Code Here

 
  @Test
  public void testRemoveAllTriples() {
    MGraph graph = getEmptyMGraph();
    Assert.assertEquals(0, graph.size());
    graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3));
    graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4));
    Assert.assertEquals(2, graph.size());
    graph.clear();
    Assert.assertEquals(0, graph.size());
  }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.impl.TripleImpl

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.