Package org.eclipse.rdf4j.model.util
Class Models
java.lang.Object
org.eclipse.rdf4j.model.util.Models
- Author:
- Jeen Broekstra, Arjohn Kampman
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Model
convertRDFStarToReification
(Model model) Converts the statements in the supplied RDF-star model to a new RDF model using reification.static void
convertRDFStarToReification
(Model model, Consumer<Statement> consumer) Converts the supplied RDF-star model to RDF reification statements.static Model
convertRDFStarToReification
(ValueFactory vf, Model model) Converts the statements in supplied RDF-star model to a new RDF model using reificiation.static void
convertRDFStarToReification
(ValueFactory vf, Model model, Consumer<Statement> consumer) Converts the supplied RDF-star model to RDF reification statements.static Model
convertRDFStarToReification
(ValueFactory vf, Model model, ModelFactory modelFactory) Converts the statements in supplied RDF-star model to a new RDF model using reificiation.static Model
convertReificationToRDFStar
(Model model) Converts the supplied RDF reification model to a new RDF-star model.static void
convertReificationToRDFStar
(Model model, Consumer<Statement> consumer) Converts the supplied RDF reification model to RDF-star statements.static Model
convertReificationToRDFStar
(ValueFactory vf, Model model) Converts the statements in supplied RDF reification model to a new RDF-star model.static void
convertReificationToRDFStar
(ValueFactory vf, Model model, Consumer<Statement> consumer) Converts the supplied RDF reification model to RDF-star statements.static Model
convertReificationToRDFStar
(ValueFactory vf, Model model, ModelFactory modelFactory) Converts the statements in supplied RDF reification model to a new RDF-star model.getProperties
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property values for the supplied subject and property from the given model.getProperty
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value for the supplied subject from the given model.getPropertyIRI
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as an IRI for the supplied subject from the given model.getPropertyIRIs
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property IRI values for the supplied subject and property from the given model.getPropertyLiteral
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as aLiteral
for the supplied subject from the given model.getPropertyLiterals
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property Literal values for the supplied subject and property from the given model.getPropertyResource
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as an IRI for the supplied subject from the given model.getPropertyResources
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property Resource values for the supplied subject and property from the given model.getPropertyString
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as a String for the supplied subject from the given model.getPropertyStrings
(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property values as Strings for the supplied subject and property from the given model.static boolean
isomorphic
(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2) Compares two RDF models, and returns true if they consist of isomorphic graphs and the isomorphic graph identifiers map 1:1 to each other.static boolean
Compares two RDF models, and returns true if the first model is a subset of the second model, using graph isomorphism to map statements between models.static boolean
Compares two RDF models, and returns true if the first model is a subset of the second model, using graph isomorphism to map statements between models.static boolean
legacyIsomorphic
(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2) Deprecated.static Supplier<ModelException>
modelException
(String message) Creates aSupplier
ofModelException
objects that be passed toOptional.orElseThrow(Supplier)
to generate exceptions as necessary.Retrieves an objectValue
from the supplied statements.Retrieves an objectValue
from the statements in the given model.Retrieves an objectIRI
value from the supplied statements.Retrieves an objectIRI
value from the supplied statements in the given model.objectIRIs
(Iterable<Statement> statements) Retrieves all objectIRI
values from the supplied statements.objectIRIs
(Model m) Retrieves all objectIRI
values from the statements in the given model.objectLiteral
(Iterable<Statement> statements) Retrieves an objectLiteral
value from the supplied statements.Retrieves an objectLiteral
value from the statements in the given model.objectLiterals
(Iterable<Statement> statements) Retrieves all objectLiteral
values from the supplied statements.Retrieves all objectLiteral
values from the statements in the given model.objectResource
(Iterable<Statement> statements) Retrieves an objectResource
value from the supplied statements.Retrieves an objectResource
value from the statements in the given model.objectResources
(Iterable<Statement> statements) Retrieves all objectResource
values from the supplied statements.Retrieves all objectResource
values from the supplied model.objectString
(Iterable<Statement> statements) Retrieves an object value as a String from the supplied statements.Retrieves an object value as a String from the statements in the given model.objectStrings
(Iterable<Statement> statements) Retrieves all object String values from the supplied statements.Retrieves all object String values from the statements in the given model.Retrieves a predicate from the supplied statements.Retrieves a predicate from the statements in the given model.static Model
Sets the property value for the given subject to the given object value, replacing any existing value(s) for the subject's property.static Model
stripContexts
(Model model, Resource... contexts) Strips contexts from the input model.Retrieves a subjectResource
from the supplied statements.Retrieves a subjectResource
from the statements in the given model.subjectBNode
(Iterable<Statement> statements) Retrieves a subjectBNode
from the supplied statements.Retrieves a subjectBNode
from the statements in the given model.subjectBNodes
(Iterable<Statement> statements) Retrieves all subjectBNode
s from the supplied statements.Retrieves all subjectBNode
s from the statements in the given model.subjectIRI
(Iterable<Statement> statements) Retrieves a subjectIRI
from the supplied statements.subjectIRI
(Model m) Retrieves a subjectIRI
from the statements in the given model.subjectIRIs
(Iterable<Statement> statements) Retrieves all subjectIRI
s from the supplied statements.subjectIRIs
(Model m) Retrieves all subjectIRI
s from the statements in the given model.static Model
synchronizedModel
(Model toSynchronize) Make a model thread-safe by synchronizing all its methods.
-
Constructor Details
-
Models
protected Models()
-
-
Method Details
-
object
Retrieves an objectValue
from the supplied statements. If more than one possible object value exists, any one value is picked and returned.- Parameters:
statements
- theStatement
Iterable
from which to retrieve an object value.- Returns:
- an object value from the given statement collection, or
Optional.empty()
if no such value exists.
-
object
Retrieves an objectValue
from the statements in the given model. If more than one possible object value exists, any one value is picked and returned.- Parameters:
m
- the model from which to retrieve an object value.- Returns:
- an object value from the given model, or
Optional.empty()
if no such value exists.
-
objectLiteral
Retrieves an objectLiteral
value from the supplied statements. If more than one possible Literal value exists, any one Literal value is picked and returned.- Parameters:
statements
- theStatement
Iterable
from which to retrieve an object Literal value.- Returns:
- an object Literal value from the given model, or
Optional.empty()
if no such value exists.
-
objectLiteral
Retrieves an objectLiteral
value from the statements in the given model. If more than one possible Literal value exists, any one Literal value is picked and returned.- Parameters:
m
- theModel
from which to retrieve an object Literal value.- Returns:
- an object Literal value from the given model, or
Optional.empty()
if no such value exists.
-
objectLiterals
Retrieves all objectLiteral
values from the supplied statements. -
objectLiterals
Retrieves all objectLiteral
values from the statements in the given model. -
objectResource
Retrieves an objectResource
value from the supplied statements. If more than one possible Resource value exists, any one Resource value is picked and returned. -
objectResource
Retrieves an objectResource
value from the statements in the given model. If more than one possible Resource value exists, any one Resource value is picked and returned. -
objectResources
Retrieves all objectResource
values from the supplied statements. -
objectResources
Retrieves all objectResource
values from the supplied model. -
objectIRI
Retrieves an objectIRI
value from the supplied statements. If more than one possible IRI value exists, any one value is picked and returned. -
objectIRI
Retrieves an objectIRI
value from the supplied statements in the given model. If more than one possible IRI value exists, any one value is picked and returned. -
objectIRIs
Retrieves all objectIRI
values from the supplied statements. -
objectIRIs
Retrieves all objectIRI
values from the statements in the given model. -
objectString
Retrieves an object value as a String from the supplied statements. If more than one possible object value exists, any one value is picked and returned. -
objectString
Retrieves an object value as a String from the statements in the given model. If more than one possible object value exists, any one value is picked and returned. -
objectStrings
Retrieves all object String values from the supplied statements. -
objectStrings
Retrieves all object String values from the statements in the given model.- Parameters:
m
- the model from which to retrieve all object String values.- Returns:
- a
Set
containing object String values from the given model, which will be empty if no such value exists. - See Also:
-
subject
Retrieves a subjectResource
from the supplied statements. If more than one possible resource value exists, any one resource value is picked and returned. -
subject
Retrieves a subjectResource
from the statements in the given model. If more than one possible resource value exists, any one resource value is picked and returned. -
subjectIRI
Retrieves a subjectIRI
from the supplied statements. If more than one possible IRI value exists, any one IRI value is picked and returned. -
subjectIRI
Retrieves a subjectIRI
from the statements in the given model. If more than one possible IRI value exists, any one IRI value is picked and returned. -
subjectIRIs
Retrieves all subjectIRI
s from the supplied statements. -
subjectIRIs
Retrieves all subjectIRI
s from the statements in the given model.- Parameters:
m
- the model from which to retrieve a subject IRI value.- Returns:
- a
Set
of subject IRI values from the given model. The returned Set may be empty.
-
subjectBNode
Retrieves a subjectBNode
from the supplied statements. If more than one possible blank node value exists, any one blank node value is picked and returned. -
subjectBNode
Retrieves a subjectBNode
from the statements in the given model. If more than one possible blank node value exists, any one blank node value is picked and returned. -
subjectBNodes
Retrieves all subjectBNode
s from the supplied statements. -
subjectBNodes
Retrieves all subjectBNode
s from the statements in the given model. -
predicate
Retrieves a predicate from the supplied statements. If more than one possible predicate value exists, any one value is picked and returned. -
predicate
Retrieves a predicate from the statements in the given model. If more than one possible predicate value exists, any one value is picked and returned. -
setProperty
public static Model setProperty(Model m, Resource subject, IRI property, Value value, Resource... contexts) Sets the property value for the given subject to the given object value, replacing any existing value(s) for the subject's property. This method updates the original input Model and then returns that same Model object.- Parameters:
m
- the model in which to set the property value. May not be null.subject
- the subject for which to set/replace the property value. May not be null.property
- the property for which to set/replace the value. May not be null.value
- the value to set for the given subject and property. May not be null.contexts
- the context(s) in which to set/replace the property value. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- the Model object, containing the updated property value.
-
getProperty
public static Optional<Value> getProperty(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.- Parameters:
m
- the model from which to retrieve an object value.subject
- the subject resource for which to retrieve a property value.property
- the property for which to retrieve a value.contexts
- the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a property value from the given model, or
Optional.empty()
if no such value exists.
-
getProperties
public static Set<Value> getProperties(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property values for the supplied subject and property from the given model.- Parameters:
m
- the model from which to retrieve the property values.subject
- the subject resource for which to retrieve all property values.property
- the property for which to retrieve all values.contexts
- the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a Set of all property values for the supplied input. The resulting set may be empty.
-
getPropertyResource
public static Optional<Resource> getPropertyResource(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as an IRI for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.- Parameters:
m
- the model from which to retrieve an object value.subject
- the subject resource for which to retrieve a property value.property
- the property for which to retrieve a value.contexts
- the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a property value Resource from the given model, or
Optional.empty()
if no such value exists.
-
getPropertyResources
public static Set<Resource> getPropertyResources(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property Resource values for the supplied subject and property from the given model.- Parameters:
m
- the model from which to retrieve the property Resource values.subject
- the subject resource for which to retrieve all property Resource values.property
- the property for which to retrieve all Resource values.contexts
- the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a Set of all property Resource values for the supplied input. The resulting set may be empty.
-
getPropertyIRI
public static Optional<IRI> getPropertyIRI(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as an IRI for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.- Parameters:
m
- the model from which to retrieve an object value.subject
- the subject resource for which to retrieve a property value.property
- the property for which to retrieve a value.contexts
- the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a property value IRI from the given model, or
Optional.empty()
if no such value exists.
-
getPropertyIRIs
public static Set<IRI> getPropertyIRIs(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property IRI values for the supplied subject and property from the given model.- Parameters:
m
- the model from which to retrieve the property IRI values.subject
- the subject resource for which to retrieve all property IRI values.property
- the property for which to retrieve all IRI values.contexts
- the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a Set of all property IRI values for the supplied input. The resulting set may be empty.
-
getPropertyLiteral
public static Optional<Literal> getPropertyLiteral(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as aLiteral
for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.- Parameters:
m
- the model from which to retrieve an object value.subject
- the subject resource for which to retrieve a property literal value.property
- the property for which to retrieve a value.contexts
- the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a property value Literal from the given model, or
Optional.empty()
if no such value exists.
-
getPropertyLiterals
public static Set<Literal> getPropertyLiterals(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property Literal values for the supplied subject and property from the given model.- Parameters:
m
- the model from which to retrieve the property Literal values.subject
- the subject resource for which to retrieve all property Literal values.property
- the property for which to retrieve all Literal values.contexts
- the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a Set of all property IRI values for the supplied input. The resulting set may be empty.
-
getPropertyString
public static Optional<String> getPropertyString(Model m, Resource subject, IRI property, Resource... contexts) Retrieve a property value as a String for the supplied subject from the given model. If more than one property value exists, any one value is picked and returned.- Parameters:
m
- the model from which to retrieve an object value.subject
- the subject resource for which to retrieve a property literal value.property
- the property for which to retrieve a value.contexts
- the contexts from which to retrieve the property value. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a property value String from the given model, or
Optional.empty()
if no such value exists.
-
getPropertyStrings
public static Set<String> getPropertyStrings(Model m, Resource subject, IRI property, Resource... contexts) Retrieve all property values as Strings for the supplied subject and property from the given model.- Parameters:
m
- the model from which to retrieve the property values as Strings.subject
- the subject resource for which to retrieve all property values as Strings.property
- the property for which to retrieve all values as Strings.contexts
- the contexts from which to retrieve the property values. Optional vararg argument. If not specified the operations works on the entire Model.- Returns:
- a Set of all property values as Strings for the supplied input. The resulting set may be empty.
-
isomorphic
public static boolean isomorphic(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2) Compares two RDF models, and returns true if they consist of isomorphic graphs and the isomorphic graph identifiers map 1:1 to each other. RDF graphs are isomorphic graphs if statements from one graphs can be mapped 1:1 on to statements in the other graphs. In this mapping, blank nodes are not considered mapped when having an identical internal id, but are mapped from one graph to the other by looking at the statements in which the blank nodes occur. A Model can consist of more than one graph (denoted by context identifiers). Two models are considered isomorphic if for each of the graphs in one model, an isomorphic graph exists in the other model, and the context identifiers of these graphs are either identical or (in the case of blank nodes) map 1:1 on each other. -
legacyIsomorphic
@Experimental @Deprecated public static boolean legacyIsomorphic(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2) Deprecated.since 3.6.0 - useisomorphic(Iterable, Iterable)
instead.Legacy implementation ofisomorphic comparison
. This method is offered as a temporary fallback for corner cases where the newly introduced isomorphism algorithm (in release 3.6.0) has worse performance or an unexpected result.- Since:
- 3.6.0
- See Also:
-
isSubset
public static boolean isSubset(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2) Compares two RDF models, and returns true if the first model is a subset of the second model, using graph isomorphism to map statements between models. -
isSubset
Compares two RDF models, and returns true if the first model is a subset of the second model, using graph isomorphism to map statements between models. -
stripContexts
Strips contexts from the input model. This method provides a newModel
containing all statements from the input model, with the supplied contexts removed from those statements.- Parameters:
model
- the input modelcontexts
- the contexts to remove. This is a vararg and as such is optional. If not supplied, the method strips all contexts.- Returns:
- a new
Model
object containg the same statements as the input model, with the supplied contexts stripped.
-
modelException
Creates aSupplier
ofModelException
objects that be passed toOptional.orElseThrow(Supplier)
to generate exceptions as necessary.- Parameters:
message
- The message to be used for the exception- Returns:
- A
Supplier
that will createModelException
objects with the given message.
-
synchronizedModel
Make a model thread-safe by synchronizing all its methods. Iterators will still not be thread-safe!- Parameters:
toSynchronize
- the model that should be synchronized- Returns:
- Synchronized Model
-
convertRDFStarToReification
@Experimental public static void convertRDFStarToReification(ValueFactory vf, Model model, Consumer<Statement> consumer) Converts the supplied RDF-star model to RDF reification statements. The converted statements are sent to the supplied consumer function.The supplied value factory is used to create all new statements.
- Parameters:
vf
- theValueFactory
to use for creating statements.model
- theModel
to convert.consumer
- theConsumer
function for the produced statements.
-
convertRDFStarToReification
@Experimental public static void convertRDFStarToReification(Model model, Consumer<Statement> consumer) Converts the supplied RDF-star model to RDF reification statements. The converted statements are sent to the supplied consumer function. -
convertRDFStarToReification
Converts the statements in supplied RDF-star model to a new RDF model using reificiation.The supplied value factory is used to create all new statements.
- Parameters:
vf
- theValueFactory
to use for creating statements.model
- theModel
to convert.- Returns:
- a new
Model
with RDF-star statements converted to reified triples.
-
convertRDFStarToReification
@Experimental public static Model convertRDFStarToReification(ValueFactory vf, Model model, ModelFactory modelFactory) Converts the statements in supplied RDF-star model to a new RDF model using reificiation.The supplied value factory is used to create all new statements.
- Parameters:
vf
- theValueFactory
to use for creating statements.model
- theModel
to convert.modelFactory
- theModelFactory
used to create the new outputModel
.- Returns:
- a new
Model
with RDF-star statements converted to reified triples.
-
convertRDFStarToReification
Converts the statements in the supplied RDF-star model to a new RDF model using reification. -
convertReificationToRDFStar
@Experimental public static void convertReificationToRDFStar(ValueFactory vf, Model model, Consumer<Statement> consumer) Converts the supplied RDF reification model to RDF-star statements. The converted statements are sent to the supplied consumer function.The supplied value factory is used to create all new statements.
- Parameters:
vf
- theValueFactory
to use for creating statements.model
- theModel
to convert.consumer
- theConsumer
function for the produced statements.
-
convertReificationToRDFStar
@Experimental public static void convertReificationToRDFStar(Model model, Consumer<Statement> consumer) Converts the supplied RDF reification model to RDF-star statements. The converted statements are sent to the supplied consumer function. -
convertReificationToRDFStar
@Experimental public static Model convertReificationToRDFStar(ValueFactory vf, Model model, ModelFactory modelFactory) Converts the statements in supplied RDF reification model to a new RDF-star model.The supplied value factory is used to create all new statements.
- Parameters:
vf
- theValueFactory
to use for creating statements.model
- theModel
to convert.modelFactory
- theModelFactory
to use for creating a new Model object for the output.- Returns:
- a new
Model
with reification statements converted to RDF-starTriple
s.
-
convertReificationToRDFStar
Converts the statements in supplied RDF reification model to a new RDF-star model.The supplied value factory is used to create all new statements.
- Parameters:
vf
- theValueFactory
to use for creating statements.model
- theModel
to convert.- Returns:
- a new
Model
with reification statements converted to RDF-starTriple
s.
-
convertReificationToRDFStar
Converts the supplied RDF reification model to a new RDF-star model.
-
isomorphic(Iterable, Iterable)
instead.