%ex3.3

\begin{enumerate}[label=(\alph*),leftmargin=2\parindent]
	\item\textbf{Two basic queries to start with:}
	\begin{itemize}
		\item\textbf{List all the distinct countries for which addresses are
			registered in the database.}
			\begin{lstlisting}[style=command]
MATCH (n:Address) RETURN DISTINCT n.countries AS countries
			\end{lstlisting}
			This returns 222 different countries. We chose ''Austria''.
			\newline
			\newline
		\item\textbf{Choose one of these countries and list 5 entities which
			are based in that country.}
			\begin{lstlisting}[style=command]
MATCH (n:Address {countries: 'Austria'})<-[r:REGISTERED_ADDRESS]-(e:Entity)
RETURN DISTINCT e AS entity LIMIT 5
			\end{lstlisting}
			\input{results/result_3a.tex}
			\newline
			\newline
	\end{itemize}
	\item
		\begin{enumerate}[label=\roman*,leftmargin=1\parindent]
			\item\textbf{First, find the 10 \texttt{top intermediaries} , i.e.
				those 10 intermediaries that have the most outgoing
				\texttt{INTERMEDIARY\_OF} edges. Output the name of the
				intermediary as well as the number of relevant edges.}
				\begin{lstlisting}[style=command]
MATCH (n:Intermediary)-[r:INTERMEDIARY_OF]->()
RETURN n.name AS name, COUNT(r) AS count ORDER BY count DESC LIMIT 10
				\end{lstlisting}
				\input{results/result_3b1.tex}
				\newline
				\newline
			\item\textbf{Extend the query of \texttt{i} to also count outgoing
				\texttt{OFFICER\_OF} edges to determine the top intermediaries.
				Output the name of the intermediary as well as the number of
				relevant edges.}
				\begin{lstlisting}[style=command]
MATCH (n:Intermediary)-[r:INTERMEDIARY_OF|OFFICER_OF]->()
RETURN n.name AS name, COUNT(r) AS count ORDER BY count DESC LIMIT 10
				\end{lstlisting}
				\input{results/result_3b2.tex}
				\newline
				\newline
			\item\textbf{For the top intermediary from query \texttt{ii},
				output all the outgoing edges, except for those that have type
				either \texttt{OFFICER\_OF} or \texttt{INTERMEDIARY\_OF}. Also
				output the respective nodes at the other side of the edges.}
				\begin{lstlisting}[style=command]
MATCH (n:Intermediary {node_id: "54662"})-[r]->(t)
	WHERE NOT (n)-[r:INTERMEDIARY_OF|OFFICER_OF]->(t)
RETURN type(r) AS relation, t.node_id AS node
				\end{lstlisting}
				\input{results/result_3b3.tex}
				\newline
				\newline
		\end{enumerate}
	\item\textbf{Find a shortest \textit{undirected} path between an Address in
		Luxembourg and an Address in Cyprus where the path has a length of at
		least 16 and at most 30.}
		% TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		% !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		% MATCH p=(lux:Address{countries:"Luxembourg"})-[*10]-(cyp:Address{countries:"Cyprus"}) RETURN p LIMIT 5
	\item\textbf{Find one (use \texttt{LIMIT 1}) subgraph of the form specied
		in Figure 4 in the database.
		Furthermore, the two entities should be in dierent countries and at
		least one of the entities should have dierent values in its
		\texttt{jurisdiction} and \texttt{country\_codes} attributes.}
		\begin{lstlisting}[style=command]
MATCH (i:Intermediary)-[]->(e1:Entity)<-[]-(o:Officer)-[]->(e2:Entity)<-[]-(i:Intermediary)
	WHERE e1 <> e2
	AND e1.countries <> e2.countries
	AND (e1.jurisdiction <> e1.country_codes
		OR e2.jurisdiction <> e2.country_codes)
RETURN i, e1, e2, o
LIMIT 1
		\end{lstlisting}
		\includegraphics{results/result_3d.png}
		\newline
		\newline
	\item\textbf{For the final task we want to make the
		\texttt{countries} attribute a real part of the
		graph.  The best way to do this is in Neo4j is
		using the \texttt{MERGE} keyword inside of a
		\texttt{MATCH} . The task is restricted to the
		nodes with label \texttt{Other} to avoid
		processing an unnecessarily large amount of data.}
		\begin{lstlisting}[style=command]
MATCH (other:Other) WHERE exists(other.countries)
MERGE (country:Country { name: other.countries })
MERGE (other)-[r:IN_COUNTRY]->(country)
		\end{lstlisting}
		\begin{lstlisting}[style=command]
MATCH (c:Country{ name:"Bermuda" }) RETURN c
		\end{lstlisting}
		\includegraphics{results/result_3d.png}
\end{enumerate}
