movieWithUserDataToTurtleOntology static method
Updates a single movie with user's personal rating and comment following the ontology structure.
Implementation
static String movieWithUserDataToTurtleOntology(
Movie movie, double? rating, String? comment) {
final triples = <URIRef, Map<URIRef, dynamic>>{};
// Create the movie resource with all movie metadata.
final movieResource = moviestarDataNS.withAttr('movie-${movie.id}');
triples[movieResource] = {
rdfType: [owlNS.withAttr('NamedIndividual'), movieType],
identifier:
Literal('${movie.id}', datatype: xsdNS.withAttr('positiveInteger')),
name: Literal(_escapeAndSanitizeString(movie.title)),
description: Literal(_escapeAndSanitizeString(movie.overview)),
image: Literal(_escapeAndSanitizeString(movie.posterUrl),
datatype: xsdNS.withAttr('anyURI')),
thumbnailUrl: Literal(_escapeAndSanitizeString(movie.backdropUrl),
datatype: xsdNS.withAttr('anyURI')),
aggregateRating:
Literal('${movie.voteAverage}', datatype: xsdNS.withAttr('double')),
datePublished: Literal(movie.releaseDate.toIso8601String(),
datatype: xsdNS.withAttr('date')),
genre: Literal(movie.genreIds.join(',')),
rdfsLabel: Literal('|name=${_escapeAndSanitizeString(movie.title)}|'),
};
// Add user's personal rating if it exists.
if (rating != null) {
triples[movieResource]![contentRating] =
Literal('$rating', datatype: xsdNS.withAttr('double'));
}
// Add user's personal comment if it exists.
if (comment != null && comment.isNotEmpty) {
triples[movieResource]![TurtleSerializer.comment] =
Literal(_escapeAndSanitizeString(comment));
}
// Add JSON backup for compatibility.
final movieJson = jsonEncode(movie.toJson());
final userDataJson = jsonEncode({
'rating': rating,
'comment': comment,
});
// Use ontology-compliant namespace bindings.
final ttlContent =
tripleMapToTurtle(triples, bindNamespaces: _getOntologyNamespaces());
final withJsonBackup =
'$ttlContent\n\n# JSON_MOVIE_DATA: $movieJson\n# JSON_USER_DATA: $userDataJson';
return withJsonBackup;
}