Skip to content

Example Star Wars

Freddy Priyatna edited this page Jul 3, 2019 · 12 revisions

EXAMPLE Starwars: Translating mappings online for Javascript and a set of CSV files (assuming that you have npm and node or docker installed

Dataset: CSV files in https://github.com/oeg-upm/mapping-translator/tree/master/examples/starwars

Mapping: https://raw.githubusercontent.com/fpriyatna/mapping-translator/master/examples/starwars/mappings6.ttl

Commands

1. ```mkdir output```
2. ```cd output```
3. Translate the corresponding RML: 
   ```curl -X POST http://mappingtranslator.mappingpedia.linkeddata.es/transform -H 'Content-Type: application/json' -d '{ "prog_lang": "javascript", "dataset_type":"csv", "mapping_url":"https://raw.githubusercontent.com/fpriyatna/mapping-translator/master/examples/starwars/mappings6.ttl", "db_name":"starwars6.sqlite", "mapping_language":"rml", "queryplanner":"joinmonster" }' > output.zip```
5. ```unzip output.zip```
6. ```npm install```
7. ```npm start```
9. Go to http://localhost:4321/graphql from your browser, use some of the queries below

Queries

Q01: To query the hero in every episode

GraphQL Query

{
  listHeroes {
    episode {
      identifier
      code
    }
    hero {
      identifier
      name
    }
  }
}

GraphQL Query Result

{
  "data": {
    "listHeroes": [
      {
        "episode": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/episode/4",
            "code": "NewHope"
          }
        ],
        "hero": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/character/2001",
            "name": "R2 D2"
          }
        ]
      },
      {
        "episode": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/episode/5",
            "code": "Empire"
          }
        ],
        "hero": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/character/1000",
            "name": "Luke Skywalker"
          }
        ]
      },
      {
        "episode": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/episode/6",
            "code": "Jedi"
          }
        ],
        "hero": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/character/2001",
            "name": "R2 D2"
          }
        ]
      }
    ]
  }
}

Resulting SQL Query

SELECT
  "listHeroes"."episodeid" || "listHeroes"."charid" AS "epi#cha",
  "episode"."id" AS "episode__id",
  'http://starwars.mappingpedia.linkeddata.es/episode/' || "episode".id || '' AS "episode__identifier",
  "episode"."code" AS "episode__code",
  "hero"."id" AS "hero__id",
  'http://starwars.mappingpedia.linkeddata.es/character/' || "hero".id || '' AS "hero__identifier",
  '' || "hero".fname || ' ' || "hero".lname || '' AS "hero__name"
FROM heroes "listHeroes"
LEFT JOIN episodes "episode" ON "listHeroes".episodeid = "episode".id
LEFT JOIN characters "hero" ON "listHeroes".charid = "hero".id

Q02: to query for the ID and friends of R2-D2

GraphQL Query

{
  listCharacter(name: "R2 D2") {
    identifier
    name
    friends {
      identifier
      charid
      friendId
    }
  }
}

GraphQL Query Result

{
  "data": {
    "listCharacter": [
      {
        "identifier": "http://starwars.mappingpedia.linkeddata.es/character/2001",
        "name": "R2 D2",
        "friends": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/friends/2001/1000",
            "charid": "2001",
            "friendId": "1000"
          },
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/friends/2001/1002",
            "charid": "2001",
            "friendId": "1002"
          },
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/friends/2001/1003",
            "charid": "2001",
            "friendId": "1003"
          }
        ]
      }
    ]
  }
}

Resulting SQL Query

SELECT
  "listCharac"."id" AS "id",
  'http://starwars.mappingpedia.linkeddata.es/character/' || "listCharac".id || '' AS "identifier",
  '' || "listCharac".fname || ' ' || "listCharac".lname || '' AS "name",
  "friends"."id" || "friends"."fid" AS "friends__id#fid",
  'http://starwars.mappingpedia.linkeddata.es/friends/' || "friends".id || '/' || "friends".fid || '' AS "friends__identifier",
  "friends"."id" AS "friends__charid",
  "friends"."fid" AS "friends__friendId"
FROM characters "listCharac"
LEFT JOIN friends "friends" ON "listCharac".id = "friends".id
WHERE '' || "listCharac".fname || ' ' || "listCharac".lname || '' = 'R2 D2'

Q03: to query for Luke Skywalker directly, using his ID

GraphQL Query

{
  listCharacter(identifier: "http://starwars.mappingpedia.linkeddata.es/character/1000") {
    name
  }
}

GraphQL Query Result

{
  "data": {
    "listCharacter": [
      {
        "name": "Luke Skywalker"
      }
    ]
  }
}

Resulting SQL Query

SELECT
  "listCharac"."id" AS "id",
  '' || "listCharac".fname || ' ' || "listCharac".lname || '' AS "name"
FROM characters "listCharac"
WHERE 'http://starwars.mappingpedia.linkeddata.es/character/' || "listCharac".id || '' = 'http://starwars.mappingpedia.linkeddata.es/character/1000'

Q04: to query for both Luke and Leia

GraphQL Query

query FetchLukeAndLeiaAliased {
  luke: listCharacter(identifier: "http://starwars.mappingpedia.linkeddata.es/character/1000") {
    name
  }
  leia: listCharacter(identifier: "http://starwars.mappingpedia.linkeddata.es/character/1003") {
    name
  }
}

GraphQL Query Result

{
  "data": {
    "luke": [
      {
        "name": "Luke Skywalker"
      }
    ],
    "leia": [
      {
        "name": "Leia Organa"
      }
    ]
  }
}

Resulting SQL Query

SELECT
  "listCharac"."id" AS "id",
  '' || "listCharac".fname || ' ' || "listCharac".lname || '' AS "name"
FROM characters "listCharac"
WHERE 'http://starwars.mappingpedia.linkeddata.es/character/' || "listCharac".id || '' = 'http://starwars.mappingpedia.linkeddata.es/character/1000'

SELECT
  "listCharac"."id" AS "id",
  '' || "listCharac".fname || ' ' || "listCharac".lname || '' AS "name"
FROM characters "listCharac"
WHERE 'http://starwars.mappingpedia.linkeddata.es/character/' || "listCharac".id || '' = 'http://starwars.mappingpedia.linkeddata.es/character/1003'

Q05: to verify that R2-D2 is a droid

GraphQL Query

{
  listCharacter(name: "R2 D2") {
    identifier
    name
    type(name: "Droid") {
      identifier
      name
    }
  }
}

GraphQL Query Result

{
  "data": {
    "listCharacter": [
      {
        "identifier": "http://starwars.mappingpedia.linkeddata.es/character/2001",
        "name": "R2 D2",
        "type": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/type/D",
            "name": "Droid"
          }
        ]
      }
    ]
  }
}

Resulting SQL Query

SELECT
  "listCharac"."id" AS "id",
  'http://starwars.mappingpedia.linkeddata.es/character/' || "listCharac".id || '' AS "identifier",
  '' || "listCharac".fname || ' ' || "listCharac".lname || '' AS "name",
  "type"."id" AS "type__id",
  'http://starwars.mappingpedia.linkeddata.es/type/' || "type".id || '' AS "type__identifier",
  "type"."name" AS "type__name"
FROM characters "listCharac"
LEFT JOIN types "type" ON "listCharac".typeid = "type".id
WHERE '' || "listCharac".fname || ' ' || "listCharac".lname || '' = 'R2 D2' AND "type".name = 'Droid'

Q06: to verify that the hero of episode Empire is a human

GraphQL Query

{
  listHeroes {
    identifier
    hero {
      identifier
      name
      type(name: "Human") {
        identifier
        name
      }
    }
    episode(code: "Empire") {
      identifier
      code
    }
  }
}

GraphQL Query Result

{
  "data": {
    "listHeroes": [
      {
        "identifier": "http://starwars.mappingpedia.linkeddata.es/heroes/5/1000",
        "hero": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/character/1000",
            "name": "Luke Skywalker",
            "type": [
              {
                "identifier": "http://starwars.mappingpedia.linkeddata.es/type/H",
                "name": "Human"
              }
            ]
          }
        ],
        "episode": [
          {
            "identifier": "http://starwars.mappingpedia.linkeddata.es/episode/5",
            "code": "Empire"
          }
        ]
      }
    ]
  }
}

Resulting SQL Query

SELECT
  "listHeroes"."episodeid" || "listHeroes"."charid" AS "epi#cha",
  'http://starwars.mappingpedia.linkeddata.es/heroes/' || "listHeroes".episodeid || '/' || "listHeroes".charid || '' AS "identifier",
  "hero"."id" AS "hero__id",
  'http://starwars.mappingpedia.linkeddata.es/character/' || "hero".id || '' AS "hero__identifier",
  '' || "hero".fname || ' ' || "hero".lname || '' AS "hero__name",
  "type"."id" AS "hero__type__id",
  'http://starwars.mappingpedia.linkeddata.es/type/' || "type".id || '' AS "hero__type__identifier",
  "type"."name" AS "hero__type__name",
  "episode"."id" AS "episode__id",
  'http://starwars.mappingpedia.linkeddata.es/episode/' || "episode".id || '' AS "episode__identifier",
  "episode"."code" AS "episode__code"
FROM heroes "listHeroes"
LEFT JOIN characters "hero" ON "listHeroes".charid = "hero".id
LEFT JOIN types "type" ON "hero".typeid = "type".id
LEFT JOIN episodes "episode" ON "listHeroes".episodeid = "episode".id
WHERE "type".name = 'Human' AND "episode".code = 'Empire'
Clone this wiki locally
You can’t perform that action at this time.