Repository navigation
Expand file tree
/
Copy pathQuery.java
More file actions
60 lines (47 loc) · 2.11 KB
/
Copy pathQuery.java
File metadata and controls
60 lines (47 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package datomic.samples;
import datomic.Connection;
import datomic.Database;
import datomic.Peer;
import java.util.Scanner;
import java.util.Collection;
import static datomic.Util.read;
import static datomic.samples.Fns.scratchConnection;
import static datomic.samples.Schema.CARDINALITY_MANY;
import static datomic.samples.Schema.CARDINALITY_ONE;
import static datomic.samples.Schema.cardinality;
public class Query {
public static void main(String[] args) {
// Your connection information for local mbrainz 1968-1973 subset goes here.
String uri = "datomic:free://localhost:4334/mbrainz-1968-1973";
// Connect to transactor, get latest database value from storage.
Connection conn = Peer.connect(uri);
Database db = conn.db();
System.out.println("All releases in the database with release names.");
Collection results = Peer.query("[:find ?release-name :where [_ :release/name ?release-name]]", db);
System.out.println(results);
pause();
System.out.println("Total number of artists without :artist/country attribute.");
Long res = Peer.query("[:find (count ?eid) ." +
":where [?eid :artist/name] " +
"(not [?eid :artist/country])]",
db);
System.out.println(res);
pause();
System.out.println("Number of artists missing either country or gender. "+
"(negation of conjunction reads 'not (clause1 and clause2)'");
res = Peer.query("[:find (count ?eid) . " +
":where [?eid :artist/name] " +
"(not [?eid :artist/country] " +
"[?eid :artist/gender])]",
db);
System.out.println(res);
pause();
}
private static final Scanner scanner = new Scanner(System.in);
private static void pause() {
if (System.getProperty("NOPAUSE") == null) {
System.out.println("\nPress enter to continue...");
scanner.nextLine();
}
}
}