moviesFromTurtle static method
- String ttlContent
Parses movies from TTL content using proper RDF parsing.
Implementation
static List<Movie> moviesFromTurtle(String ttlContent) {
try {
// First try to parse from JSON backup for backward compatibility.
final jsonMatch = RegExp(r'# JSON_DATA: (.+)').firstMatch(ttlContent);
if (jsonMatch != null) {
final jsonData = jsonMatch.group(1)!;
final decoded = jsonDecode(jsonData) as List<dynamic>;
return decoded.map((movie) => Movie.fromJson(movie)).toList();
}
// Parse using proper RDF if no JSON backup.
final triples = turtleToTripleMap(ttlContent);
final movies = <Movie>[];
// Find movie resources (subjects that have movie:Movie type).
for (final subject in triples.keys) {
final predicates = triples[subject]!;
// Check if this is a movie resource - look for various type URIs.
final typeValues =
predicates['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'] ?? [];
final isMovie = typeValues.any(
(type) =>
type.toString().contains('Movie') ||
type == 'http://schema.org/Movie' ||
type == '#Movie',
);
if (isMovie) {
// Extract movie data from predicates.
final movie = _extractMovieFromTriples(predicates);
if (movie != null) {
movies.add(movie);
}
}
}
return movies;
} catch (e) {
// Fallback to empty list if parsing fails.
return [];
}
}