

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# Neptune GraphMappingConfig の作成
<a name="dms-neptune-graph-mapping"></a>

作成した `GraphMappingConfig` は、ソースデータストアから抽出されたデータを Neptune DB クラスターにロードする方法を指定します。形式は、目的が RDF データのロードか、プロパティグラフデータのロードかによって異なります。

RDF データの場合、W3 [R2RML](https://www.w3.org/TR/r2rml/) 言語を使用してリレーショナルデータを RDF にマッピングできます。

Gremlin を使用してクエリするプロパティグラフデータをロードする場合、`GraphMappingConfig` の JSON オブジェクトを作成します。

## RDF/SPARQL データの GraphMappingConfig レイアウト
<a name="dms-neptune-graph-mapping-sparql"></a>

SPARQL を使用して照会する RDF データをロードする場合は、[R2RML](https://www.w3.org/TR/r2rml/) に `GraphMappingConfig` を書き込みます。`R2RML` はリレーショナルデータを RDF にマッピングするための標準 W3 言語です。1 つの例を次に示します。

```
@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 to RDF Mapping Language](https://www.w3.org/TR/r2rml/)」にある「W3 Recommendation」には、言語の詳細が記載されています。

## プロパティグラフ/Gremlin データの GraphMappingConfig レイアウト
<a name="dms-neptune-graph-mapping-gremlin"></a>

プロパティグラフデータの同等の `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"
            }
          ]
        }
      ]
    }
  ]
}
```