<span class="Apple-style-span" style="font-family: Verdana, Arial, &#39;Bitstream Vera Sans&#39;, Helvetica, sans-serif; font-size: 13px; "><p>Both sections relate to the case study: Index for a document of text.</p><p>SECTION A:</p>
<p>Given the attached <span class="searchword3" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 204, 255); background-position: initial initial; background-repeat: initial initial; ">Haskell</span> code which produces an index of <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span>s, make the following alterations by modifying existing functions and including new functions where necessary :</p>
<p>3) <span class="searchword0" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(255, 255, 153); background-position: initial initial; background-repeat: initial initial; ">Treat</span> a <span class="searchword1" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 204); background-position: initial initial; background-repeat: initial initial; ">capitalised</span> <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span> (one or more capitals) as being different from the word in all lower case (but they should still be sorted alphabetically) – unless it is at the start of a sentence with only the initial letter capitalised. A sentence is terminated by a ‘.’, ‘?’ or ‘!’.</p>
<p><br></p><p>import Prelude</p><p>type Doc = String type Line = String type <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span> = String</p>
<p>makeIndex :: Doc -&gt; [ ([Int], <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>) ]</p>
<p>makeIndex</p><blockquote><p>= shorten . -- [([Int], <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>)] -&gt; [([Int], Word)]</p>
<blockquote><p>amalgamate .-- [([Int], <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>)] -&gt; [([Int], Word)] makeLists . -- [(Int, Word)] -&gt; [([Int], Word)] sortLs . -- [(Int, Word)] -&gt; [(Int, Word)]</p>
</blockquote><p>allNum<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s .-- [(Int, Line)] -&gt; [(Int, Word)] numLines . -- [Line] -&gt; [(Int, Line)] splitUp -- Doc -&gt; [Line]</p>
</blockquote><p>splitUp :: Doc -&gt; [Line]</p><p>splitUp [] = [] splitUp text</p><blockquote><p>= takeWhile (/=&#39;\n&#39;) text : -- first line</p><blockquote><p>(splitUp . -- splitup other lines</p><blockquote><p>dropWhile (==’\n’) . -- delete 1st newline(s) dropWhile (/=&#39;\n&#39;)) text -- other lines</p>
</blockquote></blockquote></blockquote><p>numLines :: [Line] -&gt; [(Int, Line)]</p><p>numLines lines -- list of pairs of</p><blockquote><p>= zip [1 .. length lines] lines -- line no. &amp; line</p></blockquote><p>-- for each line -- a) split into <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span>s -- b) attach line no. to each word</p>
<p>split<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s :: Line -&gt; [Word] -- a)</p>
<p>split<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s [] = [] splitWords line</p>
<blockquote><p>= takeWhile isLetter line : -- first <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span> in line</p>
<blockquote><p>(split<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s . -- split other words</p>
<blockquote><p>dropWhile (not.isLetter) . -- delete separators dropWhile isLetter) line -- other <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span>s</p>
</blockquote></blockquote><p>where isLetter ch</p><blockquote><blockquote><p>= (‘a’&lt;=ch) &amp;&amp; (ch&lt;=’z’)</p><blockquote><table class="wiki" style="border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; ">
<tbody><tr><td style="font: normal normal normal 13px/normal Verdana, Arial, &#39;Bitstream Vera Sans&#39;, Helvetica, sans-serif; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); padding-top: 0.1em; padding-right: 0.25em; padding-bottom: 0.1em; padding-left: 0.25em; ">
(‘A’&lt;=ch) &amp;&amp; (ch&lt;=’Z’)</td></tr></tbody></table></blockquote></blockquote></blockquote></blockquote><p>num<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s :: (Int, Line) -&gt; [(Int, Word)] -- b)</p>
<p>num<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s (number, line)</p>
<blockquote><p>= map addLineNum ( split<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s line) -- all line pairs</p>
<blockquote><p>where addLineNum <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span> = (number, word) -- a pair</p>
</blockquote></blockquote><p>allNum<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s :: [(Int, Line)] -&gt; [(Int, Word)]</p>
<p>allNum<span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>s = concat . map numWords -- doc pairs</p>
<p>sortLs :: [(Int, <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>)] -&gt; [(Int, Word)]</p>
<p>sortLs [ ] = [ ] sortLs (a:x)</p><blockquote><p>= sortLs [b | b &lt;- x, compare b a] -- sort 1st half</p><blockquote><p>++ [a] ++ -- 1st in middle sortLs [b | b &lt;- x, compare a b] -- sort 2nd half</p><blockquote><p>
where compare (n1, w1) (n2, w2)</p><blockquote><p>= (w1 &lt; w2) -- 1st <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span> less</p>
<blockquote><table class="wiki" style="border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); border-collapse: collapse; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; ">
<tbody><tr><td style="font: normal normal normal 13px/normal Verdana, Arial, &#39;Bitstream Vera Sans&#39;, Helvetica, sans-serif; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); padding-top: 0.1em; padding-right: 0.25em; padding-bottom: 0.1em; padding-left: 0.25em; ">
(w1 == w2 &amp;&amp; n1 &lt; n2) -- check no.</td></tr></tbody></table></blockquote></blockquote></blockquote></blockquote></blockquote><p>makeLists :: [(Int, <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>)] -&gt; [([Int], Word)]</p>
<p>makeLists</p><blockquote><p>= map mk -- all pairs</p><blockquote><p>where mk (num, <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span>) = ([num], word)</p>
<blockquote><p>-- list of single no.</p></blockquote></blockquote></blockquote><p>amalgamate :: [([Int], <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>)] -&gt; [([Int], Word)]</p>
<p>amalgamate [ ] = [ ] amalgamate [a] = [a] amalgamate ((n1, w1) : (n2, w2) : rest)-- pairs of pairs</p><blockquote><p>| w1 /= w2 = (n1, w1) : amalgamate ((n2, w2) : rest) | otherwise = amalgamate ((n1 ++ n2, w1) : rest)</p>
<blockquote><p>-- if <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span>s are same grow list of numbers</p>
</blockquote></blockquote><p>shorten :: [([Int], <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">Word</span>)] -&gt; [([Int], Word)]</p>
<p>shorten</p><blockquote><p>= filter long -- keep pairs &gt;4</p><blockquote><p>where</p><blockquote><p>long (num, <span class="searchword2" style="background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(204, 255, 255); background-position: initial initial; background-repeat: initial initial; ">word</span>) = length word &gt; 4 -- check word &gt;4</p>
</blockquote></blockquote></blockquote></span>