Package org.apache.clerezza.rdf.core

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


    UriRef property2 = new UriRef("http://example.org/property2");
    UriRef newUriRef = new UriRef("http://example.org/newName");
    Literal literal1 = new PlainLiteralImpl("literal");
    Literal literal2 = new PlainLiteralImpl("bla bla");

    Triple triple1 = new TripleImpl(bNode1, property1, literal1);
    Triple triple2 = new TripleImpl(bNode1, property2, property1);
    Triple triple3 = new TripleImpl(bNode2, property2, bNode1);
    Triple triple4 = new TripleImpl(property1, property1, bNode2);
    Triple triple5 = new TripleImpl(property1, property1, literal2);
    initialGraph.add(triple1);
    initialGraph.add(triple2);
    initialGraph.add(triple3);
    initialGraph.add(triple4);
    initialGraph.add(triple5);
    GraphNode node = new GraphNode(property1,
        new SimpleMGraph(initialGraph.iterator()));

    node.replaceWith(newUriRef, true);
    Assert.assertEquals(5, node.getGraph().size());
    Triple expectedTriple1 = new TripleImpl(bNode1, newUriRef, literal1);
    Triple expectedTriple2 = new TripleImpl(bNode1, property2, newUriRef);
    Triple expectedTriple3 = new TripleImpl(newUriRef, newUriRef, bNode2);
    Triple expectedTriple4 = new TripleImpl(newUriRef, newUriRef, literal2);

    Assert.assertTrue(node.getGraph().contains(expectedTriple1));
    Assert.assertTrue(node.getGraph().contains(expectedTriple2));
    Assert.assertTrue(node.getGraph().contains(expectedTriple3));
    Assert.assertTrue(node.getGraph().contains(expectedTriple4));

    Assert.assertFalse(node.getGraph().contains(triple1));
    Assert.assertFalse(node.getGraph().contains(triple2));
    Assert.assertFalse(node.getGraph().contains(triple4));
    Assert.assertFalse(node.getGraph().contains(triple5));

    node = new GraphNode(property1, new SimpleMGraph(initialGraph.iterator()));
    node.replaceWith(newBnode);
    Triple expectedTriple5 = new TripleImpl(bNode1, property2, newBnode);
    Triple expectedTriple6 = new TripleImpl(newBnode, property1, bNode2);
    Triple expectedTriple7 = new TripleImpl(newBnode, property1, literal2);

    Assert.assertTrue(node.getGraph().contains(triple1));
    Assert.assertTrue(node.getGraph().contains(expectedTriple5));
    Assert.assertTrue(node.getGraph().contains(expectedTriple6));
    Assert.assertTrue(node.getGraph().contains(expectedTriple7));

    node = new GraphNode(literal1, new SimpleMGraph(initialGraph.iterator()));
    node.replaceWith(newBnode);
    Triple expectedTriple8 = new TripleImpl(bNode1, property1, newBnode);
    Assert.assertTrue(node.getGraph().contains(expectedTriple8));

    node = new GraphNode(property1, new SimpleMGraph(initialGraph.iterator()));
    node.replaceWith(newUriRef);
    Triple expectedTriple9 = new TripleImpl(bNode1, property2, newUriRef);
    Triple expectedTriple10 = new TripleImpl(newUriRef, property1, bNode2);
    Triple expectedTriple11 = new TripleImpl(newUriRef, property1, literal2);
    Assert.assertTrue(node.getGraph().contains(triple1));
    Assert.assertTrue(node.getGraph().contains(expectedTriple9));
    Assert.assertTrue(node.getGraph().contains(expectedTriple10));
    Assert.assertTrue(node.getGraph().contains(expectedTriple11));
  }
View Full Code Here


      Iterator<Triple> javaPermissionTriples =
          systemGraph.filter(permission, PERMISSION.javaPermissionEntry, null);

      while (javaPermissionTriples.hasNext()) {

        Triple t = javaPermissionTriples.next();
        Literal permEntry = (Literal) t.getObject();

        permInfoList.add(new PermissionInfo(permEntry.getLexicalForm()));
      }
    }
View Full Code Here

    public int getRowCount() {
      return tripleList.size();
    }

    public Object getValueAt(int row, int col) {
      Triple triple = tripleList.get(row);
      switch (col) {
        case 0:
          return triple.getSubject();
        case 1:
          return triple.getPredicate();
        default:
          return triple.getObject();
      }
    }
View Full Code Here

    Map<UriRef,DocumentationItem> uri2docItemObj =
      new HashMap<UriRef,DocumentationItem>();
   
    while (docs.hasNext()) {
      Triple docc = docs.next();
      UriRef docItem = (UriRef) docc.getObject();
      Iterator<Triple> afterDocItemsIter = documentations.filter(docItem,
        DOCUMENTATION.after, null);
      Set<UriRef> afterDocItems = new HashSet<UriRef>();
      while (afterDocItemsIter.hasNext()) {
        afterDocItems.add((UriRef) afterDocItemsIter.next().getObject());
View Full Code Here

    TcManager.getInstance().createMGraph(new UriRef("http://example.org/read/graph"));
  }
  @Test(expected=ReadOnlyException.class)
  public void testAddTripleToMGraph() {
    MGraph mGraph = TcManager.getInstance().getMGraph(new UriRef("http://example.org/read/graph"));
    Triple triple = new TripleImpl(new UriRef("http://example.org/definition/isNonLiteral"), new UriRef("http://example.org/definition/isTest"), new PlainLiteralImpl("test"));
    mGraph.add(triple);
  }
View Full Code Here

  public void dateStorage() {
    MGraph graph = getEmptyMGraph();
    Date date = new Date(0);
    LiteralFactory literalFactory = LiteralFactory.getInstance();
    TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
    Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), dateLiteral);
    graph.add(triple);
    Assert.assertTrue(graph.contains(triple));
  }
View Full Code Here

    Date date = new Date(0);
    LiteralFactory literalFactory = LiteralFactory.getInstance();
    TypedLiteral dateLiteral = literalFactory.createTypedLiteral(date);
    System.out.println(dateLiteral);
    UriRef property = new UriRef("http://example.com/property");
    Triple triple = new TripleImpl(new BNode(), property, dateLiteral);
    graph.add(triple);

    Triple tripleFromGraph = null;
    Iterator<Triple> propertyTriples = graph.filter(null, property, dateLiteral);
    if (propertyTriples.hasNext()) {
      tripleFromGraph = propertyTriples.next();
    } else {
      Assert.assertTrue(false);
    }
    Assert.assertEquals(dateLiteral, tripleFromGraph.getObject());
  }
View Full Code Here

    @Override
    public void run() {
      while (!stopRequested) {
        Literal randomLiteral = new PlainLiteralImpl(Util.createRandomString(22));
        Triple triple = new TripleImpl(new BNode(), new UriRef("http://example.com/property"), randomLiteral);
        mGraph.add(triple);
        addedTripleCount++;
        if ((addedTripleCount % 100) == 0) {
          testTriples.add(triple);
        }
View Full Code Here

    tmp.addAll(tc);

    List<MSG> msgSet = new LinkedList<MSG>();

    while (tmp.size() > 0) {
      Triple triple = tmp.iterator().next();
      TripleCollection msgTc = new SimpleMGraph();

      boolean containsBNode = fillMSG(triple, tmp, msgTc);
      MSG msg = new MSG(msgTc);
      msg.containsBlankNodes = containsBNode;
View Full Code Here

    typeChangeListener = new GraphListener() {

      @Override
      public void graphChanged(List<GraphEvent> events) {
        for (GraphEvent e : events) {
          Triple triple = e.getTriple();
          logger.debug("processing addition of type " + triple.getObject());
          if (type2IndexedProperties.containsKey((UriRef) triple.getObject())) {
            scheduleForReindex(triple.getSubject());
          }

        }
      }
    };

    baseGraph.addGraphListener(typeChangeListener, new FilterTriple(null, RDF.type, null));

    indexedPropertyChangeListener = new GraphListener() {

      @Override
      public void graphChanged(List<GraphEvent> events) {
        for (GraphEvent e : events) {
          logger.debug("Triple: " + e.getTriple());
          Triple triple = e.getTriple();

          UriRef predicate = triple.getPredicate();
          Set<VirtualProperty> vProperties = property2IncludingVProperty.get(predicate);

          List<Resource> indexedResources = new ArrayList<Resource>();
          logger.debug("Predicate: " + predicate);
          for (VirtualProperty vProperty : vProperties) {
            logger.debug("Subject: " + " " + triple.getSubject());
            followInversePaths(triple.getSubject(),
                vProperty.pathToIndexedResource(predicate), indexedResources);

          }
          for (Resource resource : indexedResources) {
            GraphNode node = new GraphNode(resource, e.getGraph());
            List<UriRef> types = new ArrayList<UriRef>();
            Lock lock = node.readLock();
            lock.lock();
            try {
              Iterator<Resource> resources = node.getObjects(RDF.type);
              while (resources.hasNext()) {
                Resource res = resources.next();
                if (res instanceof UriRef) {
                  types.add((UriRef) res);
                }
              }
            } finally {
              lock.unlock();
            }
            for (UriRef type : types) {
              if (type2IndexedProperties.containsKey(type)) {
                scheduleForReindex(resource);
              }
            }
          }

        }
      }
    };

    baseGraph.addGraphListener(indexedPropertyChangeListener,
        new FilterTriple(null, null, null) {

      @Override
      public boolean match(Triple triple) {
        UriRef predicate = triple.getPredicate();
        //check indirectly involved properties
        Set<VirtualProperty> vProperties = property2IncludingVProperty.get(predicate);
        if (vProperties != null) {
          for (VirtualProperty vProperty : vProperties) {
            if (property2TypeMap.containsKey(vProperty)) {
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.