classify 2012.10.23 → 2013.11.6
raw patch · 4 files changed
+45/−20 lines, 4 files
Files
- classify.cabal +1/−1
- src/Data/Classify/Parser.hs +32/−0
- src/Data/Classify/Rank.hs +11/−1
- src/Data/Classify/Television.hs +1/−18
classify.cabal view
@@ -1,6 +1,6 @@ Cabal-version: >=1.6 Name: classify-Version: 2012.10.23+Version: 2013.11.6 Build-Type: Simple License: PublicDomain License-File: LICENSE
src/Data/Classify/Parser.hs view
@@ -280,3 +280,35 @@ rets -> fst (head (sortBy (comparing (length.snd)) rets)) ++++++++++++stripName :: String -> [String]+stripName = nub . map (filter isAlphaNum . filter (not . isSpace)) . expand . map toLower+ where+ alts = [ ("the", "")+ , ("newyork", "ny")+ , ("los angeles", "la")+ , ("and", "")+ , ("&", "and") ]+ doesMatch key [] = Nothing+ doesMatch key (x:xs)+ | fst x `isPrefixOf` key = Just x+ | otherwise = doesMatch key xs+ expand lst = lst : concatMap expand [ before ++ new ++ drop (length old) after+ | (before, after) <- split lst+ , Just (old, new) <- [doesMatch after alts] ]+ worker lst = expand lst++split :: String -> [(String,String)]+split str = zip (inits str) (tails str)++
src/Data/Classify/Rank.hs view
@@ -59,13 +59,17 @@ -- Tests -------------------------------------------------------------- -testSeries = Map.fromList [ (P.trunc t,t) | (_,t,_) <- testData]+testSeries = Map.fromList [ (src,t) | (_,t,_) <- testData, src <- P.stripName t] v24 = "24" simpsons = "The Simpsons" colbert = "The Colbert Report" palms = "Hidden Palms" daily = "The Daily Show"+ncis = "NCIS"+ncis_la = "NCIS: Los Angeles"+law_svu = "Law & Order: SVU"+mike_molly = "Mike & Molly" testData = [ ("24.S06E01.6AM.TO.7AM.PROPER.DVDRip.XviD-MEMETiC.avi", "24", Version 6 1) , ("The.Simpsons.S18E09.PROPER.PDTV.XviD-2HD.avi", "The Simpsons", Version 18 9)@@ -111,6 +115,12 @@ , ("south.park.1109.dsr.xvid-sys.[VTV].avi", "South Park", Version 11 9) , ("South Park - 12x09 - Breast Cancer Show Ever.avi", "South Park", Version 12 9) , ("Merlin 2008 5x03 The Death Song Of Uther Pendragon REPACK HDTV x264-FoV", "Merlin", Version 5 3)+ , ("NCIS Los Angeles S05E07 HDTV x264-LOL", ncis_la, Version 5 7)+ , ("NCIS S11E07 HDTV x264-LOL", ncis, Version 11 7)+ , ("NCIS LA 4x14 (HDTV-x264-LOL) [VTV]", ncis_la, Version 4 14)+ , ("Law and Order SVU S14E14 HDTV x264-LOL", law_svu, Version 14 14)+ , ("Law & Order SVU 14x13 (HDTV-x264-LOL) [VTV]", law_svu, Version 14 13)+ , ("Mike and Molly S04E01 HDTV x264-LOL", mike_molly, Version 4 1) ] runTests = flip mapM_ testData $ \(str, series, expectedVersion) ->
src/Data/Classify/Television.hs view
@@ -26,7 +26,7 @@ import qualified Data.Map as Map import Data.Char ( isAlphaNum, isSpace, toLower )-import Data.List ( inits, tails, isPrefixOf )+import Data.List ( inits, tails, isPrefixOf, nub ) tryClassify :: [Name] -> String -> Maybe (Name, Version, Title) tryClassify knownNames inp =@@ -45,20 +45,3 @@ Nothing -> error $ "Data.Classify.Television.classify: Failed to parse: " ++ show inp Just result -> result -stripName :: String -> [String]-stripName = worker . filter isAlphaNum . filter (not . isSpace) . map toLower- where- alts = [ ("the", "")- , ("newyork", "ny")- , ("los angeles", "la") ]- doesMatch key [] = Nothing- doesMatch key (x:xs)- | fst x `isPrefixOf` key = Just x- | otherwise = doesMatch key xs- expand lst = lst : concatMap expand [ before ++ new ++ drop (length old) after- | (before, after) <- split lst- , Just (old, new) <- [doesMatch after alts] ]- worker lst = expand lst--split :: String -> [(String,String)]-split str = zip (inits str) (tails str)