6
|
1 |
\documentclass{article}
|
39
|
2 |
\usepackage{../style}
|
166
|
3 |
\usepackage{disclaimer}
|
202
|
4 |
\usepackage{../langs}
|
6
|
5 |
|
|
6 |
\begin{document}
|
|
7 |
|
|
8 |
|
202
|
9 |
\section*{Coursework 7 (DocDiff and Danube.org)}
|
6
|
10 |
|
202
|
11 |
This coursework is worth 10\%. The first part and second part are due
|
|
12 |
on 22 November at 11pm; the third, more advanced part, is due on 21
|
|
13 |
December at 11pm. You are asked to implement Scala programs for
|
|
14 |
measuring similarity in texts and for recommending movies
|
|
15 |
according to a ratings list. Note the second part might include
|
|
16 |
material you have not yet seen in the first two lectures. \bigskip
|
50
|
17 |
|
166
|
18 |
\IMPORTANT{}
|
202
|
19 |
|
|
20 |
\noindent
|
144
|
21 |
Also note that the running time of each part will be restricted to a
|
202
|
22 |
maximum of 30 seconds on my laptop.
|
39
|
23 |
|
166
|
24 |
\DISCLAIMER{}
|
39
|
25 |
|
|
26 |
|
202
|
27 |
\subsection*{Reference Implementation}
|
45
|
28 |
|
202
|
29 |
Like the C++ assignments, the Scala assignments will work like this: you
|
|
30 |
push your files to GitHub and receive (after sometimes a long delay) some
|
|
31 |
automated feedback. In the end we take a snapshot of the submitted files and
|
|
32 |
apply an automated marking script to them.
|
45
|
33 |
|
202
|
34 |
In addition, the Scala assignments come with a reference
|
|
35 |
implementation in form of a \texttt{jar}-file. This allows you to run
|
|
36 |
any test cases on your own computer. For example you can call Scala on
|
|
37 |
the command line with the option \texttt{-cp docdiff.jar} and then
|
|
38 |
query any function from the template file. Say you want to find out
|
|
39 |
what the function \texttt{occurences} produces: for this you just need
|
|
40 |
to prefix it with the object name \texttt{CW7a} (and \texttt{CW7b}
|
|
41 |
respectively for \texttt{danube.jar}). If you want to find out what
|
|
42 |
these functions produce for the list \texttt{List("a", "b", "b")},
|
|
43 |
you would type something like:
|
6
|
44 |
|
202
|
45 |
\begin{lstlisting}[language={},numbers=none,basicstyle=\ttfamily\small]
|
|
46 |
$ scala -cp docdiff.jar
|
|
47 |
|
|
48 |
scala> CW7a.occurences(List("a", "b", "b"))
|
|
49 |
...
|
|
50 |
\end{lstlisting}%$
|
|
51 |
|
|
52 |
\subsection*{Hints}
|
6
|
53 |
|
45
|
54 |
|
39
|
55 |
|
|
56 |
|
202
|
57 |
\newpage
|
|
58 |
\subsection*{Part 1 (4 Marks, file docdiff.scala)}
|
6
|
59 |
|
202
|
60 |
It seems source code plagiarism---stealing someone else's code---is a
|
|
61 |
serious problem at other universities.\footnote{Surely, King's
|
|
62 |
students, after all their instructions and warnings, would never
|
|
63 |
commit such an offence.} Dedecting such plagiarism is time-consuming
|
|
64 |
and disheartening. To aid the poor lecturers at other universities,
|
|
65 |
let's implement a program that determines the similarity between two
|
|
66 |
documents (be they code or English texts). A document will be
|
|
67 |
represented as a list of strings.
|
6
|
68 |
|
|
69 |
|
202
|
70 |
\subsection*{Tasks}
|
45
|
71 |
|
|
72 |
\begin{itemize}
|
202
|
73 |
\item[(1)] Implement a function that cleans a string by finding all
|
|
74 |
words in this string. For this use the regular expression
|
|
75 |
\texttt{"$\backslash$w+"} and the library function
|
|
76 |
\texttt{findAllIn}. The function should return a list of
|
|
77 |
strings.\\
|
|
78 |
\mbox{}\hfill [1 Mark]
|
45
|
79 |
|
202
|
80 |
\item[(2)] In order to compute the similarity between two documents, we
|
|
81 |
associate each document with a \texttt{Map}. This Map represents the
|
|
82 |
strings in a document and how many times these strings occur in a
|
|
83 |
document. A simple (though slightly inefficient) method for counting
|
|
84 |
the number of string-occurences in a document is as follows: remove
|
|
85 |
all duplicates from the document; for each of these (unique)
|
|
86 |
strings, count how many times they occur in the original document.
|
|
87 |
Return a Map from strings to occurences. For example
|
6
|
88 |
|
45
|
89 |
\begin{center}
|
202
|
90 |
\pcode{occurences(List("a", "b", "b", "c", "d"))}
|
45
|
91 |
\end{center}
|
|
92 |
|
202
|
93 |
produces \pcode{Map(a -> 1, b -> 2, c -> 1, d -> 1)} and
|
45
|
94 |
|
|
95 |
\begin{center}
|
202
|
96 |
\pcode{occurences(List("d", "b", "d", "b", "d"))}
|
48
|
97 |
\end{center}
|
45
|
98 |
|
202
|
99 |
produces \pcode{Map(d -> 3, b -> 2)}.\hfill[1 Mark]
|
6
|
100 |
|
202
|
101 |
\item[(3)] You can think of the Maps calculated under (2) as efficient
|
|
102 |
representations of sparse ``vectors''. In this subtask you need to
|
|
103 |
implement the \emph{product} of two vectors, sometimes also called
|
|
104 |
\emph{dot product}.\footnote{\url{https://en.wikipedia.org/wiki/Dot_product}}
|
148
|
105 |
|
202
|
106 |
For this implement a function that takes two documents
|
|
107 |
(\texttt{List[String]}) as arguments. The function first calculates
|
|
108 |
the (unique) strings in both. For each string, it multiplies the
|
|
109 |
occurences in each document. If a string does not occur in one of the
|
|
110 |
documents, then the product is zero. At the end you
|
|
111 |
sum all products. For the two documents in (2) the dot product is 7:
|
45
|
112 |
|
|
113 |
\[
|
202
|
114 |
\underbrace{1 * 0}_{"a"} \;\;+\;\;
|
|
115 |
\underbrace{2 * 2}_{"b"} \;\;+\;\;
|
|
116 |
\underbrace{1 * 0}_{"c"} \;\;+\;\;
|
|
117 |
\underbrace{1 * 3}_{"d"}
|
|
118 |
\]
|
|
119 |
|
|
120 |
\hfill\mbox{[1 Mark]}
|
|
121 |
|
|
122 |
\item[(4)] Implement first a function that calculates the overlap
|
|
123 |
between two documents, say $d_1$ and $d_2$, according to the formula
|
|
124 |
|
|
125 |
\[
|
|
126 |
\texttt{overlap}(d_1, d_2) = \frac{d_1 \cdot d_2}{max(d_1^2, d_2^2)}
|
45
|
127 |
\]
|
|
128 |
|
202
|
129 |
This function should return a \texttt{Double} between 0 and 1. The
|
|
130 |
overlap between the lists in (2) is $0.5384615384615384$.
|
|
131 |
|
|
132 |
Second implement a function that calculates the similarity of
|
|
133 |
two strings, by first extracting the strings using the function from (1)
|
|
134 |
and then calculating the overlap.
|
|
135 |
\hfill\mbox{[1 Mark]}
|
48
|
136 |
\end{itemize}
|
|
137 |
|
148
|
138 |
|
|
139 |
|
202
|
140 |
\newpage
|
|
141 |
You are creating Danube.org, which you hope will be the next big thing
|
|
142 |
in online movie provider. You know that you can save money by
|
|
143 |
anticipating what movies people will rent; you will pass these savings
|
|
144 |
on to your users by offering a discount if they rent movies that Danube.org
|
|
145 |
recommends. This assignment is meant to calculate
|
45
|
146 |
|
|
147 |
|
202
|
148 |
To do this, you offer an incentive for people to upload their lists of
|
|
149 |
recommended books. From their lists, you can establish suggested
|
|
150 |
pairs. A pair of books is a suggested pair if both books appear on one
|
|
151 |
person’s recommendation list. Of course, some suggested pairs are more
|
|
152 |
popular than others. Also, any given book is paired with some books
|
|
153 |
much more frequently than with others.
|
45
|
154 |
|
148
|
155 |
|
|
156 |
|
6
|
157 |
|
|
158 |
\end{document}
|
|
159 |
|
|
160 |
%%% Local Variables:
|
|
161 |
%%% mode: latex
|
|
162 |
%%% TeX-master: t
|
|
163 |
%%% End:
|