Class Graph

java.lang.Object
org.qubitpi.wilhelm.Graph

@Immutable @ThreadSafe public class Graph extends Object
A JSON-serializable object representation of a knowledge graph in wilhelm-ws.
  • Constructor Details

    • Graph

      public Graph(@NotNull @NotNull Set<Node> nodes, @NotNull @NotNull Set<Link> links)
      All-args constructor.
      Parameters:
      nodes - The set of all nodes contained in this Graph, cannot be null
      links - The set of all links contained in this Graph, cannot be null
  • Method Details

    • emptyGraph

      public static Graph emptyGraph()
      Creates a new Graph instance with no initial nodes or links in it.
      Returns:
      a new instance
    • isEmpty

      public boolean isEmpty()
      Returns whether or not this Graph has neither nodes noe links.
      Returns:
      true if no nodes or links exist in this Graph, or false otherwise.
    • getUndirectedNeighborsOf

      @NotNull public @NotNull Set<Node> getUndirectedNeighborsOf(Node node)
      Returns all weakly connected neighbors of a specified node.

      If the node has no such neighrbors, this method returns an empty list

      Parameters:
      node - a node from this Graph
      Returns:
      all nodes each of which has a link between it and the provided node.
    • merge

      public Graph merge(@NotNull @NotNull Graph that)
      Combines the nodes and links from this Graph instance and the other one and returns a new Graph.
      Parameters:
      that - the other Graph instance to be merged with this Graph
      Returns:
      a new instance
    • getNodes

      @NotNull public @NotNull Set<Node> getNodes()
      Returns an unmodifiable view of all the nodes in this Graph instance.
      Returns:
      an immutable list of nodes
    • getLinks

      @NotNull public @NotNull Set<Link> getLinks()
      Returns an unmodifiable view of all the links in this Graph instance.
      Returns:
      an immutable list of links
    • toString

      @NotNull public @NotNull String toString()
      Returns a JSON serialization of this Graph instance. It contains 2 fields: nodes and links, each of which is a list of nodes and links respectively. Each list element is itself a JSON object whose structure are defined by Jackson's serialization on Node and Link.
      Overrides:
      toString in class Object
      Returns:
      a JSON string