Package org.apache.clerezza.rdf.core

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


  public static void removeSubGraph(MGraph mGraph, TripleCollection subGraph)
      throws NoSuchSubGraphException {
    //point to triples of mGraph that are to be removed (if something is removed)
    final Set<Triple> removingTriples = new HashSet<Triple>();
    //we first check only the grounded triples and put the non-grounded in here:
    final TripleCollection unGroundedTriples = new SimpleMGraph();
    for (Triple triple : subGraph) {
      if (isGrounded(triple)) {
        if (!mGraph.contains(triple)) {
          throw new NoSuchSubGraphException();
        }
        removingTriples.add(triple);
      } else {
        unGroundedTriples.add(triple);
      }
    }

    //we first remove the context of bnodes we find in object position
    OBJ_BNODE_LOOP: while (true) {
      final Triple triple = getTripleWithBNodeObject(unGroundedTriples);
      if (triple == null) {
        break;
      }
      final GraphNode objectGN = new GraphNode(triple.getObject(), unGroundedTriples);
      NonLiteral subject = triple.getSubject();
      Graph context = objectGN.getNodeContext();
      Iterator<Triple> potentialIter = mGraph.filter(subject, triple.getPredicate(), null);
      while (potentialIter.hasNext()) {
        try {
          final Triple potentialTriple = potentialIter.next();
          BNode potentialMatch = (BNode)potentialTriple.getObject();
          final Graph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
          if (potentialContext.equals(context)) {
            removingTriples.addAll(potentialContext);
            unGroundedTriples.removeAll(context);
            continue OBJ_BNODE_LOOP;
          }
        } catch (ClassCastException e) {
          continue;
        }
      }
      throw new NoSuchSubGraphException();
    }
    SUBJ_BNODE_LOOP: while (true) {
      final Triple triple = getTripleWithBNodeSubject(unGroundedTriples);
      if (triple == null) {
        break;
      }
      final GraphNode subjectGN = new GraphNode(triple.getSubject(), unGroundedTriples);
      Resource object = triple.getObject();
      if (object instanceof BNode) {
        object = null;
      }
      Graph context = subjectGN.getNodeContext();
      Iterator<Triple> potentialIter = mGraph.filter(null, triple.getPredicate(), object);
      while (potentialIter.hasNext()) {
        try {
          final Triple potentialTriple = potentialIter.next();
          BNode potentialMatch = (BNode)potentialTriple.getSubject();
          final Graph potentialContext = new GraphNode(potentialMatch, mGraph).getNodeContext();
          if (potentialContext.equals(context)) {
            removingTriples.addAll(potentialContext);
            unGroundedTriples.removeAll(context);
            continue SUBJ_BNODE_LOOP;
          }
        } catch (ClassCastException e) {
          continue;
        }
View Full Code Here


    }
  };

  @Test
  public void simple() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new BNode() {
    };
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${ns:rdfs=http://www.w3.org/2000/01/rdf-schema#}${rdfs:comment}");
    StringWriter writer = new StringWriter();
View Full Code Here

    Assert.assertEquals("\"a resource\"", writer.toString());
  }

  @Test
  public void inverse() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral subject = new UriRef("http://example.org/subject");
    UriRef object = new UriRef("http://example.org/object");
    mGraph.add(new TripleImpl(subject, RDFS.comment, object));
    GraphNode node = new GraphNode(object, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${ns:rdfs=http://www.w3.org/2000/01/rdf-schema#}${-rdfs:comment}");
    StringWriter writer = new StringWriter();
View Full Code Here

    Assert.assertTrue(contextProvider != null);
    GraphNode node = new GraphNode(new BNode(), new SimpleMGraph());
    contextProvider.addUserContext(node);
    Iterator<Resource> iter = node.getObjects(GLOBALMENU.globalMenu);
    Assert.assertTrue(iter.hasNext());
    TripleCollection graph = node.getGraph();
    RdfList list = new RdfList((NonLiteral)iter.next(), graph);
    Assert.assertEquals(3, list.size());
    Assert.assertEquals(GlobalMenuItemsProviderA.groupALabel,
        getLabel(graph, list.get(0)));
    Assert.assertEquals(GlobalMenuItemsProviderA.groupCLabel,
View Full Code Here

    Assert.assertEquals("<http://example.org/subject>", writer.toString());
  }

  @Test
  public void defaultFunction() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new BNode() {
    };
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, new RenderingFunctions() {

      @Override
      public RenderingFunction<Object, String> getDefaultFunction() {
View Full Code Here

    Assert.assertEquals("VALUE:\"a resource\"", writer.toString());
  }

  @Test
  public void simpleUriRefRoot() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new UriRef("http://example.org/");
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${ns:rdfs=http://www.w3.org/2000/01/rdf-schema#}${.}${rdfs:comment}");
    StringWriter writer = new StringWriter();
View Full Code Here

    Assert.assertEquals("<http://example.org/>\"a resource\"", writer.toString());
  }

  @Test
  public void simpleWithNoOp() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new BNode() {
    };
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${ns:rdfs=http://www.w3.org/2000/01/rdf-schema#}${noop(rdfs:comment)}");
    StringWriter writer = new StringWriter();
View Full Code Here

    Assert.assertEquals("\"a resource\"", writer.toString());
  }

  @Test
  public void simpleWithUppercase() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new BNode() {
    };
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${ns:rdfs=http://www.w3.org/2000/01/rdf-schema#}${uppercase(rdfs:comment)}");
    StringWriter writer = new StringWriter();
View Full Code Here

    Assert.assertEquals("\"A RESOURCE\"", writer.toString());
  }

  @Test
  public void simpleWithLiteralUppercase() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new BNode() {
    };
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${uppercase(\"a string\")}");
    StringWriter writer = new StringWriter();
View Full Code Here

    Assert.assertEquals("A STRING", writer.toString());
  }

  @Test
  public void simpleWithCombinedFunctions() throws IOException {
    TripleCollection mGraph = new SimpleMGraph();
    NonLiteral resource = new BNode() {
    };
    mGraph.add(new TripleImpl(resource, RDFS.comment, new PlainLiteralImpl("a resource")));
    GraphNode node = new GraphNode(resource, mGraph);
    DataFieldResolver dataFieldResolver = new GraphNodeDataFieldResolver(node, simpleFunctions);

    StringReader reader = new StringReader("${ns:rdfs=http://www.w3.org/2000/01/rdf-schema#}${noop(uppercase(noop(rdfs:comment)))}");
    StringWriter writer = new StringWriter();
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.