Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.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;
View Full Code Here


    UriRef expectedUriRef = new UriRef(HOST +
        "bundle-doc/"+ REFERENCED_BUNDLE_NAME +"/bla#Test");
    mGraph.add(new TripleImpl(uriRef, uriRef, uriRef));
    Iterator<Triple> it = new UriMutatorIterator(mGraph.iterator(), HOST,
        ORIGIN_BUNDLE_NAME);
    Triple expectedTriple = new TripleImpl(expectedUriRef, expectedUriRef,
        expectedUriRef);
    Assert.assertEquals(expectedTriple, it.next());   
  }
View Full Code Here

    UriRef expectedUriRef = new UriRef(HOST +
        "bundle-doc/"+ ORIGIN_BUNDLE_NAME +"/bla#Test");
    mGraph.add(new TripleImpl(uriRef, uriRef, uriRef));
    Iterator<Triple> it = new UriMutatorIterator(mGraph.iterator(), HOST,
        ORIGIN_BUNDLE_NAME);
    Triple expectedTriple = new TripleImpl(expectedUriRef, expectedUriRef,
        expectedUriRef);
    Assert.assertEquals(expectedTriple, it.next());
  }
View Full Code Here

          UriMutatorIterator.XML_LITERAL);
    UriRef uriRef = new UriRef("bla");
      mGraph.add(new TripleImpl(uriRef, uriRef, literal));
    Iterator<Triple> it = new UriMutatorIterator(mGraph.iterator(), HOST,
        ORIGIN_BUNDLE_NAME);
    Triple expectedTriple = new TripleImpl(uriRef, uriRef,
        expectedLiteral);
    Assert.assertEquals(expectedTriple, it.next());
  }
View Full Code Here

          UriMutatorIterator.XML_LITERAL);
    UriRef uriRef = new UriRef("bla");
      mGraph.add(new TripleImpl(uriRef, uriRef, literal));
    Iterator<Triple> it = new UriMutatorIterator(mGraph.iterator(), HOST,
        ORIGIN_BUNDLE_NAME);
    Triple expectedTriple = new TripleImpl(uriRef, uriRef,
        expectedLiteral);
    Assert.assertEquals(expectedTriple, it.next());
  }
View Full Code Here

  @Override
  public Object[] toArray() {
    Object[] result = base.toArray();
    for (int i = 0; i < result.length; i++) {
      Triple triple = (Triple) result[i];
      result[i] = toTargetTriple(triple);
    }
    return result;
  }
View Full Code Here

  @Override
  public <T> T[] toArray(T[] a) {
    T[] result = base.toArray(a);
    for (int i = 0; i < result.length; i++) {
      Triple triple = (Triple) result[i];
      result[i] = (T) toTargetTriple(triple);
    }
    return result;
  }
View Full Code Here

   */
  public static void smush(MGraph mGraph, TripleCollection tBox) {
    final Set<UriRef> ifps = getIfps(tBox);
    final Map<PredicateObject, Set<NonLiteral>> ifp2nodesMap = new HashMap<PredicateObject, Set<NonLiteral>>();
    for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
      final Triple triple = it.next();
      final UriRef predicate = triple.getPredicate();
      if (!ifps.contains(predicate)) {
        continue;
      }
      final PredicateObject po = new PredicateObject(predicate, triple.getObject());
      Set<NonLiteral> equivalentNodes = ifp2nodesMap.get(po);
      if (equivalentNodes == null) {
        equivalentNodes = new HashSet<NonLiteral>();
        ifp2nodesMap.put(po, equivalentNodes);
      }
      equivalentNodes.add(triple.getSubject());
    }
    Set<Set<NonLiteral>> unitedEquivalenceSets = uniteSetsWithCommonElement(ifp2nodesMap.values());
    Map<NonLiteral, NonLiteral> current2ReplacementMap = new HashMap<NonLiteral, NonLiteral>();
    final MGraph owlSameAsGraph = new SimpleMGraph();
    for (Set<NonLiteral> equivalenceSet : unitedEquivalenceSets) {
      final NonLiteral replacement = getReplacementFor(equivalenceSet, owlSameAsGraph);
      for (NonLiteral current : equivalenceSet) {
        if (!current.equals(replacement)) {
          current2ReplacementMap.put(current, replacement);
        }
      }
    }
    final Set<Triple> newTriples = new HashSet<Triple>();
    for (Iterator<Triple> it = mGraph.iterator(); it.hasNext();) {
      final Triple triple = it.next();
      Triple replacementTriple = null;
      final NonLiteral subject = triple.getSubject();
      NonLiteral subjectReplacement =
          current2ReplacementMap.get(subject);
      final Resource object = triple.getObject();
      @SuppressWarnings("element-type-mismatch")
View Full Code Here

  private static Set<UriRef> getIfps(TripleCollection tBox) {
    final Iterator<Triple> ifpDefinitions = tBox.filter(null, RDF.type,
        OWL.InverseFunctionalProperty);
    final Set<UriRef> ifps = new HashSet<UriRef>();
    while (ifpDefinitions.hasNext()) {
      final Triple triple = ifpDefinitions.next();
      ifps.add((UriRef) triple.getSubject());
    }
    return ifps;
  }
View Full Code Here

  @Test
  public void testGetSubjectAndObjectNodes() {
    RandomMGraph graph = new RandomMGraph(500, 20, new SimpleMGraph());
    for (int j = 0; j < 200; j++) {
      Triple randomTriple = graph.getRandomTriple();
      GraphNode node = new GraphNode(randomTriple.getSubject(), graph);
      Iterator<UriRef> properties = node.getProperties();
      while (properties.hasNext()) {
        UriRef property = properties.next();
        Set<Resource> objects = createSet(node.getObjects(property));
        Iterator<GraphNode> objectNodes = node.getObjectNodes(property);
        while (objectNodes.hasNext()) {
          GraphNode graphNode = objectNodes.next();
          Assert.assertTrue(objects.contains(graphNode.getNode()));
        }
      }
    }

    for (int j = 0; j < 200; j++) {
      Triple randomTriple = graph.getRandomTriple();
      GraphNode node = new GraphNode(randomTriple.getObject(), graph);
      Iterator<UriRef> properties = node.getProperties();
      while (properties.hasNext()) {
        UriRef property = properties.next();
        Set<Resource> subjects = createSet(node.getSubjects(property));
        Iterator<GraphNode> subjectNodes = node.getSubjectNodes(property);
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.