createMovieList static method

String createMovieList(
  1. String movieListId,
  2. String listName, {
  3. List<Movie>? movies,
  4. String? description,
})

Creates a MovieList in TTL format following the ontology structure.

Implementation

static String createMovieList(
  String movieListId,
  String listName, {
  List<Movie>? movies,
  String? description,
}) {
  final triples = <URIRef, Map<URIRef, dynamic>>{};

  // Create the MovieList resource.

  final movieListResource =
      moviestarDataNS.withAttr('MovieList-$movieListId');
  triples[movieListResource] = {
    rdfType: [owlNS.withAttr('NamedIndividual'), movieListType],
    TurtleSerializer.identifier: Literal(movieListId),
    TurtleSerializer.name: Literal(_escapeAndSanitizeString(listName)),
    TurtleSerializer.description: Literal(
        _escapeAndSanitizeString(description ?? 'List of movies: $listName')),
    rdfsLabel:
        Literal('|filePath=moviestar/data/MovieList-$movieListId.ttl|'),
  };

  // Add movie references (not full movie data) if provided.

  if (movies != null && movies.isNotEmpty) {
    final movieRefs = movies
        .map((movie) => moviestarDataNS.withAttr('movie-${movie.id}'))
        .toList();
    triples[movieListResource]![hasMovie] = movieRefs;

    // Add individual movie reference definitions (not full data).
    // According to ontology, MovieList only contains references with filePath.

    for (final movie in movies) {
      final movieResource = moviestarDataNS.withAttr('movie-${movie.id}');
      triples[movieResource] = {
        rdfType: [owlNS.withAttr('NamedIndividual'), movieType],
        filePath: Literal('moviestar/data/movies/Movie-${movie.id}.ttl'),
        rdfsLabel:
            Literal('|filePath=moviestar/data/movies/Movie-${movie.id}.ttl|'),
      };
    }
  }

  // Use ontology-compliant namespace bindings.

  return tripleMapToTurtle(triples, bindNamespaces: _getOntologyNamespaces());
}