Interface Node<T>

Type Parameters:
T - The type of the value stored within the node.

public interface Node<T>
Represents a node in graph that can be 'visited' by a NodeVisitor.

This interface defines the fundamental components of a graph node, including a human-readable label and a generic, typed value field for storing associated data. It also provides methods for traversing the graph via neighbors and a hook for implementing the visitor design pattern.

The **label** serves as a non-unique, descriptive name (e.g., "Person," "City"), which is useful for grouping and classification. The **value** field provides a flexible way to store diverse data types, making it a key component for building semantically rich and expressive knowledge graphs.

The getNeighbors() method facilitates graph traversal, while the accept(NodeVisitor) method supports operations on the node using the visitor pattern.

A typical knowledge graph structure involves a collection of nodes connected by relationships (edges), where each node is represented by this interface. The use of a generic type parameter `T` allows the node's value to be defined as any data type, providing maximum flexibility.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    The operation allows a NodeVisitor to "visit" the node.
    Returns an effective and human-readable identifier of this Node, e.g., "Paris," "Albert Einstein".
    Returns the "adjacent" node of this Node.
    A generic typed field that stores the value in this Node.
  • Method Details

    • getLabel

      String getLabel()
      Returns an effective and human-readable identifier of this Node, e.g., "Paris," "Albert Einstein".

      The node label does not have to be unique. A label typically serves to classify or group nodes and can be applied to multiple nodes. Implementor who would like to make it unique should consider a separate identifier, such as UUID.

      Returns:
      the label field of this Node
    • getValue

      T getValue()
      A generic typed field that stores the value in this Node.

      Although a node label provides a human-readable name for the node, it's often not sufficient on its own. To make the graph more expressive and useful for queries and analysis, it's beneficial to have additional fields that capture the specific data associated with that node.

      A node value is a common and effective approach to storing this additional information. Knowledge graphs are designed to handle diverse types of data. A node representing a person might have

      • a birth date
      • a location
      • a profession
      While a node representing a city might have
      • a population
      • a country
      • a geographic coordinate
      A single, dedicated label field can't store all this information in a structured way. For example, a node for the city of Paris could have a Map as its value a key "Population" and a value of 2,141,000, where the type of the value is Integer. Another key could be "Country" and a value of "France," where the type is String.

      The true power of a knowledge graph to model complex relationships and data is achieved with this generic typed field for value as a fundamental part of building a flexible and robust knowledge graph node.

      Returns:
      the data stored in this Node
    • accept

      default void accept(NodeVisitor visitor)
      The operation allows a NodeVisitor to "visit" the node.
      Parameters:
      visitor - The object that operate on this Node
    • getNeighbors

      List<Node<T>> getNeighbors()
      Returns the "adjacent" node of this Node.
      Returns:
      a list of potential processable graph node in BFS.