Skip to content

Commit 59b8001

Browse files
authored
Update ArangoRDF doc page (#375)
1 parent 5a1f9e5 commit 59b8001

File tree

3 files changed

+150
-140
lines changed
  • site/content
    • 3.10/data-science/adapters/arangordf-adapter
    • 3.11/data-science/adapters/arangordf-adapter
    • 3.12/data-science/adapters/arangordf-adapter

3 files changed

+150
-140
lines changed

site/content/3.10/data-science/adapters/arangordf-adapter/_index.md

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,14 @@ the named link between two resources, represented by the graph nodes. This graph
2121
view is the easiest possible mental model for RDF and is often used in
2222
easy-to-understand visual explanations.
2323

24-
Check the resources below to get started:
24+
## Resources
2525

26+
- [ArangoRDF repository](https://github.com/ArangoDB-Community/ArangoRDF),
27+
available on GitHub
2628
- [RDF Primer](https://www.w3.org/TR/rdf11-concepts/)
2729
- [RDFLib (Python)](https://pypi.org/project/rdflib/)
2830
- [Example for Modeling RDF as ArangoDB Graphs](mapping-rdf-to-graphs.md)
2931

30-
## Resources
31-
32-
Watch this
33-
[lunch & learn session](https://www.arangodb.com/resources/lunch-sessions/graph-beyond-lunch-break-2-11-arangordf/) to get an
34-
introduction on ArangoRDF - an RDF adapter developed with the community
35-
as a first step at bringing RDF graphs into ArangoDB.
36-
37-
The [ArangoRDF repository](https://github.com/ArangoDB-Community/ArangoRDF)
38-
is available on Github. Check it out!
3932

4033
## Installation
4134

@@ -53,55 +46,66 @@ Check also the
5346
[interactive tutorial](https://colab.research.google.com/github/ArangoDB-Community/ArangoRDF/blob/main/examples/ArangoRDF.ipynb).
5447

5548
```py
49+
from rdflib import Graph
5650
from arango import ArangoClient
5751
from arango_rdf import ArangoRDF
5852

59-
db = ArangoClient(hosts="http://localhost:8529").db(
60-
"rdf", username="root", password="openSesame"
61-
)
53+
db = ArangoClient(hosts="http://localhost:8529").db("_system_", username="root", password="")
6254

63-
# Clean up existing data and collections
64-
if db.has_graph("default_graph"):
65-
db.delete_graph("default_graph", drop_collections=True, ignore_missing=True)
55+
adbrdf = ArangoRDF(db)
6656

67-
# Initializes default_graph and sets RDF graph identifier (ArangoDB sub_graph)
68-
# Optional: sub_graph (stores graph name as the 'graph' attribute on all edges in Statement collection)
69-
# Optional: default_graph (name of ArangoDB Named Graph, defaults to 'default_graph',
70-
# is root graph that contains all collections/relations)
71-
adb_rdf = ArangoRDF(db, sub_graph="http://data.sfgov.org/ontology")
72-
config = {"normalize_literals": False} # default: False
57+
g = Graph()
58+
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")
7359

74-
# RDF Import
75-
adb_rdf.init_rdf_collections(bnode="Blank")
60+
###################
61+
# RDF to ArangoDB #
62+
###################
7663

77-
# Start with importing the ontology
78-
adb_graph = adb_rdf.import_rdf("./examples/data/airport-ontology.owl", format="xml", config=config, save_config=True)
64+
# 1.1: RDF-Topology Preserving Transformation (RPT)
65+
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, overwrite_graph=True)
7966

80-
# Next, let's import the actual graph data
81-
adb_graph = adb_rdf.import_rdf(f"./examples/data/sfo-aircraft-partial.ttl", format="ttl", config=config, save_config=True)
67+
# 1.2: Property Graph Transformation (PGT)
68+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, overwrite_graph=True)
8269

70+
g = adbrdf.load_meta_ontology(g)
8371

84-
# RDF Export
85-
# WARNING:
86-
# Exports ALL collections of the database,
87-
# currently does not account for default_graph or sub_graph
88-
# Results may vary, minifying may occur
89-
rdf_graph = adb_rdf.export_rdf(f"./examples/data/rdfExport.xml", format="xml")
72+
# 1.3: RPT w/ Graph Contextualization
73+
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, contextualize_graph=True, overwrite_graph=True)
9074

91-
# Drop graph and ALL documents and collections to test import from exported data
92-
if db.has_graph("default_graph"):
93-
db.delete_graph("default_graph", drop_collections=True, ignore_missing=True)
75+
# 1.4: PGT w/ Graph Contextualization
76+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, contextualize_graph=True, overwrite_graph=True)
9477

95-
# Re-initialize our RDF Graph
96-
# Initializes default_graph and sets RDF graph identifier (ArangoDB sub_graph)
97-
adb_rdf = ArangoRDF(db, sub_graph="http://data.sfgov.org/ontology")
78+
# 1.5: PGT w/ ArangoDB Document-to-Collection Mapping Exposed
79+
adb_mapping = adbrdf.build_adb_mapping_for_pgt(g)
80+
print(adb_mapping.serialize())
81+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, adb_mapping, contextualize_graph=True, overwrite_graph=True)
9882

99-
adb_rdf.init_rdf_collections(bnode="Blank")
83+
###################
84+
# ArangoDB to RDF #
85+
###################
86+
87+
# Start from scratch!
88+
g = Graph()
89+
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")
90+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, overwrite_graph=True)
91+
92+
# 2.1: Via Graph Name
93+
g2, adb_mapping_2 = adbrdf.arangodb_graph_to_rdf("Beatles", Graph())
94+
95+
# 2.2: Via Collection Names
96+
g3, adb_mapping_3 = adbrdf.arangodb_collections_to_rdf(
97+
"Beatles",
98+
Graph(),
99+
v_cols={"Album", "Band", "Class", "Property", "SoloArtist", "Song"},
100+
e_cols={"artist", "member", "track", "type", "writer"},
101+
)
100102

101-
config = adb_rdf.get_config_by_latest() # gets the last config saved
102-
# config = adb_rdf.get_config_by_key_value('graph', 'music')
103-
# config = adb_rdf.get_config_by_key_value('AnyKeySuppliedInConfig', 'SomeValue')
103+
print(len(g2), len(adb_mapping_2))
104+
print(len(g3), len(adb_mapping_3))
104105

105-
# Re-import Exported data
106-
adb_graph = adb_rdf.import_rdf(f"./examples/data/rdfExport.xml", format="xml", config=config)
106+
print('--------------------')
107+
print(g2.serialize())
108+
print('--------------------')
109+
print(adb_mapping_2.serialize())
110+
print('--------------------')
107111
```

site/content/3.11/data-science/adapters/arangordf-adapter/_index.md

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,14 @@ the named link between two resources, represented by the graph nodes. This graph
2121
view is the easiest possible mental model for RDF and is often used in
2222
easy-to-understand visual explanations.
2323

24-
Check the resources below to get started:
24+
## Resources
2525

26+
- [ArangoRDF repository](https://github.com/ArangoDB-Community/ArangoRDF),
27+
available on GitHub
2628
- [RDF Primer](https://www.w3.org/TR/rdf11-concepts/)
2729
- [RDFLib (Python)](https://pypi.org/project/rdflib/)
2830
- [Example for Modeling RDF as ArangoDB Graphs](mapping-rdf-to-graphs.md)
2931

30-
## Resources
31-
32-
Watch this
33-
[lunch & learn session](https://www.arangodb.com/resources/lunch-sessions/graph-beyond-lunch-break-2-11-arangordf/) to get an
34-
introduction on ArangoRDF - an RDF adapter developed with the community
35-
as a first step at bringing RDF graphs into ArangoDB.
36-
37-
The [ArangoRDF repository](https://github.com/ArangoDB-Community/ArangoRDF)
38-
is available on Github. Check it out!
39-
4032
## Installation
4133

4234
To install the latest release of ArangoRDF,
@@ -53,55 +45,66 @@ Check also the
5345
[interactive tutorial](https://colab.research.google.com/github/ArangoDB-Community/ArangoRDF/blob/main/examples/ArangoRDF.ipynb).
5446

5547
```py
48+
from rdflib import Graph
5649
from arango import ArangoClient
5750
from arango_rdf import ArangoRDF
5851

59-
db = ArangoClient(hosts="http://localhost:8529").db(
60-
"rdf", username="root", password="openSesame"
61-
)
52+
db = ArangoClient(hosts="http://localhost:8529").db("_system_", username="root", password="")
53+
54+
adbrdf = ArangoRDF(db)
55+
56+
g = Graph()
57+
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")
6258

63-
# Clean up existing data and collections
64-
if db.has_graph("default_graph"):
65-
db.delete_graph("default_graph", drop_collections=True, ignore_missing=True)
59+
###################
60+
# RDF to ArangoDB #
61+
###################
6662

67-
# Initializes default_graph and sets RDF graph identifier (ArangoDB sub_graph)
68-
# Optional: sub_graph (stores graph name as the 'graph' attribute on all edges in Statement collection)
69-
# Optional: default_graph (name of ArangoDB Named Graph, defaults to 'default_graph',
70-
# is root graph that contains all collections/relations)
71-
adb_rdf = ArangoRDF(db, sub_graph="http://data.sfgov.org/ontology")
72-
config = {"normalize_literals": False} # default: False
63+
# 1.1: RDF-Topology Preserving Transformation (RPT)
64+
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, overwrite_graph=True)
7365

74-
# RDF Import
75-
adb_rdf.init_rdf_collections(bnode="Blank")
66+
# 1.2: Property Graph Transformation (PGT)
67+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, overwrite_graph=True)
7668

77-
# Start with importing the ontology
78-
adb_graph = adb_rdf.import_rdf("./examples/data/airport-ontology.owl", format="xml", config=config, save_config=True)
69+
g = adbrdf.load_meta_ontology(g)
7970

80-
# Next, let's import the actual graph data
81-
adb_graph = adb_rdf.import_rdf(f"./examples/data/sfo-aircraft-partial.ttl", format="ttl", config=config, save_config=True)
71+
# 1.3: RPT w/ Graph Contextualization
72+
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, contextualize_graph=True, overwrite_graph=True)
8273

74+
# 1.4: PGT w/ Graph Contextualization
75+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, contextualize_graph=True, overwrite_graph=True)
8376

84-
# RDF Export
85-
# WARNING:
86-
# Exports ALL collections of the database,
87-
# currently does not account for default_graph or sub_graph
88-
# Results may vary, minifying may occur
89-
rdf_graph = adb_rdf.export_rdf(f"./examples/data/rdfExport.xml", format="xml")
77+
# 1.5: PGT w/ ArangoDB Document-to-Collection Mapping Exposed
78+
adb_mapping = adbrdf.build_adb_mapping_for_pgt(g)
79+
print(adb_mapping.serialize())
80+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, adb_mapping, contextualize_graph=True, overwrite_graph=True)
9081

91-
# Drop graph and ALL documents and collections to test import from exported data
92-
if db.has_graph("default_graph"):
93-
db.delete_graph("default_graph", drop_collections=True, ignore_missing=True)
82+
###################
83+
# ArangoDB to RDF #
84+
###################
9485

95-
# Re-initialize our RDF Graph
96-
# Initializes default_graph and sets RDF graph identifier (ArangoDB sub_graph)
97-
adb_rdf = ArangoRDF(db, sub_graph="http://data.sfgov.org/ontology")
86+
# Start from scratch!
87+
g = Graph()
88+
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")
89+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, overwrite_graph=True)
9890

99-
adb_rdf.init_rdf_collections(bnode="Blank")
91+
# 2.1: Via Graph Name
92+
g2, adb_mapping_2 = adbrdf.arangodb_graph_to_rdf("Beatles", Graph())
93+
94+
# 2.2: Via Collection Names
95+
g3, adb_mapping_3 = adbrdf.arangodb_collections_to_rdf(
96+
"Beatles",
97+
Graph(),
98+
v_cols={"Album", "Band", "Class", "Property", "SoloArtist", "Song"},
99+
e_cols={"artist", "member", "track", "type", "writer"},
100+
)
100101

101-
config = adb_rdf.get_config_by_latest() # gets the last config saved
102-
# config = adb_rdf.get_config_by_key_value('graph', 'music')
103-
# config = adb_rdf.get_config_by_key_value('AnyKeySuppliedInConfig', 'SomeValue')
102+
print(len(g2), len(adb_mapping_2))
103+
print(len(g3), len(adb_mapping_3))
104104

105-
# Re-import Exported data
106-
adb_graph = adb_rdf.import_rdf(f"./examples/data/rdfExport.xml", format="xml", config=config)
105+
print('--------------------')
106+
print(g2.serialize())
107+
print('--------------------')
108+
print(adb_mapping_2.serialize())
109+
print('--------------------')
107110
```

site/content/3.12/data-science/adapters/arangordf-adapter/_index.md

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,14 @@ the named link between two resources, represented by the graph nodes. This graph
2121
view is the easiest possible mental model for RDF and is often used in
2222
easy-to-understand visual explanations.
2323

24-
Check the resources below to get started:
24+
## Resources
2525

26+
- [ArangoRDF repository](https://github.com/ArangoDB-Community/ArangoRDF),
27+
available on GitHub
2628
- [RDF Primer](https://www.w3.org/TR/rdf11-concepts/)
2729
- [RDFLib (Python)](https://pypi.org/project/rdflib/)
2830
- [Example for Modeling RDF as ArangoDB Graphs](mapping-rdf-to-graphs.md)
2931

30-
## Resources
31-
32-
Watch this
33-
[lunch & learn session](https://www.arangodb.com/resources/lunch-sessions/graph-beyond-lunch-break-2-11-arangordf/) to get an
34-
introduction on ArangoRDF - an RDF adapter developed with the community
35-
as a first step at bringing RDF graphs into ArangoDB.
36-
37-
The [ArangoRDF repository](https://github.com/ArangoDB-Community/ArangoRDF)
38-
is available on Github. Check it out!
39-
4032
## Installation
4133

4234
To install the latest release of ArangoRDF,
@@ -53,55 +45,66 @@ Check also the
5345
[interactive tutorial](https://colab.research.google.com/github/ArangoDB-Community/ArangoRDF/blob/main/examples/ArangoRDF.ipynb).
5446

5547
```py
48+
from rdflib import Graph
5649
from arango import ArangoClient
5750
from arango_rdf import ArangoRDF
5851

59-
db = ArangoClient(hosts="http://localhost:8529").db(
60-
"rdf", username="root", password="openSesame"
61-
)
52+
db = ArangoClient(hosts="http://localhost:8529").db("_system_", username="root", password="")
53+
54+
adbrdf = ArangoRDF(db)
55+
56+
g = Graph()
57+
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")
6258

63-
# Clean up existing data and collections
64-
if db.has_graph("default_graph"):
65-
db.delete_graph("default_graph", drop_collections=True, ignore_missing=True)
59+
###################
60+
# RDF to ArangoDB #
61+
###################
6662

67-
# Initializes default_graph and sets RDF graph identifier (ArangoDB sub_graph)
68-
# Optional: sub_graph (stores graph name as the 'graph' attribute on all edges in Statement collection)
69-
# Optional: default_graph (name of ArangoDB Named Graph, defaults to 'default_graph',
70-
# is root graph that contains all collections/relations)
71-
adb_rdf = ArangoRDF(db, sub_graph="http://data.sfgov.org/ontology")
72-
config = {"normalize_literals": False} # default: False
63+
# 1.1: RDF-Topology Preserving Transformation (RPT)
64+
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, overwrite_graph=True)
7365

74-
# RDF Import
75-
adb_rdf.init_rdf_collections(bnode="Blank")
66+
# 1.2: Property Graph Transformation (PGT)
67+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, overwrite_graph=True)
7668

77-
# Start with importing the ontology
78-
adb_graph = adb_rdf.import_rdf("./examples/data/airport-ontology.owl", format="xml", config=config, save_config=True)
69+
g = adbrdf.load_meta_ontology(g)
7970

80-
# Next, let's import the actual graph data
81-
adb_graph = adb_rdf.import_rdf(f"./examples/data/sfo-aircraft-partial.ttl", format="ttl", config=config, save_config=True)
71+
# 1.3: RPT w/ Graph Contextualization
72+
adbrdf.rdf_to_arangodb_by_rpt("Beatles", g, contextualize_graph=True, overwrite_graph=True)
8273

74+
# 1.4: PGT w/ Graph Contextualization
75+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, contextualize_graph=True, overwrite_graph=True)
8376

84-
# RDF Export
85-
# WARNING:
86-
# Exports ALL collections of the database,
87-
# currently does not account for default_graph or sub_graph
88-
# Results may vary, minifying may occur
89-
rdf_graph = adb_rdf.export_rdf(f"./examples/data/rdfExport.xml", format="xml")
77+
# 1.5: PGT w/ ArangoDB Document-to-Collection Mapping Exposed
78+
adb_mapping = adbrdf.build_adb_mapping_for_pgt(g)
79+
print(adb_mapping.serialize())
80+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, adb_mapping, contextualize_graph=True, overwrite_graph=True)
9081

91-
# Drop graph and ALL documents and collections to test import from exported data
92-
if db.has_graph("default_graph"):
93-
db.delete_graph("default_graph", drop_collections=True, ignore_missing=True)
82+
###################
83+
# ArangoDB to RDF #
84+
###################
9485

95-
# Re-initialize our RDF Graph
96-
# Initializes default_graph and sets RDF graph identifier (ArangoDB sub_graph)
97-
adb_rdf = ArangoRDF(db, sub_graph="http://data.sfgov.org/ontology")
86+
# Start from scratch!
87+
g = Graph()
88+
g.parse("https://raw.githubusercontent.com/stardog-union/stardog-tutorials/master/music/beatles.ttl")
89+
adbrdf.rdf_to_arangodb_by_pgt("Beatles", g, overwrite_graph=True)
9890

99-
adb_rdf.init_rdf_collections(bnode="Blank")
91+
# 2.1: Via Graph Name
92+
g2, adb_mapping_2 = adbrdf.arangodb_graph_to_rdf("Beatles", Graph())
93+
94+
# 2.2: Via Collection Names
95+
g3, adb_mapping_3 = adbrdf.arangodb_collections_to_rdf(
96+
"Beatles",
97+
Graph(),
98+
v_cols={"Album", "Band", "Class", "Property", "SoloArtist", "Song"},
99+
e_cols={"artist", "member", "track", "type", "writer"},
100+
)
100101

101-
config = adb_rdf.get_config_by_latest() # gets the last config saved
102-
# config = adb_rdf.get_config_by_key_value('graph', 'music')
103-
# config = adb_rdf.get_config_by_key_value('AnyKeySuppliedInConfig', 'SomeValue')
102+
print(len(g2), len(adb_mapping_2))
103+
print(len(g3), len(adb_mapping_3))
104104

105-
# Re-import Exported data
106-
adb_graph = adb_rdf.import_rdf(f"./examples/data/rdfExport.xml", format="xml", config=config)
105+
print('--------------------')
106+
print(g2.serialize())
107+
print('--------------------')
108+
print(adb_mapping_2.serialize())
109+
print('--------------------')
107110
```

0 commit comments

Comments
 (0)