getSubjects method

List<RdfSubject> getSubjects(
  1. RdfPredicate predicate,
  2. RdfObject object
)

Get all subjects with a given predicate and object

This is a convenience method for "reverse lookups" - finding resources that have a particular property value. It returns all subjects from triples where the predicate and object match the specified values.

In RDF terms, this retrieves all resources that have a specific property with a specific value, which is useful for finding resources by attribute.

Parameters:

  • predicate The property (predicate) to search by
  • object The value that matching resources must have for the property

Returns: An unmodifiable list of all subject resources that match the pattern. The list may be empty if no matching triples exist.

Example:

// Find all people who know Jane
final peopleWhoKnowJane = graph.getSubjects(knows, jane);

// Find all resources of type Person
final allPersons = graph.getSubjects(rdf.type, foaf.Person);

// Find resources with a specific email address
final resourcesWithEmail = graph.getSubjects(email, LiteralTerm.string('john@example.com'));

Implementation

List<RdfSubject> getSubjects(RdfPredicate predicate, RdfObject object) {
  var subjects = findTriples(
    predicate: predicate,
    object: object,
  ).map((triple) => triple.subject);
  return subjects.isEmpty
      ? const []
      : List.unmodifiable(
          subjects,
        );
}