Package org.wymiwyg.rdf.graphs.impl

Examples of org.wymiwyg.rdf.graphs.impl.SimpleGraph


   * @param addReferencedFgNodes if false an exception is thrown if graph contians an fg-node which is not in fgNodes
   */
  public NaturalizedGraph(Graph graph,
      Collection<FunctionallyGroundedNode> fgNodes, boolean addReferencedFgNodes) {
    Map<Set<NonTerminalMolecule>, Node> replacementMap = new HashMap<Set<NonTerminalMolecule>, Node>();
    Graph fgNodesGraph = new SimpleGraph();
    for (Iterator<FunctionallyGroundedNode> iter = fgNodes.iterator(); iter
        .hasNext();) {
      FunctionallyGroundedNode fgNode = iter.next();
      // fg2NormalNodeMap.put(fgNode, fgNode.getOriginalNode());
      Node replacementNode = addFgNodeMolecules(fgNode, new DefaultNaturalizer(), fgNodesGraph);
      //rehashing necessary as long unfinalized nodes come
      replacementMap.put(new HashSet<NonTerminalMolecule>(fgNode.getGroundingMolecules()), replacementNode);
    }
    Naturalizer naturalizer;
    if (addReferencedFgNodes) {
      naturalizer = new DefaultNaturalizer();
    } else {
      naturalizer = null;
    }
    addGraphTriples(graph, addReferencedFgNodes, naturalizer, replacementMap, fgNodesGraph);
    while (fgNodesGraph.size() > 0) {
      //add the triples of the fg-nodes graph and repeat if new triples result from fg-nodes replacemnets
      //withing these triples
      Graph addingFgNodesGraph = fgNodesGraph;
      fgNodesGraph = new SimpleGraph();
      addGraphTriples(addingFgNodesGraph, addReferencedFgNodes, naturalizer, replacementMap, fgNodesGraph);
    }
    markFinalized();
  }
View Full Code Here


    PathNode moleculePathNode = dirPathNode.getSubPath(name);
    Model model = ModelFactory.createDefaultModel();
    model.read(moleculePathNode.getInputStream(),
        ReferencingNaturalizer.rootURL + moleculePathNode.getPath());
    Graph graph = JenaUtil.getGraphFromModel(model, false);
    SimpleGraph simpleGraph = new SimpleGraph();
    //Collection<Node> origFgNodes = new HashSet<Node>();
    Map<Node, NamedNode> node2descriptionDocMap = new HashMap<Node, NamedNode>();
    //NamedNode descriptionDoc = null;
    for (Triple triple : graph) {
      if (triple.getPredicate().equals(
          new PropertyNodeImpl(MODELDIFF.functionallyGroundedIn
              .getURI()))) {
        NamedNode descriptionDoc  = (NamedNode) triple.getObject();
        node2descriptionDocMap.put(triple.getSubject(), descriptionDoc);
      } else {
        simpleGraph.add(triple);
      }
    }
    simpleGraph.markFinalized();
    SimpleGraph tripleSet = simpleGraph;
    for (Entry<Node, NamedNode> entry : node2descriptionDocMap.entrySet()) {
      tripleSet = replaceNode(entry.getKey(), descriptionPathToFgNode
          .get(entry.getValue()), tripleSet);
      tripleSet.markFinalized();
    }
    return tripleSet;
  }
View Full Code Here

       * specialStmt = specialStmtIter.nextStatement();
       * specialStmtIter.close(); Resource groundedNodedRes =
       * specialStmt.getSubject(); specialStmt.remove();
       */
      Graph graph = JenaUtil.getGraphFromModel(model, false);
      Graph tripleSet = new SimpleGraph();
      Node currentAfgn = null;
      Map<Node, FunctionallyGroundedNode> innerReplacements = new HashMap<Node, FunctionallyGroundedNode>();
      for (Triple triple : graph) {
        if (triple.getPredicate().equals(
            new PropertyNodeImpl(MODELDIFF.functionallyGroundedIn
                .getURI()))) {
          Node subject = triple.getSubject();
          if (!describingResource.equals(triple.getObject())) {
            // throw new RuntimeException("invalid diff");
            // now legal as fg-nodes may reference to others in
            // their nt-molecules
            //infinite recursion by cache
            FunctionallyGroundedNode replacement = getFgNodeFromDescribingNode(zipFile,
                (NamedNode) triple.getObject());
            innerReplacements.put(subject, replacement);
           
          } else {
            currentAfgn = subject;
          }
        } else {
          tripleSet.add(triple);
        }
      }
      if (afgn == null) {
        afgn = currentAfgn;
      } else {
View Full Code Here

   * @param tripleSet
   */
  private <T extends Collection<? extends Triple>> SimpleGraph replaceNode(
      Node currentAfgn, Node afgn, T tripleSet) {
    try {
      return new GraphUtil<SimpleGraph>().replaceNode(tripleSet, currentAfgn, afgn, new SimpleGraph());
    } catch (SourceNodeNotFoundException e) {
      SimpleGraph result = new SimpleGraph();
      result.addAll(tripleSet);
     
      return result;
    }
    /*
     * Set<Triple> result = new HashSet<Triple>(); for (Triple triple :
View Full Code Here

      log.debug("Anonymized graph: ");
      log.debug(stringWriter);
    }
    ReferenceGroundedDecomposition refDec = new ReferenceGroundedDecompositionImpl(graph);
    ReferenceGroundedDecomposition leanifiedDec = getLeanVersionWithoutAnonymizing(refDec);
    Graph nonNaturalGraph = new SimpleGraph();
    for (Iterator<MaximumContextualMolecule> iter = leanifiedDec
        .getContextualMolecules().iterator(); iter.hasNext();) {
      nonNaturalGraph.addAll(iter.next());
    }
    for (Iterator<TerminalMolecule> iter = leanifiedDec.getTerminalMolecules()
        .iterator(); iter.hasNext();) {
      nonNaturalGraph.addAll(iter.next());
    }

    try {
      SimpleGraph result = new NaturalizedGraph(nonNaturalGraph, leanifiedDec
          .getFunctionallyGroundedNodes());
      result.markFinalized();
      /*System.out.println("DEBUG not anonymized:");
      JenaUtil.getModelFromGraph(result).write(System.out, "N3");*/
      return result;
    } catch (NoReplacementFoundException ex) {
      log.error(ex.toString());
View Full Code Here

      for (Iterator<MaximumContextualMolecule> iter = contextualMolecules
          .iterator(); iter.hasNext();) {
        MaximumContextualMolecule current = (MaximumContextualMolecule) iter
            .next();
        // test, why does it takes sooo much longer with molecule?
        SimpleGraph currentGraph = new SimpleGraph();
        currentGraph.addAll(current);
        GraphLeanifier.makeLean(currentGraph);
        currentGraph.markFinalized();
        leanifiedMolecules.add(currentGraph);
      }
      contextualMolecules = new HashSet<MaximumContextualMolecule>();
      for (Iterator<Graph> iter = leanifiedMolecules.iterator(); iter
          .hasNext();) {
View Full Code Here

   * @param graph
   * @return
   */
  private static Graph getLabelableGraph(Graph graph) {
    Map<Node, LabelableNode> nodeMap = new HashMap<Node, LabelableNode>();
    Graph labelableGraph = new SimpleGraph();
    for (Triple triple : graph) {
      labelableGraph.add(getLabelableTriple(triple, nodeMap));
    }
    return labelableGraph;
  }
View Full Code Here

      return getNextSubGraph();
    }

    private Graph getNextSubGraph() {
      int count = 0;
      Graph currentGraph = new SimpleGraph();
      for (TripleInfo info : tripleInfos) {
        switch (info.status) {
        case undefined:
          if (count < omitUndefined) {
            count++;
            break;
          } else {
            currentGraph.add(info.triple);
          }
          ;
          break;
        case needed:
          currentGraph.add(info.triple);
        }
      }
      if (count == 0) {
        return null;
      }
      System.out.println("returning subgraph of size "
          + currentGraph.size());
      return currentGraph;
    }
View Full Code Here

        StringBuffer moleculePath = new StringBuffer(relativePath);
        moleculePath.append(Util.createRandomString(8));
        moleculePath.append(".rdf");
        ZipEntry entry = new ZipEntry(moleculePath.toString());
        zipOut.putNextEntry(entry);
        Graph graph = new SimpleGraph();
        Node naturalNode = naturalizer.naturalize(fgNode, graph);
        Graph addition;
        try {
          addition = new GraphUtil<Graph>().replaceNode(molecule,
              fgNode, naturalNode, new SimpleGraph());
        } catch (SourceNodeNotFoundException e) {
          // this is in fact the normal case of non-self-referencing
          // fg-nodes (x mbox [mbox "foo"]. x mbox "foo")
          addition = molecule;
        }
        try {
          addition = new GraphUtil<Graph>().replaceNode(addition,
              NonTerminalMolecule.GROUNDED_NODE, naturalNode,
              new SimpleGraph());
        } catch (SourceNodeNotFoundException e) {
          // this is a bit strange ...
          throw new RuntimeException(e);
        }
        graph.addAll(addition);
        /*
         * graph.addAll(molecule); graph.add(new
         * TripleImp(naturalizer.naturalize(fgNode, null), new
         * PropertyNodeImpl(MODELDIFF.functionallyGroundedIn .getURI()),
         * namedNode));
 
View Full Code Here

*/
public class FgNodeMergerTest {

  @Test
  public void simple() {
    SimpleGraph graph = new SimpleGraph();
    Node nanmedNode = new NamedNodeImpl("http://1.example.org/");
    graph.add(new TripleImpl(new NodeImpl(),
        new InverseFunctionalPropertyNodeImpl(
            "http://example.org/functional"), nanmedNode));
    Node fg2 = new NodeImpl();
    graph.add(new TripleImpl(fg2, new InverseFunctionalPropertyNodeImpl(
        "http://example.org/functional"), nanmedNode));
    graph.add(new TripleImpl(fg2, new InverseFunctionalPropertyNodeImpl(
        "http://example.org/f2"), new NamedNodeImpl(
        "http://2.example.org/")));
    ReferenceGroundedDecomposition dec = new ReferenceGroundedDecompositionImpl(
        graph);
    Set<FunctionallyGroundedNode> functionallyGroundedNodes = dec
View Full Code Here

TOP

Related Classes of org.wymiwyg.rdf.graphs.impl.SimpleGraph

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.