Skip to content

Commit 2afb984

Browse files
Domain-based restructure (#137)
## What is the goal of this PR? We categorize the examples by domain and provide a summary in the top-level readme. In addition, we now benchmark each example in typedb factory in order to keep track of performance changes in typedb. ## What are the changes implemented in this PR? - Top-level README: a link to each example with a summary, and a bit of a restructure; - closes #123; - Domain-based package structure, with one package per domain; - closes #120; - Benchmarks: for most examples just runs the tests 20 times; - closes #124.
1 parent ef14cb0 commit 2afb984

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+269
-164
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ bin/
3939

4040
# NPM
4141
node_modules/
42-
yarn.lock
4342

4443
# Python
4544
__pycache__

.grabl/automation.yml

+90-6
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,124 @@ build:
3333
bazel run //:typedb-extractor -- dist/typedb-all-linux
3434
sudo systemd-run ./dist/typedb-all-linux/typedb server
3535
sleep 60
36-
bazel test //catalogue_of_life:tests --test_output=errors
36+
bazel test //biology/catalogue_of_life:tests --test_output=errors
3737
test-gitapp:
3838
image: vaticle-ubuntu-21.04
3939
command: |
4040
bazel run //:typedb-extractor -- dist/typedb-all-linux
4141
sudo systemd-run ./dist/typedb-all-linux/typedb server
4242
sleep 60
43-
bazel test //github/tests:test-migrator-explorer --test_output=errors
43+
bazel test //software/github/tests:test-migrator-explorer --test_output=errors
4444
test-phone-calls-java:
4545
image: vaticle-ubuntu-21.04
4646
command: |
4747
bazel run //:typedb-extractor -- dist/typedb-all-linux
4848
sudo systemd-run ./dist/typedb-all-linux/typedb server
4949
sleep 60
50-
bazel test //phone_calls/java:test --test_output=errors
50+
bazel test //telecom/phone_calls/java:test --test_output=errors
5151
test-phone-calls-nodejs:
5252
image: vaticle-ubuntu-21.04
5353
command: |
5454
bazel run //:typedb-extractor -- dist/typedb-all-linux
5555
sudo systemd-run ./dist/typedb-all-linux/typedb server
5656
sleep 60
57-
bazel test //phone_calls/nodejs:test --test_output=errors
57+
bazel test //telecom/phone_calls/nodejs:test --test_output=errors
5858
test-phone-calls-python:
5959
image: vaticle-ubuntu-21.04
6060
command: |
6161
pyenv global system
6262
bazel run //:typedb-extractor -- dist/typedb-all-linux
6363
sudo systemd-run ./dist/typedb-all-linux/typedb server
6464
sleep 60
65-
bazel test //phone_calls/python:test --test_output=errors
65+
bazel test //telecom/phone_calls/python:test --test_output=errors
6666
test-xcom:
6767
image: vaticle-ubuntu-21.04
6868
command: |
6969
bazel run //:typedb-extractor -- dist/typedb-all-linux
7070
sudo systemd-run ./dist/typedb-all-linux/typedb server
7171
sleep 60
72-
bazel test //xcom:test --test_output=errors
72+
bazel test //gaming/xcom:test --test_output=errors
73+
performance:
74+
test-performance-typedb-core-server:
75+
machine: 16-core-32-gb
76+
image: vaticle-ubuntu-21.04
77+
type: background
78+
timeout: "30m"
79+
command: |
80+
cat > typedb.service <<- EOM
81+
[Unit]
82+
Description=TypeDB
83+
84+
[Service]
85+
Type=simple
86+
Environment=SERVER_JAVAOPTS=-Xmx16G
87+
ExecStart=/home/grabl/$GRABL_REPO/dist/typedb-all-linux/typedb server
88+
Restart=on-failure
89+
RestartSec=10
90+
KillMode=process
91+
92+
[Install]
93+
WantedBy=multi-user.target
94+
EOM
95+
96+
sudo mv typedb.service /etc/systemd/system/
97+
98+
bazel run //:typedb-extractor -- dist/typedb-all-linux
99+
cd ./dist/typedb-all-linux/
100+
101+
sudo systemctl daemon-reload
102+
sudo systemctl start typedb
103+
export GRABL_EXPORT_PERFORMANCE_TYPEDB_CORE_URI="${HOSTNAME}:1729"
104+
monitor: |
105+
sleep 10s
106+
tail -f -n +1 /home/grabl/$GRABL_REPO/dist/typedb-all-linux/server/logs/typedb.log
107+
benchmark-catalogue-of-life-loader:
108+
machine: 16-core-32-gb
109+
image: vaticle-ubuntu-21.04
110+
dependencies: [test-performance-typedb-core-server]
111+
timeout: "30m"
112+
command: |
113+
bazel run //biology/catalogue_of_life:loader -- --typedb $GRABL_EXPORT_PERFORMANCE_TYPEDB_CORE_URI
114+
benchmark-catalogue-of-life-tests:
115+
image: vaticle-ubuntu-21.04
116+
command: |
117+
bazel run //:typedb-extractor -- dist/typedb-all-linux
118+
sudo systemd-run ./dist/typedb-all-linux/typedb server
119+
sleep 60
120+
bazel test //biology/catalogue_of_life:tests --test_output=errors --runs_per_test=20 --jobs=1
121+
benchmark-gitapp-tests:
122+
image: vaticle-ubuntu-21.04
123+
command: |
124+
bazel run //:typedb-extractor -- dist/typedb-all-linux
125+
sudo systemd-run ./dist/typedb-all-linux/typedb server
126+
sleep 60
127+
bazel test //software/github/tests:test-migrator-explorer --test_output=errors --runs_per_test=20 --jobs=1
128+
benchmark-phone-calls-java-test:
129+
image: vaticle-ubuntu-21.04
130+
command: |
131+
bazel run //:typedb-extractor -- dist/typedb-all-linux
132+
sudo systemd-run ./dist/typedb-all-linux/typedb server
133+
sleep 60
134+
bazel test //telecom/phone_calls/java:test --test_output=errors --runs_per_test=20 --jobs=1
135+
# benchmark-phone-calls-nodejs-test:
136+
# image: vaticle-ubuntu-21.04
137+
# command: |
138+
# bazel run //:typedb-extractor -- dist/typedb-all-linux
139+
# sudo systemd-run ./dist/typedb-all-linux/typedb server
140+
# sleep 60
141+
# bazel test //telecom/phone_calls/nodejs:test --test_output=errors --runs_per_test=20 --jobs=1
142+
benchmark-phone-calls-python-test:
143+
image: vaticle-ubuntu-21.04
144+
command: |
145+
pyenv global system
146+
bazel run //:typedb-extractor -- dist/typedb-all-linux
147+
sudo systemd-run ./dist/typedb-all-linux/typedb server
148+
sleep 60
149+
bazel test //telecom/phone_calls/python:test --test_output=errors --runs_per_test=20 --jobs=1
150+
benchmark-xcom-test:
151+
image: vaticle-ubuntu-21.04
152+
command: |
153+
bazel run //:typedb-extractor -- dist/typedb-all-linux
154+
sudo systemd-run ./dist/typedb-all-linux/typedb server
155+
sleep 60
156+
bazel test //gaming/xcom:test --test_output=errors --runs_per_test=20 --jobs=1

README.md

+54-28
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,69 @@
22

33
[![Grabl](https://grabl.io/api/status/vaticle/typedb-examples/badge.svg)](https://grabl.io/vaticle/typedb-examples)
44

5-
This repository includes examples that showcase usage of TypeDB Clients in reading from and writing to a TypeDB knowledge graph.
5+
This repository includes examples that showcase usage of TypeDB Clients in reading from and writing to a TypeDB
6+
database.
67

7-
## Explore Client Examples
8+
## [Biology: Catalogue of Life](biology/catalogue_of_life)
9+
10+
[Catalogue of Life](https://www.catalogueoflife.org/) is a database of over 4.5 million currently known taxa in biology,
11+
compiled from over a hundred different sources. The example showcases simple data preparation and a sample configuration
12+
file for loading a large taxonomic dataset using [TypeDB Loader.](https://github.com/typedb-osi/typedb-loader)
13+
14+
## [Gaming: XCOM Project](gaming/xcom)
15+
16+
The XCOM 2 example contains a database of interdependent research tasks in the game XCOM 2, featuring automatic
17+
inference of available research based on completed tasks and available items. See [the schema](gaming/xcom/schema.tql)
18+
for the examples of reasoner rules inferring attributes.
19+
20+
## [Software: GitHub](software/github)
21+
22+
The GitHub example showcases migration of heavily interconnected data from a live repository on GitHub or from a Vaticle
23+
GitHub snapshot, and provides a visual interface to explore some sample queries.
24+
25+
## [Telecom: Phone Calls](telecom/phone_calls)
826

927
TypeDB officially supports clients for Java, Node.js and Python. Learn more about [TypeDB Clients](http://docs.vaticle.com/docs/client-api/overview).
1028

11-
### Client Java Examples
12-
- [Phone Calls: Migrate and perform expressive queries using Client Java](phone_calls/java/)
13-
- [XCOM Project: Migrate and perform logical queries on tree-structured game data using Client Java](xcom/)
29+
The Phone Calls example showcases basic migration of a database of customers of a fictional telecom company and calls
30+
they make in various formats (CSV, JSON, and XML) and expressive TypeQL queries using
31+
the [Java,](telecom/phone_calls/java) [Node.js,](telecom/phone_calls/nodejs) and [Python](telecom/phone_calls/python)
32+
clients.
33+
34+
### Data migration
35+
36+
- Java: [CSV](telecom/phone_calls/java/CSVMigration.java) | [JSON](telecom/phone_calls/java/JSONMigration.java)
37+
| [XML](telecom/phone_calls/java/XMLMigration.java)
38+
- Node.js: [CSV](telecom/phone_calls/nodejs/migrateCsv.js) | [JSON](telecom/phone_calls/nodejs/migrateJson.js)
39+
| [XML](telecom/phone_calls/nodejs/migrateXml.js)
40+
- Python: [CSV](telecom/phone_calls/python/migrate_csv.py) | [JSON](telecom/phone_calls/python/migrate_json.py)
41+
| [XML](telecom/phone_calls/python/migrate_xml.py)
42+
43+
### Query examples
1444

15-
### Client Node.js Examples
16-
- [Phone Calls: Migrate and perform expressive queries using Client Node.js](phone_calls/nodejs/)
45+
- [Java](telecom/phone_calls/java/Queries.java)
46+
- [Node.js](telecom/phone_calls/nodejs/queries.js)
47+
- [Python](telecom/phone_calls/python/queries.py)
1748

18-
### Client Python Examples
19-
- [Phone Calls: Migrate and perform expressive queries using Client Python](phone_calls/python/)
49+
## Visualise data using TypeDB Studio
2050

21-
## Explore Use Cases
51+
After loading the data of any of the examples, you can
52+
use [TypeDB Studio](https://github.com/vaticle/typedb-studio/releases) to explore
53+
the graph structure of the database.
2254

23-
### Migrate data to TypeDB:
55+
## TypeDB Bio
2456

25-
#### serialised:
26-
- Java: [CSV](phone_calls/java/CSVMigration.java) | [JSON](phone_calls/java/JSONMigration.java) | [XML](phone_calls/java/XMLMigration.java)
27-
- Node.js: [CSV](phone_calls/nodejs/migrateCsv.js) | [JSON](phone_calls/nodejs/migrateJson.js) | [XML](phone_calls/nodejs/migrateXml.js)
28-
- Python: [CSV](phone_calls/python/migrate_csv.py) | [JSON](phone_calls/python/migrate_json.py) | [XML](phone_calls/python/migrate_xml.py)
57+
[TypeDB Bio](https://github.com/vaticle/typedb-bio) is a collection of knowledge graphs of biomedical data.
2958

30-
### Perform expressive queries:
31-
- [Java](phone_calls/java/Queries.java)
32-
- [Node.js](phone_calls/nodejs/queries.js)
33-
- [Python](phone_calls/python/queries.py)
34-
35-
## Explore TypeDB Bio
36-
[BioGrakn](https://github.com/vaticle/typedb-bio) is a collection of knowledge graphs of biomedical data.
59+
TypeDB Bio provides an intuitive way to query interconnected and heterogeneous biomedical data in one single place. The
60+
schema that models the underlying knowledge graph alongside the descriptive query language, TypeQL, makes writing
61+
complex queries an extremely straightforward and intuitive process. Furthermore, the automated reasoning capability of
62+
TypeDB, allows TypeDB Bio to become an intelligent database of biomedical data that infers implicit knowledge based on
63+
the explicitly stored data. TypeDB Bio can understand biological facts, infer based on new findings and enforce research
64+
constraints, all at query (run) time.
3765

38-
TypeDB Bio provides an intuitive way to query interconnected and heterogeneous biomedical data in one single place. The schema that models the underlying knowledge graph alongside the descriptive query language, TypeQL, makes writing complex queries an extremely straightforward and intuitive process. Furthermore, the automated reasoning capability of TypeDB, allows TypeDB Bio to become an intelligent database of biomedical data that infers implicit knowledge based on the explicitly stored data. TypeDB Bio can understand biological facts, infer based on new findings and enforce research constraints, all at query (run) time.
66+
## TypeDB CTI
3967

40-
## Explore Schemas
41-
- [Catalogue of Life](catalogue_of_life/schema.tql)
42-
- [GitHub](github/schemas)
43-
- [Phone Calls](phone_calls/schema.tql)
44-
- [XCOM](xcom/schema.tql)
68+
[TypeDB CTI](https://github.com/typedb-osi/typedb-cti) is an open source threat intelligence platform for organisations
69+
to store and manage their cyber threat intelligence (CTI) knowledge. It enables threat intel professionals to bring
70+
together their disparate CTI information into one database and find new insights about cyber threats.

WORKSPACE

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pip_install(
142142
# Load python example dependencies
143143
pip_install(
144144
name = "phone_calls_pip",
145-
requirements = "//phone_calls/python:requirements.txt"
145+
requirements = "//telecom/phone_calls/python:requirements.txt"
146146
)
147147

148148
# Load java example dependencies
@@ -151,8 +151,8 @@ load("//dependencies/maven:artifacts.bzl", vaticle_typedb_examples_maven_artifac
151151
# Load nodejs example dependencies
152152
yarn_install(
153153
name = "npm",
154-
package_json = "//phone_calls/nodejs:package.json",
155-
yarn_lock = "//phone_calls/nodejs:yarn.lock"
154+
package_json = "//telecom/phone_calls/nodejs:package.json",
155+
yarn_lock = "//telecom/phone_calls/nodejs:yarn.lock"
156156
)
157157

158158
############################

catalogue_of_life/BUILD renamed to biology/catalogue_of_life/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
java_binary(
2323
name = "loader",
24-
main_class = "com.vaticle.typedb.example.catalogueOfLife.Loader",
24+
main_class = "com.vaticle.typedb.example.biology.catalogueOfLife.Loader",
2525
srcs = ["Loader.java"],
2626
deps = [
2727
"@maven//:com_univocity_univocity_parsers",
@@ -36,7 +36,7 @@ java_binary(
3636

3737
java_test(
3838
name = "tests",
39-
test_class = "com.vaticle.typedb.example.catalogueOfLife.test.CoLTest",
39+
test_class = "com.vaticle.typedb.example.biology.catalogueOfLife.test.CoLTest",
4040
srcs = [
4141
"test/CoLTest.java"
4242
],

catalogue_of_life/Loader.java renamed to biology/catalogue_of_life/Loader.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* under the License.
2020
*/
2121

22-
package com.vaticle.typedb.example.catalogueOfLife;
22+
package com.vaticle.typedb.example.biology.catalogueOfLife;
2323

2424
import com.univocity.parsers.common.record.Record;
2525
import com.univocity.parsers.tsv.TsvParser;
@@ -231,7 +231,7 @@ public static void loadData(Path dataDirectory, CLIOptions options) throws IOExc
231231
}
232232

233233
public static void extractSchema(Path dataDirectory) throws IOException {
234-
InputStream schema = Loader.class.getResourceAsStream("/catalogue_of_life/schema.tql");
234+
InputStream schema = Loader.class.getResourceAsStream("/biology/catalogue_of_life/schema.tql");
235235
if (schema == null) throw new FileNotFoundException("schema.tql not found within the jar!");
236236
Files.copy(schema, dataDirectory.resolve("schema.tql"), StandardCopyOption.REPLACE_EXISTING);
237237
}
@@ -240,7 +240,7 @@ public static Path populateLoaderConfigTemplate(Path dataDirectory) throws IOExc
240240
Path config = dataDirectory.resolve("loader-config.json");
241241

242242
try (FileWriter configWriter = new FileWriter(config.toFile())) {
243-
InputStream template = Loader.class.getResourceAsStream("/catalogue_of_life/loader-config.json.template");
243+
InputStream template = Loader.class.getResourceAsStream("/biology/catalogue_of_life/loader-config.json.template");
244244
if (template == null) throw new FileNotFoundException("loader-config.json.template not found within the jar!");
245245

246246
BufferedReader reader = new BufferedReader(new InputStreamReader(template));
File renamed without changes.
File renamed without changes.

catalogue_of_life/test/CoLTest.java renamed to biology/catalogue_of_life/test/CoLTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
* under the License.
2020
*/
2121

22-
package com.vaticle.typedb.example.catalogueOfLife.test;
22+
package com.vaticle.typedb.example.biology.catalogueOfLife.test;
2323

2424
import com.vaticle.typedb.client.TypeDB;
2525
import com.vaticle.typedb.client.api.TypeDBClient;
2626
import com.vaticle.typedb.client.api.TypeDBOptions;
2727
import com.vaticle.typedb.client.api.TypeDBSession;
2828
import com.vaticle.typedb.client.api.TypeDBTransaction;
29-
import com.vaticle.typedb.example.catalogueOfLife.Loader;
29+
import com.vaticle.typedb.example.biology.catalogueOfLife.Loader;
3030
import com.vaticle.typeql.lang.TypeQL;
3131
import org.junit.AfterClass;
3232
import org.junit.BeforeClass;
@@ -50,7 +50,7 @@ public class CoLTest {
5050

5151
@BeforeClass
5252
public static void loadTestData() throws IOException {
53-
Path dataDirectory = Path.of("catalogue_of_life/test/data");
53+
Path dataDirectory = Path.of("biology/catalogue_of_life/test/data");
5454
Loader.prepareData(dataDirectory);
5555
Loader.loadData(dataDirectory, Loader.parseCLIOptions(new String[]{}).get());
5656

xcom/BUILD renamed to gaming/xcom/BUILD

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ java_library(
4545

4646
java_test(
4747
name = "test",
48-
classpath_resources = ["//xcom/config:logback-xml"],
49-
test_class = "com.vaticle.typedb.example.xcom.XCOMTest",
48+
classpath_resources = ["//gaming/xcom/config:logback-xml"],
49+
test_class = "com.vaticle.typedb.example.gaming.xcom.XCOMTest",
5050
srcs = [
5151
"XCOMTest.java"
5252
],
@@ -68,8 +68,8 @@ java_test(
6868

6969
java_binary(
7070
name = "migration",
71-
classpath_resources = ["//xcom/config:logback-xml"],
72-
main_class = "com.vaticle.typedb.example.xcom.Migration",
71+
classpath_resources = ["//gaming/xcom/config:logback-xml"],
72+
main_class = "com.vaticle.typedb.example.gaming.xcom.Migration",
7373
srcs = ["Migration.java"],
7474
deps = [
7575
"@vaticle_typedb_client_java//:client-java",
@@ -84,8 +84,8 @@ java_binary(
8484

8585
java_binary(
8686
name = "queries",
87-
classpath_resources = ["//xcom/config:logback-xml"],
88-
main_class = "com.vaticle.typedb.example.xcom.Queries",
87+
classpath_resources = ["//gaming/xcom/config:logback-xml"],
88+
main_class = "com.vaticle.typedb.example.gaming.xcom.Queries",
8989
srcs = ["Queries.java", "TransactionMode.java", "ResearchTask.java", "InventoryItem.java", "Result.java"],
9090
deps = [
9191
"@vaticle_typedb_client_java//:client-java",

xcom/InventoryItem.java renamed to gaming/xcom/InventoryItem.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* under the License.
2020
*/
2121

22-
package com.vaticle.typedb.example.xcom;
22+
package com.vaticle.typedb.example.gaming.xcom;
2323

2424
public class InventoryItem {
2525
public InventoryItem(String name, long quantity) {

0 commit comments

Comments
 (0)