Class DocumentGraphRepository

java.lang.Object
org.apache.jena.ontapi.impl.repositories.DocumentGraphRepository
All Implemented Interfaces:
GraphRepository

public class DocumentGraphRepository extends Object implements GraphRepository
Simple GraphRepository implementation with location mapping.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    DocumentGraphRepository(Supplier<org.apache.jena.graph.Graph> factory)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    addMapping(String id, String uriOrFile)
    Adds mapping Graph's ID <-> source document location, which can be an OS file path, class-resource path, or URI (ftp or http).
    static String
    checkLocation(String uriOrFile)
    Checks whether the specified string is a valid URI or a file path.
    void
    Removes all graphs.
    boolean
    Returns true if a mapping for the specified identifier exists in the repository.
    long
    Returns the number of identifiers.
    org.apache.jena.graph.Graph
    get(String id)
    Gets the graph by its ID, which can be ontology id, location (file or uri) or arbitrary identifier, if there is a mapping for it.
    Stream<org.apache.jena.graph.Graph>
    Returns all already loaded graphs.
    ids()
    Lists all graph's identifiers.
    org.apache.jena.graph.Graph
    put(String id, org.apache.jena.graph.Graph graph)
    Associates the graph with the specified id.
    org.apache.jena.graph.Graph
    Removes and returns the graph identified by the specified id, along with all its associations.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DocumentGraphRepository

      public DocumentGraphRepository()
    • DocumentGraphRepository

      public DocumentGraphRepository(Supplier<org.apache.jena.graph.Graph> factory)
  • Method Details

    • checkLocation

      public static String checkLocation(String uriOrFile)
      Checks whether the specified string is a valid URI or a file path.
      Parameters:
      uriOrFile - to validate
      Returns:
      the same string
    • addMapping

      public DocumentGraphRepository addMapping(String id, String uriOrFile)
      Adds mapping Graph's ID <-> source document location, which can be an OS file path, class-resource path, or URI (ftp or http). File URL should be of the form file:///.... Class-resource path string should be without leading "/" symbol. After successful load, the graph will be available both by id and by fileNameOrUri (via get(String) method). A graph can be associated with different identifiers but only with one source.
      Parameters:
      id - Graph's id, arbitrary string
      uriOrFile - location of the Graph document (e.g. "file://ontology.ttl")
      Returns:
      this instance
      See Also:
    • get

      public org.apache.jena.graph.Graph get(String id)
      Gets the graph by its ID, which can be ontology id, location (file or uri) or arbitrary identifier, if there is a mapping for it. The method attempts to load the graph if it is not yet in the repository.
      Specified by:
      get in interface GraphRepository
      Parameters:
      id - String Graph's identifier
      Returns:
      Graph
      Throws:
      org.apache.jena.shared.JenaException - if graph cannot be loaded
      See Also:
    • ids

      public Stream<String> ids()
      Lists all graph's identifiers. Note that the number of identifiers may exceed the number of graphs if there are multiple id-source mappings.
      Specified by:
      ids in interface GraphRepository
      Returns:
      Stream of ids
    • put

      public org.apache.jena.graph.Graph put(String id, org.apache.jena.graph.Graph graph)
      Associates the graph with the specified id. If there is no id-source mapping yet, the given id will be used as a document source.
      Specified by:
      put in interface GraphRepository
      Parameters:
      id - String Graph's identifier, which can be arbitrary string
      graph - Graph
      Returns:
      Graph the previously associated with id or null
    • remove

      public org.apache.jena.graph.Graph remove(String id)
      Removes and returns the graph identified by the specified id, along with all its associations.
      Specified by:
      remove in interface GraphRepository
      Parameters:
      id - String Graph's identifier
      Returns:
      Graph or null if the graph is not found
    • clear

      public void clear()
      Removes all graphs.
      Specified by:
      clear in interface GraphRepository
    • count

      public long count()
      Returns the number of identifiers. Note that it may exceed the number of graphs if there are multiple associations.
      Specified by:
      count in interface GraphRepository
      Returns:
      long
    • graphs

      public Stream<org.apache.jena.graph.Graph> graphs()
      Returns all already loaded graphs. Note that the number of returned graphs may not be equal to the number of mappings (count()).
      Specified by:
      graphs in interface GraphRepository
      Returns:
      distinct Stream of Graphs
    • contains

      public boolean contains(String id)
      Returns true if a mapping for the specified identifier exists in the repository.
      Specified by:
      contains in interface GraphRepository
      Parameters:
      id - String Graph's identifier
      Returns:
      boolean