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

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


  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


  public void checkMenu() throws Exception {
    Assert.assertTrue(webServerExist);
    UserContextProvider contextProvider = (UserContextProvider)
        waitFor(UserContextProvider.class, 300000);
    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);
View Full Code Here

    LockableMGraph systemGraph = getSystemGraph();
    NonLiteral user = getUserByUserName(name);
    if (user != null) {
      GraphNode userNodeInSystemGraph =
          new GraphNode(getUserByUserName(name), systemGraph);
      MGraph copiedUserContext = new SimpleMGraph(userNodeInSystemGraph.getNodeContext());
      return new GraphNode(userNodeInSystemGraph.getNode(),
          copiedUserContext);
    } else {
      return null;
    }
View Full Code Here

  private static String REFERENCED_BUNDLE_NAME = "your.symbolic.name";

  @Test
  public void testMutator() {
    MGraph mGraph = new SimpleMGraph();
    UriRef uriRef = new UriRef(UriMutatorIterator.BASE_URI_PLACEHOLDER +
        REFERENCED_BUNDLE_NAME + "/bla#Test");
    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

    boolean freeConceptProviderFound = false;

    List<ConceptProvider> conceptProviderList = conceptProviderManager
        .getConceptProviders();

    MGraph resultMGraph = new SimpleMGraph();
    GraphNode resultNode = new GraphNode(new BNode(), resultMGraph);
    boolean first = true;
    for (ConceptProvider cp : conceptProviderList) {
      if (!freeConceptProviderFound) {
        if (cp instanceof LocalConceptProvider) {
View Full Code Here

    Assert.assertEquals(expectedTriple, it.next());   
  }

  @Test
  public void testMutatorNoSymbolicName() {
    MGraph mGraph = new SimpleMGraph();
    UriRef uriRef = new UriRef(UriMutatorIterator.BASE_URI_PLACEHOLDER +
        "/bla#Test");
    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

    Assert.assertEquals(expectedTriple, it.next());
  }

  @Test
  public void baseUriTransformation() {
    MGraph mGraph = new SimpleMGraph();
    String xml = "<a href=\"" + UriMutatorIterator.BASE_URI_PLACEHOLDER +
      REFERENCED_BUNDLE_NAME + "/bla\"/>";
    Literal literal = new TypedLiteralImpl(xml,
          UriMutatorIterator.XML_LITERAL);
    String expectedXml = "<a href=\"" + HOST +
      "bundle-doc/"+ REFERENCED_BUNDLE_NAME +"/bla\"/>";
    Literal expectedLiteral = new TypedLiteralImpl(expectedXml,
          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

    Assert.assertEquals(expectedTriple, it.next());
  }

  @Test
  public void baseUriTransformationNoSymbolicName() {
    MGraph mGraph = new SimpleMGraph();
    String xml = "<a href=\"" + UriMutatorIterator.BASE_URI_PLACEHOLDER +
      "/bla\"/>";
    Literal literal = new TypedLiteralImpl(xml,
          UriMutatorIterator.XML_LITERAL);
    String expectedXml = "<a href=\"" + HOST +
      "bundle-doc/"+ ORIGIN_BUNDLE_NAME +"/bla\"/>";
    Literal expectedLiteral = new TypedLiteralImpl(expectedXml,
          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

      }
      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);
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

TOP

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

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.