@@ -21,22 +21,14 @@ the named link between two resources, represented by the graph nodes. This graph
2121view is the easiest possible mental model for RDF and is often used in
2222easy-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
4234To 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
5649from arango import ArangoClient
5750from 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