]> git.somenet.org - pub/jan/adbs.git/blob - ex3/main_3.tex
more ex3.3
[pub/jan/adbs.git] / ex3 / main_3.tex
1 %ex3.3
2
3 \begin{enumerate}[label=(\alph*),leftmargin=2\parindent]
4         \item\textbf{Two basic queries to start with:}
5         \begin{itemize}
6                 \item\textbf{List all the distinct countries for which addresses are
7                         registered in the database.}
8                         \begin{lstlisting}[style=command]
9 MATCH (n:Address) RETURN DISTINCT n.countries AS countries
10                         \end{lstlisting}
11                         This returns 222 different countries. We chose ''Austria''.
12                         \newline
13                         \newline
14                 \item\textbf{Choose one of these countries and list 5 entities which
15                         are based in that country.}
16                         \begin{lstlisting}[style=command]
17 MATCH (n:Address {countries: 'Austria'})<-[r:REGISTERED_ADDRESS]-(e:Entity)
18 RETURN DISTINCT e AS entity LIMIT 5
19                         \end{lstlisting}
20                         \input{results/result_3a.tex}
21                         \newline
22                         \newline
23         \end{itemize}
24         \item
25                 \begin{enumerate}[label=\roman*,leftmargin=1\parindent]
26                         \item\textbf{First, find the 10 \texttt{top intermediaries} , i.e.
27                                 those 10 intermediaries that have the most outgoing
28                                 \texttt{INTERMEDIARY\_OF} edges. Output the name of the
29                                 intermediary as well as the number of relevant edges.}
30                                 \begin{lstlisting}[style=command]
31 MATCH (n:Intermediary)-[r:INTERMEDIARY_OF]->()
32 RETURN n.name AS name, COUNT(r) AS count ORDER BY count DESC LIMIT 10
33                                 \end{lstlisting}
34                                 \input{results/result_3b1.tex}
35                                 \newline
36                                 \newline
37                         \item\textbf{Extend the query of \texttt{i} to also count outgoing
38                                 \texttt{OFFICER\_OF} edges to determine the top intermediaries.
39                                 Output the name of the intermediary as well as the number of
40                                 relevant edges.}
41                                 \begin{lstlisting}[style=command]
42 MATCH (n:Intermediary)-[r:INTERMEDIARY_OF|OFFICER_OF]->()
43 RETURN n.name AS name, COUNT(r) AS count ORDER BY count DESC LIMIT 10
44                                 \end{lstlisting}
45                                 \input{results/result_3b2.tex}
46                                 \newline
47                                 \newline
48                         \item\textbf{For the top intermediary from query \texttt{ii},
49                                 output all the outgoing edges, except for those that have type
50                                 either \texttt{OFFICER\_OF} or \texttt{INTERMEDIARY\_OF}. Also
51                                 output the respective nodes at the other side of the edges.}
52                                 \begin{lstlisting}[style=command]
53 MATCH (n:Intermediary {node_id: "54662"})-[r]->(t)
54         WHERE NOT (n)-[r:INTERMEDIARY_OF|OFFICER_OF]->(t)
55 RETURN type(r) AS relation, t.node_id AS node
56                                 \end{lstlisting}
57                                 \input{results/result_3b3.tex}
58                                 \newline
59                                 \newline
60                 \end{enumerate}
61         \item\textbf{Find a shortest \textit{undirected} path between an Address in
62                 Luxembourg and an Address in Cyprus where the path has a length of at
63                 least 16 and at most 30.}
64                 % TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
65                 % !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
66                 % MATCH p=(lux:Address{countries:"Luxembourg"})-[*10]-(cyp:Address{countries:"Cyprus"}) RETURN p LIMIT 5
67         \item\textbf{Find one (use \texttt{LIMIT 1}) subgraph of the form specied
68                 in Figure 4 in the database.
69                 Furthermore, the two entities should be in dierent countries and at
70                 least one of the entities should have dierent values in its
71                 \texttt{jurisdiction} and \texttt{country\_codes} attributes.}
72                 \begin{lstlisting}[style=command]
73 MATCH (i:Intermediary)-->(e1:Entity)<--(o:Officer)-->(e2:Entity)<--(i:Intermediary)
74         WHERE e1 <> e2
75         AND e1.countries <> e2.countries
76         AND (e1.jurisdiction <> e1.country_codes
77                 OR e2.jurisdiction <> e2.country_codes)
78 RETURN i, e1, e2, o
79 LIMIT 1
80                 \end{lstlisting}
81                 \begin{figure}[H]
82                         \centering
83                         \includegraphics[width=6cm]{results/result_3d.png}
84                 \end{figure}
85         \item\textbf{For the final task we want to make the
86                 \texttt{countries} attribute a real part of the
87                 graph.  The best way to do this is in Neo4j is
88                 using the \texttt{MERGE} keyword inside of a
89                 \texttt{MATCH} . The task is restricted to the
90                 nodes with label \texttt{Other} to avoid
91                 processing an unnecessarily large amount of data.}
92                 \begin{lstlisting}[style=command]
93 MATCH (other:Other) WHERE exists(other.countries)
94 MERGE (country:Country { name: other.countries })
95 MERGE (other)-[r:IN_COUNTRY]->(country)
96                 \end{lstlisting}
97                 \input{results/result_3e.tex}
98                 \begin{lstlisting}[style=command]
99 MATCH (c:Country{ name:"Bermuda" }) RETURN c
100                 \end{lstlisting}
101                 \begin{figure}[H]
102                         \centering
103                         \includegraphics[width=5cm]{results/result_3e.png}
104                 \end{figure}
105 \end{enumerate}