Examples of FunctionallyGroundedNodeImpl


Examples of org.wymiwyg.rdf.graphs.fgnodes.impl.FunctionallyGroundedNodeImpl

    };
  }

  private FunctionallyGroundedNode functionalyze(FunctionallyGroundedNode node) {
    FunctionallyGroundedNodeImpl result = new FunctionallyGroundedNodeImpl();
    for (NonTerminalMolecule molecule : node.getGroundingMolecules()) {
      result.addMolecule(functionalyze(molecule));
    }
    result.markFinalized();
    return result;
  }
View Full Code Here

Examples of org.wymiwyg.rdf.graphs.fgnodes.impl.FunctionallyGroundedNodeImpl

      }
    }
  }

  private FunctionallyGroundedNode functionalyze(NamedNode node) {
    FunctionallyGroundedNodeImpl result = new FunctionallyGroundedNodeImpl();
    Node afgn = new NodeImpl();
    SimpleNonTerminalMolecule molecule = new SimpleNonTerminalMolecule(afgn);
    String uriString = node.getURIRef();
    LiteralNode uriLit = new TypedLiteralNodeImpl(uriString, anyURIDataType);
    Triple triple = new TripleImpl(afgn, nameProp, uriLit);
    molecule.add(triple);
    molecule.markFinalized();
    result.addMolecule(molecule);
    result.markFinalized();
    result.notifyAllFinalized();
    return result;
  }
View Full Code Here

Examples of org.wymiwyg.rdf.graphs.fgnodes.impl.FunctionallyGroundedNodeImpl

  }
 
  private FunctionallyGroundedNode getFgNodeFromPathNode(ZipFile zipFile,
      PathNode pathNode, NamedNode describingResource) throws IOException {
    Node afgn = null;
    FunctionallyGroundedNodeImpl result = functionallyGroundedBuilder.createFGNode();
    descriptionPathToFgNode.put(describingResource, result);
    for (String moleculeNodeName : pathNode.list()) {
      PathNode moleculePathNode = pathNode.getSubPath(moleculeNodeName);
      Model model = ModelFactory.createDefaultModel();
      model
          .read(moleculePathNode.getInputStream(),
              ReferencingNaturalizer.rootURL
                  + moleculePathNode.getPath());
      /*
       * StmtIterator specialStmtIter = model.listStatements(null,
       * MODELDIFF.functionallyGroundedIn, (Resource)null); Statement
       * 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 {
        tripleSet = replaceNode(currentAfgn, afgn, tripleSet);
      }
      for (Entry<Node, FunctionallyGroundedNode> entry : innerReplacements.entrySet()) {
        tripleSet = replaceNode(entry.getKey(), entry.getValue(), tripleSet);
      }
      NonTerminalMolecule ntMolecule = functionallyGroundedBuilder.createNTMolecule(afgn);
      ntMolecule.addAll(tripleSet);
      result.addMolecule(ntMolecule);
    }
   
    return result;
  }
View Full Code Here

Examples of org.wymiwyg.rdf.molecules.impl.FunctionallyGroundedNodeImpl

    Collection<Finalizable> finalizableObjects = new ArrayList<Finalizable>();
    Map<Node, FunctionallyGroundedNodeImpl> resultMap = new HashMap<Node, FunctionallyGroundedNodeImpl>(
        groundeNodeMap.size());
    Iterator<Node> nodeIter = groundeNodeMap.keySet().iterator();
    while (nodeIter.hasNext()) {
      FunctionallyGroundedNodeImpl functionallyGroundedNodeImpl = new FunctionallyGroundedNodeImpl();
      resultMap.put(nodeIter.next(), functionallyGroundedNodeImpl);
      finalizableObjects.add((Finalizable) functionallyGroundedNodeImpl);
    }
    Iterator<Entry<Node, Set<Triple>>> entryIter = groundeNodeMap.entrySet().iterator();
    while (entryIter.hasNext()) {
      final Entry<Node, Set<Triple>> entry = entryIter.next();
      final Node groundedNode = entry.getKey();
      FunctionallyGroundedNodeImpl functionallyGroundedNodeImpl = resultMap.get(groundedNode);
      Set<Triple> groundingTriples = entry.getValue();
      Iterator<Triple> iterator = groundingTriples.iterator();
      while (iterator.hasNext()) {
        Triple triple = iterator.next();
        NonTerminalMoleculeImpl nonTerminalMolecule = new NonTerminalMoleculeImpl(
            groundedNode, triple, resultMap);
        functionallyGroundedNodeImpl.addGroundingMolecule(nonTerminalMolecule);
        finalizableObjects.add((Finalizable) nonTerminalMolecule);
      }
    }
    for (Finalizable finalizable : finalizableObjects) {
      finalizable.markFinalized();
View Full Code Here

Examples of org.wymiwyg.rdf.molecules.impl.FunctionallyGroundedNodeImpl

          ntMolecules.add(ntMolecule);
        }

        keys.addAll(nodes2Keys.remove(nodeInGroup));
      }
      FunctionallyGroundedNodeImpl newNode = new FunctionallyGroundedNodeImpl(
          ntMolecules);
      newNodes.add(newNode);
      nodes2Keys.put(newNode, keys);
      for (FunctionallyGroundedNode nodeInGroup : group) {
        old2NewMap.put(nodeInGroup, newNode);
      }

    }



    // replace member of the group occuring in nt-molecules of any fg-node
    // with the new node,
    // this involves replacing original-fg-nodes which unfinalised ones,
    // where this
    // occurs node2Keys and recursively the other nodes are updated
    // for all nodes
    Collection<NonTerminalMoleculeImpl> newNtMolecules = new ArrayList<NonTerminalMoleculeImpl>();
    Map<FunctionallyGroundedNode, Set<T>> resultNodes2Keys = nodes2Keys;
    while (true) {
      Map<FunctionallyGroundedNode, FunctionallyGroundedNode> newOld2NewMap = new HashMap<FunctionallyGroundedNode, FunctionallyGroundedNode>();
      Map<FunctionallyGroundedNode, Set<T>> newNodes2Keys = new HashMap<FunctionallyGroundedNode, Set<T>>();
      for (FunctionallyGroundedNode node : resultNodes2Keys.keySet()) {
        // we add the replacement and the untouched nodes to a
        // newNodes2keySet
        // if newNodes contains a key we modify it
        // if we create a new key it is added to newOld2NewMap
        boolean moleculeReplaced = false;
        Set<NonTerminalMolecule> moleculesOfNewNode = new HashSet<NonTerminalMolecule>();
        for (NonTerminalMolecule molecule : node
            .getGroundingMolecules()) {
          NonTerminalMoleculeImpl replacementMolecule = null;
          Triple triple = molecule.iterator().next(); // nt-molecules
          // have exactly
          // one element
          Node subject = triple.getSubject();
          if (subject != NonTerminalMolecule.GROUNDED_NODE) {
            Node replacementSubject = old2NewMap.get(subject);
            if (replacementSubject != null) {
              replacementMolecule = new NonTerminalMoleculeImpl(
                  new TripleImpl(replacementSubject, triple
                      .getPredicate(),
                      NonTerminalMolecule.GROUNDED_NODE));
            }
          } else {
            Node replacementObject = old2NewMap.get(triple
                .getObject());
            if (replacementObject != null) {
              replacementMolecule = new NonTerminalMoleculeImpl(
                  new TripleImpl(
                      NonTerminalMolecule.GROUNDED_NODE,
                      triple.getPredicate(),
                      replacementObject));
            }

          }
          if (replacementMolecule != null) {
            moleculeReplaced = true;
            moleculesOfNewNode.add(replacementMolecule);
            newNtMolecules.add(replacementMolecule);
          } else {
            moleculesOfNewNode.add(molecule);
          }
        }
        Set<T> keys = resultNodes2Keys.get(node);
        if (newNodes.contains(node)) {
          ((FunctionallyGroundedNodeImpl) node)
              .setMolecules(moleculesOfNewNode);
          newNodes2Keys.put(node, keys);
        } else {
          if (moleculeReplaced) {
            FunctionallyGroundedNodeImpl newNode = new FunctionallyGroundedNodeImpl(
                moleculesOfNewNode);
            newNodes.add(newNode);
            newOld2NewMap.put(node, newNode);
            // Set<T> keys = nodes2Keys.remove(node);
            newNodes2Keys.put(newNode, keys);
          } else {
            newNodes2Keys.put(node, keys);
          }
        }
      }
      old2NewMap = newOld2NewMap;
      resultNodes2Keys = newNodes2Keys;
      if (old2NewMap.size() == 0) {
        break;
      }
    }

    // at the end we finalize our nodes and molecules
    for (FunctionallyGroundedNodeImpl newNode : newNodes)
      newNode.markFinalized();
    for (NonTerminalMoleculeImpl newMol : newNtMolecules)
      newMol.markFinalized();

   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.