N-grams: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Disaggregated one function, expanded range of test.)
Line 354: Line 354:


windows :: Int -> [a] -> [[a]]
windows :: Int -> [a] -> [[a]]
windows n = getZipList . traverse ZipList . take n . tails
windows n = transpose . take n . tails

transpose :: [[a]] -> [[a]]
transpose [] = []
transpose xs = getZipList (traverse ZipList xs)




Line 367: Line 371:
>> putStrLn ""
>> putStrLn ""
)
)
[2, 3, 4]</syntaxhighlight>
[0 .. 4]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>2-GRAMS:
<pre>0-GRAMS:

1-GRAMS:
(" ",3)
("A",1)
("D",1)
("E",3)
("I",2)
("L",3)
("N",1)
("T",1)
("V",2)

2-GRAMS:
(" A",1)
(" A",1)
(" L",2)
(" L",2)