diff --git a/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt b/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt index 97d9f6a4..8aea4b45 100644 --- a/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt +++ b/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt @@ -16,7 +16,14 @@ internal class Brief(val number: Int, val name: String, val kinds: Set, val themes: Regex, val against: Regex, val era: Pair, val kids: Boolean = false, val uk: Boolean = false, val current: Boolean = false, val needTheme: Boolean = false) -private fun w(vararg words: String) = Regex("\\b(" + words.joinToString("|") + ")", RegexOption.IGNORE_CASE) +/** + * A brief's words, matched at the start of a word so a stem finds its forms ("haunt" finds haunted). Short words that start + * other words are matched whole (Paul, 30 November 2026: "con" found continue and confront, so Superman III scored as a BritX + * con film; "war" found warrior, "mob" mobile). + */ +private val WholeWords = setOf("con", "war", "mob", "gang", "drug", "cop", "date", "team", "time", "life", "home", "sea", "oil", "eat", "ai", "case", "band", + "tale", "toy", "crew", "fame", "dad", "mom", "mum", "kids", "spy", "hero", "noel", "evil", "epic") +private fun w(vararg words: String) = Regex("\\b(" + words.joinToString("|") { if (it.lowercase() in WholeWords) "$it(?:s|es)?\\b" else it } + ")", RegexOption.IGNORE_CASE) /** Every channel the Chair places titles on: Orbit's own, then the channels you've made ([YourBriefs]). */ internal val Briefs: List get() = BaseBriefs + YourBriefs @@ -141,8 +148,9 @@ internal val BaseBriefs: List = listOf( // Paul, 30 November 2026 (catalogue discovery): the three newest channels, from their approved identities. // ATLAS: international drama and cinema in its own language; only titles made outside the English-speaking world. Brief(ATLAS_NUMBER, "ATLAS", setOf("Series", "Movie"), setOf("Drama", "Crime", "Thriller", "Mystery", "Romance", "Action", "Science Fiction", "Fantasy"), - themes = w("korea", "seoul", "japan", "tokyo", "nordic", "scandi", "denmark", "sweden", "norway", "iceland", "spain", "madrid", "france", "paris", "germany", "berlin", - "italy", "naples", "mexico", "brazil", "india", "turkey", "israel", "colombia", "argentina"), + // Where a story is set says nothing about where a film was made (Paul, 30 November 2026: Wheels on Meals scored on + // "Spain"); ATLAS goes by the countries that made it ([international]), not by places in its description. + themes = w("subtitled", "foreign-language", "world cinema"), against = w("documentary", "animated", "reality"), era = 1960 to 2026, current = true), // SYNDICATE: organised crime, from the mob family to the cartel and the heist crew, series and films. Brief(SYNDICATE_NUMBER, "SYNDICATE", setOf("Series", "Movie"), setOf("Crime", "Drama", "Thriller"), setOf("Crime"), @@ -320,9 +328,28 @@ internal fun channelScore(e: TitleEvidence, b: Brief, text: ChannelText, links: if (ch == 101 && rating in Adult) return 0.0 to listOf("rated $rating, too old for Orbit 1") if (ch == 601 && rating in PreschoolRatings) return 0.0 to listOf("rated $rating, a preschool show") if (ch == PUNCHLINE_NUMBER && "Horror" in g) return 0.0 to listOf("a horror film: After Dark's, not PUNCHLINE's") + // What kind of film it is, not only its tags (Paul, 30 November 2026, the film discovery): a secondary genre tag doesn't + // make a film the channel's. Each rule says which heavier genre outweighs the channel's own. + if (b.kinds == setOf("Movie") || ch in setOf(SYNDICATE_NUMBER, ATLAS_NUMBER, 601)) { + val comedyWords = Regex("\\b(comedy|comedian|spoof|parody|slapstick|stand-up|farce|hilarious|zany|madcap)", RegexOption.IGNORE_CASE).containsMatchIn(ov) + if (ch == PUNCHLINE_NUMBER && (g intersect setOf("Drama", "Crime", "Biography", "Action", "Thriller", "War")).isNotEmpty() && !comedyWords && !LiveSpecial.containsMatchIn(ov)) + return 0.0 to listOf("comedy is a secondary tag here: ${(g intersect setOf("Drama", "Crime", "Biography", "Action", "Thriller", "War")).joinToString()} carries the film") + if (ch == 307 && (g intersect setOf("Biography", "Sport", "War", "Action", "Crime", "History")).isNotEmpty()) + return 0.0 to listOf("romance is a secondary tag here: ${(g intersect setOf("Biography", "Sport", "War", "Action", "Crime", "History")).joinToString()} carries the film") + if (ch == CHRISTMAS_NUMBER && (g intersect setOf("Action", "Thriller", "Horror", "Crime", "War")).isNotEmpty()) + return 0.0 to listOf("set at Christmas, but ${(g intersect setOf("Action", "Thriller", "Horror", "Crime", "War")).joinToString()}: not festive family viewing") + if (ch == SYNDICATE_NUMBER && (g intersect setOf("Action", "Adventure")).isNotEmpty() && b.themes.findAll(all).count() < 2) + return 0.0 to listOf("an action film with a criminal in it, not organised crime") + if (ch == 601 && "Action" !in g && "Anime" !in g) return 0.0 to listOf("animation without action: PixelZ's or Wonder's, not Vortex's") + if (ch == 601 && PixelzStudio.containsMatchIn(e.studios.orEmpty().joinToString(" "))) return 0.0 to listOf("a PixelZ studio's film") + if (ch == 301 && e.community != null && e.community < 6.5) return 0.0 to listOf("not an event film: its viewers rate it ${e.community}") + if (ch == 309 && "Crime" !in g && !b.themes.containsMatchIn(all)) return 0.0 to listOf("British, but not crime or gritty drama") + } if (ch == ATLAS_NUMBER && !international(e)) return 0.0 to listOf(if (e.countries.isNullOrEmpty()) "country of origin not known" else "made in the English-speaking world") val countries = e.countries.orEmpty().joinToString(" "); val studios = e.studios.orEmpty().joinToString(" ") val british = Uk.containsMatchIn(countries) || UkStudio.containsMatchIn(studios) || links.britishList(e.id) != null + val ukFirst = e.countries.isNullOrEmpty() || Uk.containsMatchIn(e.countries.first()) + if (ch == 309 && british && !ukFirst && links.britishList(e.id) == null) return 0.0 to listOf("a co-production led from ${e.countries!!.first()}, not a British film") if (ch == 309 && !british) return 0.0 to listOf(if (e.countries.isNullOrEmpty() && e.studios.isNullOrEmpty()) "British origin not verified" else "not British by its countries, studios or lists") if (b.uk) { if (british) { s += .1; ev += links.britishList(e.id)?.let { "British (on the library's $it list)" } ?: "British" } diff --git a/android/app/src/test/java/tv/orbit/classic/ChairFilmExamplesTest.kt b/android/app/src/test/java/tv/orbit/classic/ChairFilmExamplesTest.kt new file mode 100644 index 00000000..ce695b58 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/ChairFilmExamplesTest.kt @@ -0,0 +1,41 @@ +package tv.orbit.classic + +import org.json.JSONObject +import org.junit.Assert.assertTrue +import org.junit.Test + +/** + * Paul's film examples from the library discovery (30 November 2026), as permanent checks on the Director's Chair. Each uses + * the film's real details from the server. A must-not is never a strong match (0.5 or more) for that channel; a must stays at + * least a possible one (0.4), here scored without the channel's description profile, which the TV adds. + */ +class ChairFilmExamplesTest { + private val films = javaClass.classLoader!!.getResourceAsStream("chair-film-examples.jsonl")!!.bufferedReader().readLines() + .filter { it.isNotBlank() }.map { TitleEvidence.of(JSONObject(it)) }.associateBy { it.name } + private fun score(name: String, channel: Int): Double { + val e = films.getValue(name) + return channelScore(e, Briefs.first { it.number == channel }, ChannelText(emptyMap(), mapOf(e.id to e))).first + } + private val mustNot = listOf( + "Superman III" to 309, "Superman II" to 309, "Rye Lane" to 309, "Fast X" to SYNDICATE_NUMBER, "A Shaun the Sheep Movie: Farmageddon" to 601, + "Megamind vs. The Doom Syndicate" to SYNDICATE_NUMBER, "Three Billboards Outside Ebbing, Missouri" to PUNCHLINE_NUMBER, + "Are You There God? It's Me, Margaret." to PUNCHLINE_NUMBER, "Tucker: The Man and His Dream" to PUNCHLINE_NUMBER, "Charlie's Angels" to PUNCHLINE_NUMBER, + "Silent Night" to CHRISTMAS_NUMBER, "Cinderella Man" to 307, "Superman IV: The Quest for Peace" to 301) + private val must = listOf( + "Cemetery Man" to 305, "Tales from the Darkside: The Movie" to 305, "Circus of Horrors" to 305, "Gunfight at the O.K. Corral" to OUTLAW_NUMBER, + "A Christmas Story" to CHRISTMAS_NUMBER, "KPop Demon Hunters" to 601, "Peaky Blinders: The Immortal Man" to SYNDICATE_NUMBER) + + @Test fun theChairsMistakesStayFixed() { + val wrong = mustNot.filter { (name, ch) -> name in films && score(name, ch) >= 0.5 }.map { (name, ch) -> "$name on $ch: ${score(name, ch)}" } + assertTrue(wrong.joinToString("\n"), wrong.isEmpty()) + } + + @Test fun itsGoodPicksStay() { + val lost = must.filter { (name, ch) -> name in films && score(name, ch) < 0.4 }.map { (name, ch) -> "$name on $ch: ${score(name, ch)}" } + assertTrue(lost.joinToString("\n"), lost.isEmpty()) + // Dawn of the Dead (2004) belongs with horror, on Orbit Horror or After Dark. + assertTrue(maxOf(score("Dawn of the Dead", 304), score("Dawn of the Dead", 305)) >= 0.5) + } + + @Test fun everyExampleIsInTheFixture() { assertTrue((mustNot + must).map { it.first }.all { it in films }) } +} diff --git a/android/app/src/test/java/tv/orbit/classic/FilmDiscoveryTest.kt b/android/app/src/test/java/tv/orbit/classic/FilmDiscoveryTest.kt index 34c8ac22..6c29ba05 100644 --- a/android/app/src/test/java/tv/orbit/classic/FilmDiscoveryTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/FilmDiscoveryTest.kt @@ -51,7 +51,8 @@ class FilmDiscoveryTest { } File(dir, if (name.contains("verified")) "stage2.tsv" else "stage1.tsv").writeText(out.toString()) if (!name.contains("verified")) { - // The strongest per channel by what the catalogue can tell (genre, era, rating), most-copied first: those go to the server. + // The strongest per channel by what the catalogue can tell (genre, era, rating), the best fit first and copies only to + // break a tie (Paul, 30 November 2026: a film in one copy mustn't fall behind a weaker one in several). val pick = StringBuilder("channel\tid\ttitle\tyear\tcopies\tlocal\n") val free = lines.filter { !onOrbit(it) } for (b in briefs) { @@ -64,7 +65,7 @@ class FilmDiscoveryTest { if (y < lo - 2 || y > hi + 1) return@mapNotNull null if (b.kids && e.rating.orEmpty() in Adult) return@mapNotNull null Triple(o, o.optInt("copies"), channelScore(e, b, text).first) - }.filter { it.third > 0.0 }.sortedWith(compareByDescending> { it.second }.thenByDescending { it.third }).take(60) + }.filter { it.third > 0.0 }.sortedWith(compareByDescending> { it.third }.thenByDescending { it.second }).take(60) cands.forEach { (o, c, sc) -> pick.append("${b.number} ${b.name}\t${o.getString("id")}\t${o.getString("name").replace('\t', ' ')}\t${o.optInt("year")}\t$c\t${"%.2f".format(sc)}\n") } } File(dir, "select.tsv").writeText(pick.toString()) diff --git a/android/app/src/test/resources/chair-film-examples.jsonl b/android/app/src/test/resources/chair-film-examples.jsonl new file mode 100644 index 00000000..9b190a73 --- /dev/null +++ b/android/app/src/test/resources/chair-film-examples.jsonl @@ -0,0 +1,21 @@ +{"id": "5437389", "type": "Movie", "name": "Are You There God? It's Me, Margaret.", "year": 2023, "overview": "When her family moves from New York City to New Jersey, an 11-year-old girl navigates new friends, feelings, and the beginning of adolescence.", "genres": ["Comedy", "Drama"], "studios": ["Gracie Films", "Lionsgate"], "rating": "PG-13", "community": 7.114, "taglines": ["Discovering who you are is a journey that lasts a lifetime."], "countries": ["United States of America"]} +{"id": "5439986", "type": "Movie", "name": "Cinderella Man", "year": 2005, "overview": "The true story of James J. Braddock, a supposedly washed-up boxer, who returned to the spotlight to win the heavyweight championship of the world.", "genres": ["Biography", "Drama", "Romance"], "studios": ["Miramax"], "rating": "PG-13", "community": 8, "taglines": ["One man's extraordinary fight to save the family he loved."], "countries": ["United States of America"]} +{"id": "5436079", "type": "Movie", "name": "Charlie's Angels", "year": 2000, "overview": "Three private investigators are assigned to track down a kidnapped software engineer, but the case isn't as straightforward as it seems.", "genres": ["Action", "Adventure", "Comedy"], "studios": ["Columbia Pictures"], "rating": "PG-13", "community": 5.6, "taglines": ["Get some action."], "countries": ["United States of America"]} +{"id": "5439422", "type": "Movie", "name": "Fast X", "year": 2023, "overview": "Dom Toretto and his family are targeted by the vengeful son of drug kingpin Hernan Reyes.", "genres": ["Action", "Adventure", "Crime"], "studios": ["Universal Pictures"], "rating": "PG-13", "community": 5.7, "taglines": ["The end of the road begins."], "countries": ["United States of America"]} +{"id": "5052566", "type": "Movie", "name": "Circus of Horrors", "year": 1960, "overview": "A plastic surgeon and his nurse join a bizarre circus to escape from the police. Here he befriends deformed women and transforms them for his \"Temple of Beauty\". However, when they threaten to leave, they meet with mysterious accidents.", "genres": ["Horror", "Crime"], "studios": ["Lynx Films Ltd."], "rating": "NR", "community": 5.8, "taglines": ["Spectacular Towering Terror! One man's lust...made men into beasts, stripped women of their souls!"], "countries": ["United Kingdom"]} +{"id": "5436975", "type": "Movie", "name": "Peaky Blinders: The Immortal Man", "year": 2026, "overview": "After his estranged son gets embroiled in a Nazi plot, self-exiled gangster Tommy Shelby must return to Birmingham to save his family \u2014 and his nation.", "genres": ["Crime", "Drama", "War"], "studios": ["BBC Film"], "rating": "R", "community": 7.7, "taglines": ["It will all come to this."], "countries": ["United Kingdom"]} +{"id": "5053000", "type": "Movie", "name": "Gunfight at the O.K. Corral", "year": 1957, "overview": "Lawman Wyatt Earp and outlaw Doc Holliday form an unlikely alliance which culminates in their participation in the legendary Gunfight at the O.K. Corral.", "genres": ["Western"], "studios": ["Wallis-Hazen Inc.", "Hal Wallis Productions", "Paramount Pictures"], "rating": "NR", "community": 7, "taglines": ["The Wildest Gunfight in the History of the West!"], "countries": ["United States of America"]} +{"id": "5439105", "type": "Movie", "name": "Dawn of the Dead", "year": 2004, "overview": "A nurse, a policeman, a young married couple, a salesman and other survivors of a worldwide plague that is producing aggressive, flesh-eating zombies, take refuge in a mega Midwestern shopping mall.", "genres": ["Horror"], "studios": ["Universal Pictures"], "rating": "R", "community": 7.2, "taglines": ["When there's no more room in Hell, the dead will walk the Earth."], "countries": ["United States of America"]} +{"id": "5440660", "type": "Movie", "name": "Superman II", "year": 1980, "overview": "Superman agrees to sacrifice his powers to start a relationship with Lois Lane, unaware that three Kryptonian criminals he inadvertently released are conquering Earth.", "genres": ["Action", "Adventure", "Sci-Fi"], "studios": ["Warner Bros. Pictures"], "rating": "PG", "community": 6.8, "taglines": ["The Man of Steel meets his match!"], "countries": ["United Kingdom", "United States of America"]} +{"id": "5440126", "type": "Movie", "name": "Tales from the Darkside: The Movie", "year": 1990, "overview": "The film, shot in anthology style, depicts a kidnapped paperboy who tells three stories of horror to the suburban witch who is preparing to eat him, \u00e0 la Hansel and Gretel.", "genres": ["Comedy", "Fantasy", "Horror", "Thriller"], "studios": ["Paramount Pictures"], "rating": "R", "community": 6.2, "taglines": ["Four Ghoulish Fables In One Modern Nightmare!"], "countries": ["United States of America"]} +{"id": "5435898", "type": "Movie", "name": "Tucker: The Man and His Dream", "year": 1988, "overview": "The story of Preston Tucker, the maverick car designer and his ill-fated challenge to the auto industry with his revolutionary car concept.", "genres": ["Biography", "Comedy", "Drama"], "studios": ["Lucasfilm"], "rating": "PG", "community": 6.9, "taglines": ["When they tried to buy him, he refused. When they tried to bully him, he resisted. When they tried to break him, he became an American legend. The true story of Preston Tucker."], "countries": ["United States of America"]} +{"id": "5440816", "type": "Movie", "name": "A Christmas Story", "year": 1983, "overview": "In the 1940s, a young boy named Ralphie Parker attempts to convince his parents, teacher, and Santa Claus that a Red Ryder Range 200 Shot BB gun really is the perfect Christmas gift.", "genres": ["Comedy", "Family"], "studios": ["Metro-Goldwyn-Mayer"], "rating": "PG", "community": 7.9, "taglines": ["A tribute to the original, traditional, one-hundred-percent, red-blooded, two-fisted, all-American Christmas."], "countries": ["United States of America"]} +{"id": "5476001", "type": "Movie", "name": "Cemetery Man", "year": 1994, "overview": "Something is causing the dead to rise from their graves as flesh-eating zombies, and cemetery custodian Francesco Dellamorte grows tired of killing them all for the second time. However, the town politicians won't listen to him.", "genres": ["Comedy", "Drama", "Fantasy", "Horror"], "studios": ["StudioCanal"], "rating": "R", "community": 6.909, "taglines": ["Zombies, guns and sex, OH MY!!!"], "countries": ["Italy", "France", "Germany"]} +{"id": "5435661", "type": "Movie", "name": "Superman III", "year": 1983, "overview": "Entrepreneur Ross Webster teams up with a computer genius in order to realise his own evil intentions. When Superman obstructs his plans, he decides to destroy him.", "genres": ["Action", "Adventure", "Comedy"], "studios": ["Warner Bros. Pictures"], "rating": "PG", "community": 5, "taglines": ["If the world's most powerful computer can control even Superman...no one on earth is safe."], "countries": ["United States of America", "United Kingdom", "Netherlands"]} +{"id": "5439904", "type": "Movie", "name": "Superman IV: The Quest for Peace", "year": 1987, "overview": "With the world on the brink of a nuclear war, Superman takes it upon himself to destroy all nuclear weapons. However, Lex Luthor creates Nuclear Man, a force strong enough to take down Superman.", "genres": ["Action", "Adventure", "Sci-Fi"], "studios": ["Warner Bros. Pictures"], "rating": "PG", "community": 3.7, "taglines": ["Nuclear Power. In the best hands, it is dangerous. In the hands of Lex Luthor, it is pure evil. This is Superman's greatest battle. And it is for all of us."], "countries": ["United Kingdom", "United States of America"]} +{"id": "5435726", "type": "Movie", "name": "Rye Lane", "year": 2023, "overview": "Two youngsters reeling from bad breakups connect over an eventful day in South London.", "genres": ["Comedy", "Drama", "Romance"], "studios": ["Searchlight Pictures", "BBC Film", "BFI", "DJ Films", "Turnover Films"], "rating": "R", "community": 7.2, "taglines": null, "countries": ["United Kingdom", "United States of America"]} +{"id": "5439096", "type": "Movie", "name": "Three Billboards Outside Ebbing, Missouri", "year": 2017, "overview": "A mother personally challenges the local authorities to solve her daughter's murder when they fail to catch the culprit.", "genres": ["Comedy", "Crime", "Drama"], "studios": ["Blueprint Pictures", "Cutting Edge Group", "Fox Searchlight Pictures", "Film4 Productions"], "rating": "R", "community": 8.1, "taglines": ["A mother personally challenges the local authorities to solve her daughter's murder when they fail to catch the culprit."], "countries": ["United Kingdom", "United States of America"]} +{"id": "5439924", "type": "Movie", "name": "KPop Demon Hunters", "year": 2025, "overview": "When K-pop superstars Rumi, Mira and Zoey aren't selling out stadiums, they're using their secret powers to protect their fans from supernatural threats.", "genres": ["Action", "Adventure", "Animation", "Comedy", "Fantasy", "Musical"], "studios": ["Columbia Pictures"], "rating": "PG", "community": 7.966, "taglines": ["They sing. They dance. They battle demons."], "countries": ["United States of America"]} +{"id": "5438910", "type": "Movie", "name": "Megamind vs. The Doom Syndicate", "year": 2024, "overview": "Megamind's former villain team, The Doom Syndicate, has returned. Newly crowned hero Megamind's must now keep up evil appearances until he can assemble his friends to stop his former evil teammates from launching Metro City to the...", "genres": ["Animation", "Action", "Adventure"], "studios": ["DreamWorks Animation Television"], "rating": "TV-G", "community": 2.5, "taglines": ["Act like a villain, think like a hero."], "countries": ["United States of America"]} +{"id": "5437297", "type": "Movie", "name": "A Shaun the Sheep Movie: Farmageddon", "year": 2019, "overview": "When an alien with amazing powers crash-lands near Mossy Bottom Farm, Shaun the Sheep goes on a mission to shepherd the intergalactic visitor home before a sinister organization can capture her.", "genres": ["Animation", "Adventure", "Comedy"], "studios": ["Netflix"], "rating": "G", "community": 6.8, "taglines": ["Close encounters of the furred kind."], "countries": ["France", "United Kingdom"]} +{"id": "5439643", "type": "Movie", "name": "Silent Night", "year": 2023, "overview": "A grieving father enacts his long-awaited revenge against a ruthless gang on Christmas Eve.", "genres": ["Action", "Crime", "Drama"], "studios": ["Thunder Road", "Capstone Group", "A Better Tomorrow Films", "Lionsgate"], "rating": "R", "community": 5.3, "taglines": ["Action speaks louder than words."], "countries": ["United States of America"]}