Module org.apache.jena.ontapi
Class DocumentGraphRepository
java.lang.Object
org.apache.jena.ontapi.impl.repositories.DocumentGraphRepository
- All Implemented Interfaces:
GraphRepository
Simple GraphRepository implementation with location mapping.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddMapping
(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
clear()
Removes all graphs.boolean
Returnstrue
if a mapping for the specified identifier exists in the repository.long
count()
Returns the number of identifiers.org.apache.jena.graph.Graph
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>
graphs()
Returns all already loaded graphs.ids()
Lists all graph's identifiers.org.apache.jena.graph.Graph
Associates the graph with the specified id.org.apache.jena.graph.Graph
Removes and returns the graph identified by the specifiedid
, along with all its associations.
-
Constructor Details
-
DocumentGraphRepository
public DocumentGraphRepository() -
DocumentGraphRepository
-
-
Method Details
-
checkLocation
Checks whether the specified string is a valid URI or a file path.- Parameters:
uriOrFile
- to validate- Returns:
- the same string
-
addMapping
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 formfile:///...
. Class-resource path string should be without leading "/" symbol. After successful load, the graph will be available both byid
and byfileNameOrUri
(viaget(String)
method). A graph can be associated with different identifiers but only with one source.- Parameters:
id
- Graph's id, arbitrary stringuriOrFile
- location of the Graph document (e.g. "file://ontology.ttl")- Returns:
- this instance
- See Also:
-
get
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 interfaceGraphRepository
- Parameters:
id
-String
Graph's identifier- Returns:
Graph
- Throws:
org.apache.jena.shared.JenaException
- if graph cannot be loaded- See Also:
-
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 interfaceGraphRepository
- Returns:
Stream
of ids
-
put
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 interfaceGraphRepository
- Parameters:
id
-String
Graph's identifier, which can be arbitrary stringgraph
-Graph
- Returns:
Graph
the previously associated with id ornull
-
remove
Removes and returns the graph identified by the specifiedid
, along with all its associations.- Specified by:
remove
in interfaceGraphRepository
- Parameters:
id
-String
Graph's identifier- Returns:
Graph
ornull
if the graph is not found
-
clear
public void clear()Removes all graphs.- Specified by:
clear
in interfaceGraphRepository
-
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 interfaceGraphRepository
- Returns:
long
-
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 interfaceGraphRepository
- Returns:
- distinct
Stream
ofGraph
s
-
contains
Returnstrue
if a mapping for the specified identifier exists in the repository.- Specified by:
contains
in interfaceGraphRepository
- Parameters:
id
-String
Graph's identifier- Returns:
- boolean
-