| | import duckdb as duckdb |
| | import pandas as pd |
| | import tabulate |
| | from datasets import load_dataset |
| |
|
| | cursor = duckdb.connect() |
| | cursor.execute("PRAGMA threads=4") |
| |
|
| | NROWS = 100000000 |
| | NA_VALUES = "\\N" |
| |
|
| | dataset = load_dataset("open_subtitles", lang1="en", lang2="nl", split="train") |
| | open_subtitles = dataset.data.table |
| | print( |
| | tabulate.tabulate( |
| | cursor.execute(f"SELECT * FROM open_subtitles LIMIT 5").fetchdf(), |
| | headers="keys", |
| | tablefmt="psql", |
| | ) |
| | ) |
| |
|
| | |
| | |
| | |
| |
|
| | title_basics = pd.read_csv( |
| | "title.basics.tsv.gz", sep="\t", na_values=NA_VALUES, nrows=NROWS |
| | ) |
| | basics_df = cursor.execute("SELECT * from title_basics limit 5").fetch_df() |
| | print(tabulate.tabulate(basics_df, headers="keys", tablefmt="psql")) |
| |
|
| | title_episodes = pd.read_csv( |
| | "title.episode.tsv.gz", sep="\t", na_values=NA_VALUES, nrows=NROWS |
| | ) |
| | episodes_df = cursor.execute("SELECT * from title_episodes limit 5").fetch_df() |
| | print(tabulate.tabulate(episodes_df, headers="keys", tablefmt="psql")) |
| |
|
| | title_ratings = pd.read_csv( |
| | "title.ratings.tsv.gz", sep="\t", na_values=NA_VALUES, nrows=NROWS |
| | ) |
| | ratings_df = cursor.execute("SELECT * from title_ratings limit 5").fetch_df() |
| | print(tabulate.tabulate(ratings_df, headers="keys", tablefmt="psql")) |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | |
| | episode_detail = cursor.execute( |
| | """ |
| | SELECT |
| | open_subtitles.id, |
| | open_subtitles.translation, |
| | open_subtitles.meta, |
| | title_basics.tconst, |
| | title_basics.primaryTitle, |
| | title_basics.startYear, |
| | title_basics.endYear, |
| | title_basics.genres, |
| | title_basics.runtimeMinutes, |
| | title_basics.titleType, |
| | title_basics.isAdult, |
| | title_ratings.tconst AS rating_tconst, |
| | title_ratings.averageRating, |
| | title_ratings.numVotes, |
| | title_episodes.tconst as episode_tconst, |
| | title_episodes.parentTconst, |
| | title_episodes.seasonNumber, |
| | title_episodes.episodeNumber |
| | FROM |
| | title_episodes |
| | INNER JOIN |
| | title_basics |
| | ON |
| | title_episodes.parentTconst = title_basics.tconst |
| | INNER JOIN |
| | title_ratings |
| | ON |
| | title_episodes.tconst = title_ratings.tconst |
| | INNER JOIN |
| | open_subtitles |
| | ON |
| | title_episodes.tconst = 'tt' || open_subtitles.meta.imdbId |
| | WHERE isAdult == 0 |
| | and averageRating > 8.0 |
| | and numVotes > 1000 |
| | ORDER BY startYear, episode_tconst, seasonNumber, episodeNumber, meta.sentenceIds.en |
| | """ |
| | ).fetch_df() |
| | print(tabulate.tabulate(episode_detail[:5], headers="keys", tablefmt="psql")) |
| |
|
| | |
| | episode_detail.to_json("episode_opensubtitles.json", orient="records", lines=True) |
| |
|