Package org.wymiwyg.rdf.graphs

Examples of org.wymiwyg.rdf.graphs.Triple


   */
  private FunctionallyGroundedNode selectFGNodeWithProperty(
      Set<FunctionallyGroundedNode> fgNodes, PropertyNode property) {
    for (FunctionallyGroundedNode node : fgNodes) {
      for (NonTerminalMolecule molecule : node.getGroundingMolecules()) {
        Triple triple = molecule.iterator().next();
        if (triple.getPredicate().equals(property)) {
          return node;
        }
      }
    }
    return null;
View Full Code Here


   * @param resource
   */
  private static void deleteStatementsWith(Graph graph, Node resource) {
    Iterator stmtIter = graph.iterator();
      while (stmtIter.hasNext()) {
        Triple statement = (Triple) stmtIter.next();
        Node subject = statement.getSubject();
        if (resource.equals(subject)) {
          stmtIter.remove();
          continue;
        }
        Node object = statement.getObject();
        if (resource.equals(object)) {
          stmtIter.remove();
          continue;
        }

View Full Code Here

                      // contain n2;
    // for every statement in p2 with no other anonymous node than n2 check
    // if there is an identical statement in p1, otherwise add {n1, n2} to
    // knownNotImpying an return false;
    P2_ITER: for (Iterator<Triple> iterP2 = p2.iterator(); iterP2.hasNext();) {
      Triple currentP2 = iterP2.next();
      if (!containsNoOtherAnon(currentP2, n2)) {
        for (Iterator<Triple> iterP1 = p1.iterator(); iterP1.hasNext();) {
          Triple currentP1 = iterP1.next();
          Triple currentP1Replaced = replaceInStmt(currentP1, n1,
              n2);
          if (currentP1Replaced.equals(currentP2)) {
            iterP2.remove();
            continue P2_ITER;
          }
        }
        knownNotImplying.add(currentPair);
        return false;
      }
    }
    history1.add(n1);
    history2.add(n2);
    // for every other statement (n2, p, o2) or (o2, p, n2) in p2 check if
    // there is a statement (n1, p, o1) respectively (o1, p, n1) in p1 with
    // the same predicate and for which implies(o1, o2,
    // history1.clone(),history2.clone(), knownNotImplying,
    // conditionalImplications) is true, otherwise add {n1, n2} to
    // knownNotImpying an return false;

    // first round: just check direction and property-type, add checkPairs
    // to
    // will fail if for any entry of the set, all pairs in the contained set do not matchs
    Set<Set<Node[]>> checkingSets = new HashSet<Set<Node[]>>();
   
    P2_ITER: for (Iterator<Triple> iterP2 = p2.iterator(); iterP2.hasNext();) {
      Triple currentP2 = iterP2.next();;
      boolean forwardP2 = currentP2.getSubject().equals(n2);
      Set<Node[]> pairsToCheck = new HashSet<Node[]>();
      for (Iterator<Triple> iterP1 = p1.iterator(); iterP1.hasNext();) {
        Triple currentP1 = iterP1.next();
        boolean forwardP1 = currentP1.getSubject().equals(n1);
        if ((forwardP1 == forwardP2)
            && currentP1.getPredicate().equals(
                currentP2.getPredicate())) {
          Node[] currentPairToCheck = new Node[2];
          if (forwardP1) {
            currentPairToCheck[0] = currentP1.getObject();
            currentPairToCheck[1] = currentP2.getObject();
          } else {
            currentPairToCheck[0] = currentP1.getSubject();
            currentPairToCheck[1] = currentP2.getSubject();
          }
          //Fixing: if p1 contains multiple statements with same property and direction this may not be the right match
          pairsToCheck.add(currentPairToCheck);
        }
View Full Code Here

   */
  private static Set<Triple> getPropertySet(Graph graph, Node node) {
    Set<Triple> result = new HashSet<Triple>();
    Iterator stmtIter = graph.iterator();
      while (stmtIter.hasNext()) {
        Triple statement = (Triple) stmtIter.next();
        Node subject = statement.getSubject();
        if ((node.hashCode() == subject.hashCode()) && subject.equals(node)) {
          result.add(statement);
          continue;
        }
        Node object = statement.getObject();
        if ((node.hashCode() == object.hashCode()) && object.equals(node)) {
          result.add(statement);
        }

      }
View Full Code Here

   */
  private static Node geNewCandidateImplicated(Graph graph, Set<Node> exclude,
      Node currentCandidateImplicator) {
    Iterator stmtIter = graph.iterator();
    while (stmtIter.hasNext()) {
      Triple statement = (Triple) stmtIter.next();
      Node subject = statement.getSubject();
      if ((!(subject instanceof GroundedNode))
          && !exclude.contains(subject)
          && !subject.equals(currentCandidateImplicator)) {
        return subject;
      }
      Node object = statement.getObject();
      if ((!(object instanceof GroundedNode))
          && !exclude.contains(object)
          && !object.equals(currentCandidateImplicator)) {
        return object;
      }
View Full Code Here

   * @return
   */
  private static Node getNewCandidateImplicator(Graph graph, Set<Node> exclude) {
    Iterator stmtIter = graph.iterator();
    while (stmtIter.hasNext()) {
      Triple statement = (Triple) stmtIter.next();
      Node subject = statement.getSubject();
      if (!exclude.contains(subject)) {
        return subject;
      }
      Node object = statement.getObject();
      if (!exclude.contains(object)) {
        return object;
      }

    }
View Full Code Here

   */
private static void addGraphToModel(Graph graph, Model model) {
    AnonymousMapper mapper = new AnonymousMapper(model);
    // int i = 0;
    for (Iterator iter = graph.iterator(); iter.hasNext();) {
      Triple currentTriple = (Triple) iter.next();
      Node subject = currentTriple.getSubject();
      Resource targetSubject;
      if (subject instanceof NamedNode) {
        targetSubject = model.createResource(((NamedNode)subject).getURIRef());
      } else {
        targetSubject  = mapper.getResource(subject);
      }
      Property targetPredicate = model.createProperty(currentTriple.getPredicate().getURIRef());
      Node object = currentTriple.getObject();
      RDFNode targetObject;
      if (object instanceof GroundedNode) {
        if (object instanceof TypedLiteralNode) {
          TypedLiteralNode literal = (TypedLiteralNode)object;
          targetObject = model.createTypedLiteral(literal.getLexicalForm(),  TypeMapper.getInstance().getSafeTypeByName(literal.getDataType().toString()));
View Full Code Here

    return map;
  }

  public static boolean isValidMapping(Map<Node, Node> mapping, Graph g1, Graph g2) {
    for (Iterator iter = g1.iterator(); iter.hasNext();) {
      Triple triple = (Triple) iter.next();
      Node subject = triple.getSubject();
      PropertyNode predicate = triple.getPredicate();
      Node object = triple.getObject();
      if (!(subject instanceof GroundedNode)) {
        subject = mapping.get(subject);
      }
      if (!(object instanceof GroundedNode)) {
        object = mapping.get(object);
      }
      Triple mappedTriple = new TripleImpl(subject, predicate, object);
      if (!g2.contains(mappedTriple)) {
        return false;
      }
    }
    return true;
View Full Code Here

  }

  public static Graph applyMapping(Graph graph, Map mapping) {
    SimpleGraph result = new SimpleGraph();
    for (Iterator iter = graph.iterator(); iter.hasNext();) {
      Triple triple = (Triple) iter.next();
      Node subject = triple.getSubject();
      PropertyNode predicate = triple.getPredicate();
      Node object = triple.getObject();
      if (!(subject instanceof GroundedNode)) {
        subject = (Node) mapping.get(subject);
      }
      if (!(object instanceof GroundedNode)) {
        object = (Node) mapping.get(object);
      }
      Triple mappedTriple = new TripleImpl(subject, predicate, object);
      result.add(mappedTriple);
    }
    result.markFinalized();
    return result;
  }
View Full Code Here

  private List<ContextNode> nodes;

  ContextGraph(Graph base) {
    Map<Node,ContextNode> map = new HashMap<Node,ContextNode>();
    for (Iterator iter = base.iterator(); iter.hasNext();) {
      Triple triple = (Triple) iter.next();
      Node subject = triple.getSubject();
      boolean subjectUbngn = !(subject instanceof GroundedNode);
      Node object = triple.getObject();
      boolean objectUbngn = !(object instanceof GroundedNode);
      ContextNode subjectContextNode = null;
      if (subjectUbngn) {
       
        subjectContextNode = map.get(subject);
        if (subjectContextNode == null) {
          subjectContextNode = new ContextNode(subject);
          map.put(subject, subjectContextNode);
        }
       
        subject = subjectContextNode;
      }
      ContextNode objectContextNode = null;
      if (objectUbngn) {
       
        objectContextNode = map.get(object);
        if (objectContextNode == null) {
          objectContextNode = new ContextNode(object);
          map.put(object, objectContextNode);
        }
        //contextNode.addUsage(triple, subjectUbngn);
        object = objectContextNode;
      }
      if (subjectUbngn || objectUbngn) {
        triple = new TripleImpl(subject, triple.getPredicate(),
            object);
        statements.add(triple);
        if (subjectUbngn) {
          subjectContextNode.addUsage(triple, objectUbngn);
        }
View Full Code Here

TOP

Related Classes of org.wymiwyg.rdf.graphs.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.