创建 Neptune GraphMappingConfig - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

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

创建 Neptune GraphMappingConfig

这些区域有:GraphMappingConfig指定如何将从源数据存储中提取的数据加载到 Neptune 数据库集群中。其格式根据要加载 RDF 数据还是要加载属性图形数据而有所不同。

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

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

RDF/SPARQL 数据的 GraphMappingConfig 布局

如果要加载要使用 SPARQL 查询的 RDF 数据,请编写GraphMappingConfigR2RMLR2RML是用于将关系数据映射到 RDF 的标准 W3 语言。示例如下:

@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" ] ] .

W3 建议,请访问R2 毫升:RDB 到 RDF 映射语言提供了语言的详细信息。

属性图形/Gremlin 数据的 GraphMappingConfig 布局

与属性图形数据相当的 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" } ] } ] } ] }