创建海王星 GraphMappingConfig - Amazon Neptune

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建海王星 GraphMappingConfig

您创建的 GraphMappingConfig 指定如何将从源数据存储中提取的数据加载到 Neptune 数据库集群中。它的格式根据要加载 RDF 数据还是要加载属性图数据而有所不同。

对于 RDF 数据,您可以使用 W3 R2RML 语言,将关系数据映射到 RDF。

如果要加载将使用 Gremlin 查询的属性图数据,则为 GraphMappingConfig 创建 JSON 对象。

GraphMappingConfig RDF/SPARQL 数据的布局

如果您正在使用 SPARQL 加载要查询的 RDF 数据,您可以在 R2RML 中编写 GraphMappingConfigR2RML 是一种标准 W3 语言,用于将关系数据映射到 RDF。示例如下:

@prefix rr: <http://www.w3.org/ns/r2rml#> . @prefix ex: <http://example.com/ns#> . <#TriplesMap1> rr:logicalTable [ rr:tableName "nodes" ]; rr:subjectMap [ rr:template "http://data.example.com/employee/{id}"; rr:class ex:Employee; ]; rr:predicateObjectMap [ rr:predicate ex:name; rr:objectMap [ rr:column "label" ]; ] .

以下是另一个示例:

@prefix rr: <http://www.w3.org/ns/r2rml#> . @prefix ex: <http://example.com/#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . <#TriplesMap2> rr:logicalTable [ rr:tableName "Student" ]; rr:subjectMap [ rr:template "http://example.com/{ID}{Name}"; rr:class foaf:Person ]; rr:predicateObjectMap [ rr:predicate ex:id ; rr:objectMap [ rr:column "ID"; rr:datatype xsd:integer ] ]; rr:predicateObjectMap [ rr:predicate foaf:name ; rr:objectMap [ rr:column "Name" ] ] .

位于 R2RML:RDB 到 RDF 映射语言的 W3 推荐提供了语言的详细信息。

GraphMappingConfig Property-Graph/Gremlin 数据的布局

与属性图形数据相当的 GraphMappingConfig 是一个 JSON 对象,该对象为要从源数据生成的每个图形实体提供映射规则。以下模板显示了此对象中的各个规则的情况:

{ "rules": [ { "rule_id": "(an identifier for this rule)", "rule_name": "(a name for this rule)", "table_name": "(the name of the table or view being loaded)", "vertex_definitions": [ { "vertex_id_template": "{col1}", "vertex_label": "(the vertex to create)", "vertex_definition_id": "(an identifier for this vertex)", "vertex_properties": [ { "property_name": "(name of the property)", "property_value_template": "{col2} or text", "property_value_type": "(data type of the property)" } ] } ] }, { "rule_id": "(an identifier for this rule)", "rule_name": "(a name for this rule)", "table_name": "(the name of the table or view being loaded)", "edge_definitions": [ { "from_vertex": { "vertex_id_template": "{col1}", "vertex_definition_id": "(an identifier for the vertex referenced above)" }, "to_vertex": { "vertex_id_template": "{col3}", "vertex_definition_id": "(an identifier for the vertex referenced above)" }, "edge_id_template": { "label": "(the edge label to add)", "template": "{col1}_{col3}" }, "edge_properties":[ { "property_name": "(the property to add)", "property_value_template": "{col4} or text", "property_value_type": "(data type like String, int, double)" } ] } ] } ] }

请注意,顶点标签的存在意味着在这里创建了顶点,而没有顶点标签则意味着顶点由不同的源创建,而此定义仅添加顶点属性。

以下是员工记录的示例规则:

{ "rules": [ { "rule_id": "1", "rule_name": "vertex_mapping_rule_from_nodes", "table_name": "nodes", "vertex_definitions": [ { "vertex_id_template": "{emp_id}", "vertex_label": "employee", "vertex_definition_id": "1", "vertex_properties": [ { "property_name": "name", "property_value_template": "{emp_name}", "property_value_type": "String" } ] } ] }, { "rule_id": "2", "rule_name": "edge_mapping_rule_from_emp", "table_name": "nodes", "edge_definitions": [ { "from_vertex": { "vertex_id_template": "{emp_id}", "vertex_definition_id": "1" }, "to_vertex": { "vertex_id_template": "{mgr_id}", "vertex_definition_id": "1" }, "edge_id_template": { "label": "reportsTo", "template": "{emp_id}_{mgr_id}" }, "edge_properties":[ { "property_name": "team", "property_value_template": "{team}", "property_value_type": "String" } ] } ] } ] }