Example #1
0
  public static Graph getGraph() {

    Graph g = Factory.createGraphMem();

    g.add(
        new Triple(
            NodeFactory.createURI("http://example.com/subject"),
            NodeFactory.createURI("http://example.com/predicate"),
            NodeFactory.createURI("http://example.com/object")));

    g.add(
        new Triple(
            NodeFactory.createBlankNode(BlankNodeId.create("a")),
            NodeFactory.createURI("http://example.com/p1"),
            NodeFactory.createBlankNode(BlankNodeId.create("b"))));

    g.add(
        new Triple(
            NodeFactory.createBlankNode(BlankNodeId.create("b")),
            NodeFactory.createURI("http://example.com/p2"),
            NodeFactory.createLiteral("foo")));

    g.add(
        new Triple(
            NodeFactory.createURI("http://example.com/ns/e"),
            NodeFactory.createURI("http://example.com/ns/p5"),
            NodeFactory.createLiteral("verify base works")));

    return g;
  }
Example #2
0
 @Test
 public void testGraph() throws Exception {
   Graph graph = new PeopleGraphImpl().graphFor(1);
   graph.add(new PersonImpl(1, "Zequinha", 10.0));
   graph.add(new PersonImpl(2, "Barbosa", 20.0));
   List<Person> closest = graph.getClosestFriends(5);
   assertEquals(2, closest.size());
 }
 @Test
 public void graphWithTwoNodesAndTwoNeighbours() throws Exception {
   Node node = new Node("1");
   node.addNeighbour(new Node("3"));
   Node node2 = new Node("2");
   node2.addNeighbour(new Node("4"));
   graph.add(node);
   graph.add(node2);
   assertEquals("1 3\n2 4\n", serializeGraph());
 }
Example #4
0
 /** Check that the standard reifier will note, but not hide, reification quads. */
 public void testStandard() {
   Graph g = getGraph();
   assertFalse(ReifierStd.hasTriple(g, triple("s p o")));
   g.add(NodeCreateUtils.createTriple("x rdf:subject s"));
   assertEquals(1, g.size());
   g.add(NodeCreateUtils.createTriple("x rdf:predicate p"));
   assertEquals(2, g.size());
   g.add(NodeCreateUtils.createTriple("x rdf:object o"));
   assertEquals(3, g.size());
   g.add(NodeCreateUtils.createTriple("x rdf:type rdf:Statement"));
   assertEquals(4, g.size());
   assertTrue(ReifierStd.hasTriple(g, triple("s p o")));
 }
  private void getNewNodes() {
    Vector levelNodes = new Vector();
    Vector nextLevelNodes = new Vector();
    Vector passedNodes = new Vector();
    levelNodes.add(centerNode.name);
    for (int level = 0; level <= Config.navigationDepth; level++) {
      for (Enumeration e = levelNodes.elements(); e.hasMoreElements(); ) {
        String nodeName = (String) e.nextElement();

        if (!passedNodes.contains(nodeName)) {
          passedNodes.add(nodeName);

          Node node = graph.nodeFromName(nodeName);
          if (node == null) {
            node = xmlReader.getNode(nodeName);
            graph.add(node);
          }
          node.passed = true;

          Set linkSet = node.links.keySet();
          for (Iterator it = linkSet.iterator(); it.hasNext(); ) {
            String neighbourName = (String) it.next();
            if (!passedNodes.contains(neighbourName) && !levelNodes.contains(neighbourName)) {
              nextLevelNodes.add(neighbourName);
            }
          }
        }
      }
      levelNodes = nextLevelNodes;
      nextLevelNodes = new Vector();
    }
  }
Example #6
0
  public static void main(String[] args) throws FileNotFoundException {
    Scanner file = new Scanner(new File("connected.txt"));
    for (int i = 0; i < 3; i++) {
      file.next();
    }
    int totalVector = Integer.parseInt(file.next());
    Graph graph = new Graph(totalVector);
    System.out.println(totalVector);
    while (file.hasNext()) {
      String s = file.next();
      char s1 = s.charAt(1);
      char s2 = s.charAt(3);
      Vertex v1 = new Vertex(s1);
      Vertex v2 = new Vertex(s2);

      String c = file.next();
      char cArray[] = c.toCharArray();
      char ccArray[] = new char[cArray.length - 2];
      for (int i = 1; i < cArray.length - 1; i++) {
        ccArray[i - 1] = cArray[i];
      }
      int cost = Integer.parseInt(String.valueOf(ccArray));
      graph.add(v1, v2, cost);
    }
    file.close();
    graph.printData();
    graph.DFTraversal(graph, graph.headvertex);
    graph.miniumSpanningTree(graph);
  }
 @Test
 public void graphWithOneNodeAndOneNeighbourReturnsNodeAndNeighbour() throws Exception {
   Node node = new Node("1");
   node.addNeighbour(new Node("2"));
   graph.add(node);
   assertEquals("1 2\n", serializeGraph());
 }
Example #8
0
 public void testQuadRemove() {
   Graph g = getGraph();
   assertEquals(0, g.size());
   Triple s = NodeCreateUtils.createTriple("x rdf:subject s");
   Triple p = NodeCreateUtils.createTriple("x rdf:predicate p");
   Triple o = NodeCreateUtils.createTriple("x rdf:object o");
   Triple t = NodeCreateUtils.createTriple("x rdf:type rdf:Statement");
   g.add(s);
   g.add(p);
   g.add(o);
   g.add(t);
   assertEquals(4, g.size());
   g.delete(s);
   g.delete(p);
   g.delete(o);
   g.delete(t);
   assertEquals(0, g.size());
 }
 public void extractInto(Node root) {
   active.add(root);
   Iterator<Triple> it = extractFrom.find(root, Node.ANY, Node.ANY);
   while (it.hasNext()) {
     Triple t = it.next();
     Node subRoot = t.getObject();
     toUpdate.add(t);
     if (!(active.contains(subRoot) || b.stopAt(t))) extractInto(subRoot);
   }
 }
Example #10
0
 public void testKevinCaseB() {
   Graph G = getGraph();
   Node X = node("x"), Y = node("y");
   Node a = node("a"), b = node("b"), c = node("c");
   G.add(Triple.create(X, RDF.Nodes.subject, Y));
   try {
     ReifierStd.reifyAs(G, X, Triple.create(a, b, c));
     fail("X already has subject Y: cannot make it a");
   } catch (CannotReifyException e) {
     pass();
   }
 }
Example #11
0
  /**
   * Adds the given triple to the graph.
   *
   * @param subject The subject node
   * @param predicate The predicate node
   * @param object The object node
   * @param graph The graph we are adding the triple to
   * @throws MetaDataException
   */
  public static void addTriple(Node subject, Node predicate, Node object, Graph graph)
      throws MetaDataException {

    try {

      // Add the type triple
      graph.add((SubjectNode) subject, (PredicateNode) predicate, (ObjectNode) object);
    } catch (GraphException graphException) {

      throw new MetaDataException(
          "Failed to add triple for predicate: " + predicate, graphException);
    }
  }
Example #12
0
    /**
     * Update the triangulation by removing the cavity triangles and then filling the cavity with
     * new triangles.
     *
     * @param site the site that created the cavity
     * @param cavity the triangles with site in their circumcircle
     * @return one of the new triangles
     */
    private Triangle update(Pnt site, Set<Triangle> cavity) {
      Set<Set<Pnt>> boundary = new HashSet<Set<Pnt>>();
      Set<Triangle> theTriangles = new HashSet<Triangle>();

      // Find boundary facets and adjacent triangles
      for (Triangle triangle : cavity) {
        theTriangles.addAll(neighbors(triangle));
        for (Pnt vertex : triangle) {
          Set<Pnt> facet = triangle.facetOpposite(vertex);
          if (boundary.contains(facet)) boundary.remove(facet);
          else boundary.add(facet);
        }
      }
      theTriangles.removeAll(cavity); // Adj triangles only

      // Remove the cavity triangles from the triangulation
      for (Triangle triangle : cavity) triGraph.remove(triangle);

      // Build each new triangle and add it to the
      // triangulation
      Set<Triangle> newTriangles = new HashSet<Triangle>();
      for (Set<Pnt> vertices : boundary) {
        vertices.add(site);
        Triangle tri = new Triangle(vertices);
        triGraph.add(tri);
        newTriangles.add(tri);
      }

      // Update the graph links for each new triangle
      theTriangles.addAll(newTriangles); // Adj triangle + new
      // triangles
      for (Triangle triangle : newTriangles)
        for (Triangle other : theTriangles)
          if (triangle.isNeighbor(other)) triGraph.add(triangle, other);

      // Return one of the new triangles
      return newTriangles.iterator().next();
    }
 /**
  * Adds a set of precomputed triples to the deductions store. These do not, themselves, fire any
  * rules but provide additional axioms that might enable future rule firing when real data is
  * added. Used to implement bindSchema processing in the parent Reasoner.
  *
  * @return return true if the rule set has also been loaded
  */
 protected boolean preloadDeductions(Graph preloadIn) {
   Graph d = fdeductions.getGraph();
   BasicForwardRuleInfGraph preload = (BasicForwardRuleInfGraph) preloadIn;
   // If the rule set is the same we can reuse those as well
   if (preload.rules == rules) {
     // Load raw deductions
     for (Iterator<Triple> i = preload.find(null, null, null); i.hasNext(); ) {
       d.add(i.next());
     }
     engine.setRuleStore(preload.engine.getRuleStore());
     return true;
   } else {
     return false;
   }
 }
 @Override
 protected Boolean processMethod() throws AsyncException {
   Graph d = fdeductions.getGraph();
   BasicForwardRuleInfGraph preload = (BasicForwardRuleInfGraph) preloadIn;
   // If the rule set is the same we can reuse those as well
   if (preload.rules == rules) {
     // Load raw deductions
     for (Iterator<Triple> i = preload.find(getHandler(""), null, null, null); i.hasNext(); ) {
       d.add(getHandler(""), i.next());
     }
     engine.setRuleStore(preload.engine.getRuleStore());
     return true;
   } else {
     return false;
   }
 }
Example #15
0
 public void addAll(Collection<? extends Vertex> V) {
   for (Vertex v : V) add(v);
 }
Example #16
0
 @Override
 public void add(Triple t) {
   base.add(t);
   getEventManager().notifyAddTriple(this, t);
 }
Example #17
0
 @Override
 public void performAdd(Triple t) {
   base.add(t);
 }
 private void addNode(String nodeName) {
   graph.add(new Node(nodeName));
 }
 @Override
 public final boolean add(GNode<N> n) {
   return g.add(n);
 }
Example #20
0
 public Vertex vert(String s, Double lat, Double longx) {
   Vertex v = new Vertex(s, lat, longx);
   add(v);
   return v;
 }
Example #21
0
 public Vertex vert(String s) {
   Vertex v = new Vertex(s);
   add(v);
   return v;
 }
 @Override
 public final boolean add(GNode<N> n, byte flags) {
   return g.add(n, flags);
 }
Example #23
0
 @Override
 public void add(Edge edge) {
   super.add(edge);
   super.add(edge.getTransposedEdge());
 }
Example #24
0
 /**
  * All sites must fall within the initial triangle.
  *
  * @param triangle the initial triangle
  */
 public Triangulation(Triangle triangle) {
   triGraph = new Graph<Triangle>();
   triGraph.add(triangle);
   mostRecent = triangle;
 }
Example #25
0
 public void testKevinCaseA() {
   Graph G = getGraph();
   Node X = node("x"), a = node("a"), b = node("b"), c = node("c");
   G.add(Triple.create(X, RDF.Nodes.type, RDF.Nodes.Statement));
   ReifierStd.reifyAs(G, X, Triple.create(a, b, c));
 }
 public void navigateFirst(String nodeName) {
   Node node = xmlReader.getNode(nodeName);
   graph.add(node);
   navigateTo(node);
 }
Example #27
0
 public ZDiscoveryController(IRobot robot, Graph nodeGraph) {
   super(robot);
   this.graph = nodeGraph;
   nodeGraph.setLast(null);
   nodeGraph.add(new JunctionNode(robot), 0);
 }