Package org.wymiwyg.rdf.graphs

Examples of org.wymiwyg.rdf.graphs.Node


    terminalMolecules = new HashSet<TerminalMolecule>();
    Map<Node, ContextualMoleculeImpl> contextualMoleculeMap = new HashMap<Node, ContextualMoleculeImpl>();

    for (Triple triple : remainingTriples) {
      Node subject = triple.getSubject();
      Node object = triple.getObject();
      if (fgNodesMap.containsKey(subject)) {
        subject = fgNodesMap.get(subject);
      }
      if (fgNodesMap.containsKey(object)) {
        object = fgNodesMap.get(object);
View Full Code Here


      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();
View Full Code Here

   */
  private Collection<Triple> extractNonTerminalTriples(
      Collection<Triple> triples) {
    Collection<Triple> result = new ArrayList<Triple>();
    for (Triple triple : triples) {
      Node groundedNode = getGroundedNode(triple);
      if (groundedNode == null) {
        result.add(triple);
      } else {
        addToGroundedNodes(groundedNode, triple);
      }
View Full Code Here

  private static void serializeMolecule(NonTerminalMolecule molecule,
      ArrayList<FunctionallyGroundedNode> visitedFgNodes,
      StringWriter writer) {
    Triple triple = molecule.iterator().next();
    Node groundingNode;
    if (triple.getSubject() != NonTerminalMolecule.GROUNDED_NODE) {
      writer.append('i');
      groundingNode = triple.getSubject();
    } else {
      groundingNode = triple.getObject();
    }
    writer.append('<');
    writer.append(triple.getPredicate().getURIRef());
    writer.append('>');
    writer.append(' ');
    if (groundingNode instanceof FunctionallyGroundedNode) {
      serialize((FunctionallyGroundedNode) groundingNode,
          visitedFgNodes, writer);
    } else {
      if (groundingNode instanceof LiteralNode) {
        try {
          appendLiteral(writer, (LiteralNode) groundingNode);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      } else {
        if (groundingNode instanceof NamedNode) {
          writer.append('<');
          writer.append(((NamedNode) groundingNode).getURIRef());
          writer.append('>');
        } else {
          // e.g. ModelGroundedNode
          writer.append('_');
          writer.append(groundingNode.toString());
          writer.append('_');
        }
      }
    }
  }
View Full Code Here

            .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,
View Full Code Here

  }

  private Set<Node> getUsedButNotGroundedNodeSet() {
    Set<Node> resultSet = new HashSet<Node>();
    for (Triple triple : this) {
      Node subject = triple.getSubject();
      if (!(subject instanceof GroundedNode)) {
        resultSet.add(subject);
      }
      Node object = triple.getObject();
      if (!(object instanceof GroundedNode)) {
        resultSet.add(object);
      }
    }
    return resultSet;
View Full Code Here

    this.afgn = afgn;
  }

  public boolean add(Triple triple) {
    boolean modified = false;
    Node subject = triple.getSubject();
    Node object = triple.getObject();
    if (subject.equals(afgn)) {
      subject = GROUNDED_NODE;
      modified = true;
    }
    if (object.equals(afgn)) {
      object = GROUNDED_NODE;
      modified = true;
    }
    if (modified) {
      return super.add(new TripleImpl(subject, triple.getPredicate(), object));
View Full Code Here

    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) {
View Full Code Here

   * @param fgNodesGraph the graph to which the triples resulting from fg-node naturalization are added
   */
  private void addGraphTriples(Graph graph, boolean addReferencedFgNodes, Naturalizer naturalizer, Map<Set<NonTerminalMolecule>, Node> replacementMap, Graph fgNodesGraph) {
    for (Iterator iter = graph.iterator(); iter.hasNext();) {
      Triple triple = (Triple) iter.next();
      Node subject = triple.getSubject();
      if (subject instanceof FunctionallyGroundedNode) {
        if (addReferencedFgNodes) {
          Node replacement = replacementMap.get(((FunctionallyGroundedNode) subject).getGroundingMolecules()); // (Node)fg2NormalNodeMap.get(object);
          if (replacement == null) {
            Set<NonTerminalMolecule> groundingMolecules = ((FunctionallyGroundedNode) subject).getGroundingMolecules();
            subject = addFgNodeMolecules((FunctionallyGroundedNode) subject, naturalizer, fgNodesGraph);
            replacementMap.put(groundingMolecules, subject);
          } else {
            subject = replacement;
          }
        } else {
          Node replacement = replacementMap.get(((FunctionallyGroundedNode) subject).getGroundingMolecules());
          if (replacement == null) {
            log.error("no replacement found for the fg-node: "+ subject);
            throw new RuntimeException("no replacement found for the fg-node: "+ subject);
          }
          subject = replacement;
        }
      } else {
        if (subject instanceof GroundedNode) {
          if (!(subject instanceof NaturallyGroundedNode)) {
            throw new RuntimeException("Cannot naturalize subject node of type "+subject.getClass());
          }
        }
      }
      Node object = triple.getObject();
      if (object instanceof FunctionallyGroundedNode) {
        if (addReferencedFgNodes) {
          Node replacement = replacementMap.get(((FunctionallyGroundedNode) object).getGroundingMolecules()); // (Node)fg2NormalNodeMap.get(object);
          if (replacement == null) {
            Set<NonTerminalMolecule> groundingMolecules = ((FunctionallyGroundedNode) object).getGroundingMolecules();
            object = addFgNodeMolecules((FunctionallyGroundedNode) object, naturalizer, fgNodesGraph);
            replacementMap.put(groundingMolecules, object);
          } else {
            object = replacement;
          }
         
        } else {
          Node replacement = (replacementMap).get(new HashSet<NonTerminalMolecule>(((FunctionallyGroundedNode) object).getGroundingMolecules())); // (Node)fg2NormalNodeMap.get(object);
          if (replacement == null) {
            throw new NoReplacementFoundException("no replacement found for the fg-node: "+ object, (FunctionallyGroundedNode) object);
          }
          object = replacement;
        }
View Full Code Here

      // TODO cannot finalize molecules
      M resultMolecule = factory.createMolecule();
      for (Triple currentTriple : currentMolecule) {
        // check if subject is mappable
        boolean modified = false;
        Node subject = currentTriple.getSubject();
        if (subject instanceof FunctionallyGroundedNode) {
          if (fgNodes2CrossGraphFgNodes
              .containsKey(((FunctionallyGroundedNode) subject))) {
            subject = fgNodes2CrossGraphFgNodes
                .get(((FunctionallyGroundedNode) subject));
            modified = true;
          } else {
            /*
             * commonFgNodesInDiffMolecules
             * .add((FunctionallyGroundedNode) subject);
             */
          }
        }
        Node object = currentTriple.getObject();
        if (object instanceof FunctionallyGroundedNode) {
          if (fgNodes2CrossGraphFgNodes
              .containsKey(((FunctionallyGroundedNode) object))) {
            object = fgNodes2CrossGraphFgNodes
                .get(((FunctionallyGroundedNode) object));
View Full Code Here

TOP

Related Classes of org.wymiwyg.rdf.graphs.Node

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.