]> git.somenet.org - pub/jan/adbs.git/blob - ex3/main_3.tex
GITOLITE.txt
[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
65                 \begin{lstlisting}[style=command]
66 MATCH p=shortestPath((lux:Address{countries:"Luxembourg"})-[*1..30]-(cyp:Address{countries:"Cyprus"}))
67 WITH *, length(p) AS len WHERE len >= 16 AND len < 17
68 //RETURN lux, cyp, len LIMIT 10
69 RETURN p LIMIT 1
70                 \end{lstlisting}
71
72                 Adjusting the values only produced different graphs, but there were
73                 always more than 10 paths available.
74                 One of these graphs we included, to show at least one result.
75
76                 \input{results/result_3c.tex}
77
78                 \begin{figure}[H]
79                         \centering
80                         \includegraphics[width=12cm]{results/result_3c.png}
81                 \end{figure}
82         \item\textbf{Find one (use \texttt{LIMIT 1}) subgraph of the form specied
83                 in Figure 4 in the database.
84                 Furthermore, the two entities should be in different countries and at
85                 least one of the entities should have different values in its
86                 \texttt{jurisdiction} and \texttt{country\_codes} attributes.}
87                 \begin{lstlisting}[style=command]
88 MATCH (i:Intermediary)-->(e1:Entity)<--(o:Officer)-->(e2:Entity)<--(i:Intermediary)
89         WHERE e1 <> e2
90         AND e1.countries <> e2.countries
91         AND (e1.jurisdiction <> e1.country_codes
92                 OR e2.jurisdiction <> e2.country_codes)
93 RETURN i, e1, e2, o
94 LIMIT 1
95                 \end{lstlisting}
96                 \begin{figure}[H]
97                         \centering
98                         \includegraphics[width=6cm]{results/result_3d.png}
99                 \end{figure}
100         \item\textbf{For the final task we want to make the \texttt{countries}
101                 attribute a real part of the graph.
102                 The best way to do this is in Neo4j is using the \texttt{MERGE} keyword
103                 inside of a \texttt{MATCH}. The task is restricted to the nodes with
104                 label \texttt{Other} to avoid processing an unnecessarily large amount
105                 of data.}
106                 \begin{lstlisting}[style=command]
107 MATCH (other:Other) WHERE exists(other.countries)
108 MERGE (country:Country { name: other.countries })
109 MERGE (other)-[r:IN_COUNTRY]->(country)
110                 \end{lstlisting}
111                 \input{results/result_3e.tex}
112                 \begin{lstlisting}[style=command]
113 MATCH (c:Country{ name:"Mauritius" }) RETURN c
114                 \end{lstlisting}
115                 \begin{figure}[H]
116                         \centering
117                         \includegraphics[width=5cm]{results/result_3e.png}
118                 \end{figure}
119 \end{enumerate}