Package org.apache.clerezza.rdf.core

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


        mGraph.add(new TripleImpl(uriRefA1, uriRefA1, uriRefA1));
        mGraph = simpleTcmProvider.createMGraph(uriRefB1);
        mGraph.add(new TripleImpl(uriRefB1, uriRefB1, uriRefB1));

        // get a Graph
        TripleCollection tripleCollection = simpleTcmProvider.getTriples(uriRefA);
        // get a MGraph
        TripleCollection tripleCollection2 = simpleTcmProvider.getTriples(uriRefB1);

        Iterator<Triple> iterator = tripleCollection.iterator();
        assertEquals(new TripleImpl(uriRefA, uriRefA, uriRefA), iterator.next());
        assertFalse(iterator.hasNext());

        iterator = tripleCollection2.iterator();
        assertEquals(new TripleImpl(uriRefB1, uriRefB1, uriRefB1), iterator.next());
        assertFalse(iterator.hasNext());
    }
View Full Code Here


//    }

    @Test
    public void testGraphDeletion() throws Exception {

        TripleCollection triples = createTestTripleCollection(createTestTriple());

        TcProvider provider = getInstance();
        UriRef name1 = new UriRef("http://myGraph1");
        Graph graph = provider.createGraph(name1, triples);
View Full Code Here

    @Test
    public void testGetTriplesGraph() throws Exception {
        TcProvider provider = getInstance();
        Graph graph = provider.createGraph(graphUriRef,
                createTestTripleCollection(createTestTriple()));
        TripleCollection tc = provider.getTriples(graphUriRef);
        assertNotNull(tc);
    }
View Full Code Here

    public void testGetTriplesMGraph() throws Exception {
        TcProvider provider = getInstance();

        MGraph graph = provider.createMGraph(graphUriRef);

        TripleCollection tc = provider.getTriples(graphUriRef);
        assertNotNull(tc);
    }
View Full Code Here

    testWithFiles("ifTest.turtle", "ifTest.seed", "ifTest.txt");
  }

  private void testWithFiles(String triples, String template, String expected)
      throws Exception {
    TripleCollection tc = Parser.getInstance().parse(
        getClass().getResourceAsStream(triples),
        "text/turtle");
    GraphNode res = new GraphNode(root, tc);
    ByteArrayOutputStream baosRendered = new ByteArrayOutputStream();
    renderlet.render(res, null, null, null,
View Full Code Here

    multistatus.appendChild(responseElement);
    responseElement.appendChild(hrefElement);

    Map<Property, String> setMap = getNodeListAsMap(propsToSet);
    Map<Property, String> removeMap = getNodeListAsMap(propsToRemove);
    TripleCollection contentGraph = hierarchyNode.getGraph();
    for(Map.Entry<Property, String> entry : setMap.entrySet()){
      Property property = entry.getKey();
      if(property.ns.equalsIgnoreCase(davUri)){
        if(protectedProps.contains(property.prop)){
          propForbidden.appendChild(responseDoc
              .createElementNS(davUri, property.prop));
        } else {
          UriRef predicate = new UriRef(property.value());
          Lock writeLock = hierarchyNode.writeLock();
          writeLock.lock();
          try {
            Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
            replaceProp(subject, predicate, valIter, contentGraph, entry);
          } finally {
            writeLock.unlock();
          }
          propOk.appendChild(responseDoc.createElementNS(davUri, property.prop));
        }
      } else {
        UriRef predicate = new UriRef(property.value());
        Lock writeLock = hierarchyNode.writeLock();
        writeLock.lock();
        try {
          Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
          replaceProp(subject, predicate, valIter, contentGraph, entry);
        } finally {
          writeLock.unlock();
        }
        propOk.appendChild(responseDoc.createElementNS(property.ns, "R:" + property.prop));
      }
    }

    for(Map.Entry<Property, String> entry : removeMap.entrySet()){
      Property property = entry.getKey();
      if(davProps.contains(property.prop)){
        propForbidden.appendChild(responseDoc
              .createElementNS(davUri, property.prop));
      } else {
        UriRef predicate = new UriRef(property.value());
        Lock writeLock = hierarchyNode.writeLock();
        writeLock.lock();
        try {
          Iterator<Resource> valIter = hierarchyNode.getObjects(predicate);
          Set<Triple> triplesToBeRemoved = new HashSet<Triple>();
          while (valIter.hasNext()) {
            triplesToBeRemoved.add(new TripleImpl(subject, predicate, valIter.next()));
          }
          contentGraph.removeAll(triplesToBeRemoved);
        } finally {
          writeLock.unlock();
        }
        propOk.appendChild(responseDoc.createElementNS(property.ns, property.prop));
View Full Code Here

  private GraphNode getResourceAsGraphNode(UriInfo uriInfo) {
    final UriRef uri = new UriRef(uriInfo.getAbsolutePath().toString());
    GraphNode result = graphNodeProvider.getLocal(uri);
    //could chck if nodeContext > 0, but this would be less efficient
    TripleCollection tc = result.getGraph();
    if (tc.filter(uri, null, null).hasNext()) {
      return result;
    }
    if (tc.filter(null, null, uri).hasNext()) {
      return result;
    }
    return null;
  }
View Full Code Here

  final static UriRef u1 = new UriRef("http://example.org/u1");

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

    Assert.assertEquals(0, mapping.size());
  }

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

    Assert.assertNull(mapping);
  }

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

TOP

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

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.