Class UnionGraphImpl

java.lang.Object
org.apache.jena.graph.impl.GraphBase
org.apache.jena.graph.compose.CompositionBase
org.apache.jena.ontapi.impl.UnionGraphImpl
All Implemented Interfaces:
org.apache.jena.graph.Graph, org.apache.jena.graph.impl.GraphWithPerform, UnionGraph

public class UnionGraphImpl extends org.apache.jena.graph.compose.CompositionBase implements UnionGraph
UnionGraph.

It consists of two parts: a base graph and an sub-graphs collection. Unlike MultiUnion this implementation explicitly requires primary (base) graph. Underlying sub-graphs are only used for searching; modify operations are performed only on the base graph. This graph allows building graph hierarchy which can be used to link different models. Also, it allows recursion, that is, it can contain itself somewhere in the hierarchy. The PrefixMapping of this graph is taken from the base graph, and, therefore, any changes in it reflect both the base and this graph.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    An extended Jena Graph Event Manager, a holder for GraphListeners.
    static class 
    A container to hold all sub-graphs, that make up the hierarchy.

    Nested classes/interfaces inherited from interface org.apache.jena.ontapi.UnionGraph

    UnionGraph.EventManager, UnionGraph.Listener
  • Field Summary

    Fields inherited from class org.apache.jena.graph.impl.GraphBase

    TOSTRING_TRIPLE_BASE, TOSTRING_TRIPLE_LIMIT

    Fields inherited from interface org.apache.jena.graph.Graph

    emptyGraph
  • Constructor Summary

    Constructors
    Constructor
    Description
    UnionGraphImpl(org.apache.jena.graph.Graph base)
    Creates an instance with default settings.
    UnionGraphImpl(org.apache.jena.graph.Graph base, boolean distinct)
    Creates a graph for the given base, which will be either distinct or non-distinct, depending on the second parameter.
    UnionGraphImpl(org.apache.jena.graph.Graph base, UnionGraph.EventManager eventManager, boolean distinct)
    Creates a graph for the given base.
  • Method Summary

    Modifier and Type
    Method
    Description
    addSubGraph(org.apache.jena.graph.Graph graph)
    Adds the specified graph to the underlying graph collection.
    void
     
    void
    Closes the graph including all related graphs.
    boolean
    dependsOn(org.apache.jena.graph.Graph other)
    Generic dependsOn, returns true iff this graph or any sub-graphs depend on the specified graph.
    org.apache.jena.graph.Graph
    Returns the base (primary) graph.
    Answers the ont event manager for this graph.
    org.apache.jena.shared.PrefixMapping
     
    Returns the underlying graph, possible empty.
    boolean
    graphBaseContains(org.apache.jena.graph.Triple t)
    Answers true if the graph contains any triple matching t.
    int
     
    boolean
    Answers true iff this UnionGraph has sub-graphs.
    boolean
    Answers true iff this graph is distinct.
    boolean
     
    org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.graph.Graph>
    Lists all indivisible (base) data Graphs that are encapsulated either in the hierarchy or (which is possible) inside the base (root) graph itself.
    void
    performAdd(org.apache.jena.graph.Triple t)
     
    void
    performDelete(org.apache.jena.graph.Triple t)
     
    void
    remove(org.apache.jena.graph.Node s, org.apache.jena.graph.Node p, org.apache.jena.graph.Node o)
     
    removeSubGraph(org.apache.jena.graph.Graph graph)
    Removes the specified graph from the underlying graph collection.
    Stream<org.apache.jena.graph.Graph>
    Lists all sub-graphs.
    Lists all parent graphs.
     

    Methods inherited from class org.apache.jena.graph.compose.CompositionBase

    butNot, ifIn, ifIn, recording, reject, rejecting, rejecting

    Methods inherited from class org.apache.jena.graph.impl.GraphBase

    add, contains, contains, delete, find, find, forTestingOnly_graphBaseFind, getCapabilities, getTransactionHandler, isClosed, isIsomorphicWith, notifyAdd, notifyDelete, size, toString

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.jena.graph.Graph

    add, add, contains, contains, delete, delete, find, find, find, getCapabilities, getTransactionHandler, isClosed, isIsomorphicWith, size, sizeLong, stream, stream

    Methods inherited from interface org.apache.jena.ontapi.UnionGraph

    addSubGraphIfAbsent, contains
  • Constructor Details

    • UnionGraphImpl

      public UnionGraphImpl(org.apache.jena.graph.Graph base)
      Creates an instance with default settings.

      Note: it results a distinct graph (i.e. its parameter distinct is true). This means that the method GraphBase.find(Triple) does not produce duplicates. The additional duplicate checking may lead to temporary writing the whole graph or some its part into memory in the form of Set, and for huge ontologies it is unacceptable. This checking is not performed if the graph is single (the underlying part is empty).

      Also notice, a top-level ontology view of in-memory graph is not sensitive to the distinct parameter since it uses only base graphs to collect axiomatic data.

      Parameters:
      base - Graph, not null
    • UnionGraphImpl

      public UnionGraphImpl(org.apache.jena.graph.Graph base, boolean distinct)
      Creates a graph for the given base, which will be either distinct or non-distinct, depending on the second parameter. Other settings are default.
      Parameters:
      base - Graph, not null
      distinct - if true a distinct graph is created
    • UnionGraphImpl

      public UnionGraphImpl(org.apache.jena.graph.Graph base, UnionGraph.EventManager eventManager, boolean distinct)
      Creates a graph for the given base.
      Parameters:
      base - Graph, not null
      eventManager - UnionGraph.EventManager or null to use default fresh event manager
      distinct - if true a distinct graph is created
  • Method Details

    • getPrefixMapping

      public org.apache.jena.shared.PrefixMapping getPrefixMapping()
      Specified by:
      getPrefixMapping in interface org.apache.jena.graph.Graph
      Overrides:
      getPrefixMapping in class org.apache.jena.graph.impl.GraphBase
    • getEventManager

      public UnionGraph.EventManager getEventManager()
      Answers the ont event manager for this graph. Override to use in GraphBase.add(Triple).
      Specified by:
      getEventManager in interface org.apache.jena.graph.Graph
      Specified by:
      getEventManager in interface UnionGraph
      Overrides:
      getEventManager in class org.apache.jena.graph.impl.GraphBase
      Returns:
      GraphEventManager, not null
    • isDistinct

      public boolean isDistinct()
      Answers true iff this graph is distinct. See UnionGraphImpl(Graph) description.
      Specified by:
      isDistinct in interface UnionGraph
      Returns:
      boolean
    • getBaseGraph

      public org.apache.jena.graph.Graph getBaseGraph()
      Returns the base (primary) graph.
      Specified by:
      getBaseGraph in interface UnionGraph
      Returns:
      Graph, not null
    • getSubGraphs

      public UnionGraphImpl.SubGraphs getSubGraphs()
      Returns the underlying graph, possible empty.
      Returns:
      UnionGraphImpl.SubGraphs, not null
    • hasSubGraph

      public boolean hasSubGraph()
      Description copied from interface: UnionGraph
      Answers true iff this UnionGraph has sub-graphs.
      Specified by:
      hasSubGraph in interface UnionGraph
      Returns:
      boolean
    • subGraphs

      public Stream<org.apache.jena.graph.Graph> subGraphs()
      Description copied from interface: UnionGraph
      Lists all sub-graphs. The base graph is not included in the result.
      Specified by:
      subGraphs in interface UnionGraph
      Returns:
      Stream of sub-graphs
    • superGraphs

      public Stream<UnionGraph> superGraphs()
      Description copied from interface: UnionGraph
      Lists all parent graphs. The base graph is not included in the result.
      Specified by:
      superGraphs in interface UnionGraph
      Returns:
      Stream of sub-graphs
    • performAdd

      public void performAdd(org.apache.jena.graph.Triple t)
      Specified by:
      performAdd in interface org.apache.jena.graph.impl.GraphWithPerform
      Overrides:
      performAdd in class org.apache.jena.graph.impl.GraphBase
    • performDelete

      public void performDelete(org.apache.jena.graph.Triple t)
      Specified by:
      performDelete in interface org.apache.jena.graph.impl.GraphWithPerform
      Overrides:
      performDelete in class org.apache.jena.graph.impl.GraphBase
    • remove

      public void remove(org.apache.jena.graph.Node s, org.apache.jena.graph.Node p, org.apache.jena.graph.Node o)
      Specified by:
      remove in interface org.apache.jena.graph.Graph
      Overrides:
      remove in class org.apache.jena.graph.impl.GraphBase
    • clear

      public void clear()
      Specified by:
      clear in interface org.apache.jena.graph.Graph
      Overrides:
      clear in class org.apache.jena.graph.impl.GraphBase
    • addSubGraph

      public UnionGraph addSubGraph(org.apache.jena.graph.Graph graph)
      Adds the specified graph to the underlying graph collection. Note: for a well-formed ontological UnionGraph the input graph must be also a UnionGraph, even it has no hierarchy structure.
      Specified by:
      addSubGraph in interface UnionGraph
      Parameters:
      graph - Graph, not null
      Returns:
      this instance
    • removeSubGraph

      public UnionGraph removeSubGraph(org.apache.jena.graph.Graph graph)
      Removes the specified graph from the underlying graph collection.
      Specified by:
      removeSubGraph in interface UnionGraph
      Parameters:
      graph - Graph, not null
      Returns:
      this instance
    • listSubGraphBases

      public org.apache.jena.util.iterator.ExtendedIterator<org.apache.jena.graph.Graph> listSubGraphBases()
      Lists all indivisible (base) data Graphs that are encapsulated either in the hierarchy or (which is possible) inside the base (root) graph itself.
      Returns:
      distinct ExtendedIterator of Graphs, including the base graph
      See Also:
    • graphBaseContains

      public boolean graphBaseContains(org.apache.jena.graph.Triple t)
      Answers true if the graph contains any triple matching t.
      Parameters:
      t - Triple, not null
      Returns:
      boolean
      See Also:
      • MultiUnion.graphBaseContains(Triple)
    • graphBaseSize

      public int graphBaseSize()
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface org.apache.jena.graph.Graph
      Overrides:
      isEmpty in class org.apache.jena.graph.impl.GraphBase
    • close

      public void close()
      Closes the graph including all related graphs. Caution: this is an irreversible operation, once closed, a graph cannot be reopened.
      Specified by:
      close in interface org.apache.jena.graph.Graph
      Overrides:
      close in class org.apache.jena.graph.impl.GraphBase
    • dependsOn

      public boolean dependsOn(org.apache.jena.graph.Graph other)
      Generic dependsOn, returns true iff this graph or any sub-graphs depend on the specified graph.
      Specified by:
      dependsOn in interface org.apache.jena.graph.Graph
      Overrides:
      dependsOn in class org.apache.jena.graph.impl.GraphBase
      Parameters:
      other - Graph
      Returns:
      boolean
    • toString

      public String toString()
      Overrides:
      toString in class org.apache.jena.graph.impl.GraphBase