Skip to content

Instantly share code, notes, and snippets.

@elf-pavlik
Last active August 29, 2015 14:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elf-pavlik/406ffe0300e399f72c11 to your computer and use it in GitHub Desktop.
Save elf-pavlik/406ffe0300e399f72c11 to your computer and use it in GitHub Desktop.
{
"@context": {
"@vocab": "http://schema.org/",
"mm": "http://ns.metamaps.cc/#",
"mmc": "http://metamaps.cc/metacodes/",
"permission": { "@type": "@id", "@id": "mm:permission"},
"featured": "mm:featured",
"arranged": "mm:arranged"
},
"@id": "http://metamaps.cc/maps/1207",
"@type": [
"CreativeWork",
"mm:Metamap"
],
"name": "mm json-ld hackday",
"description": "example map for experimenting with RDF data model and JSON-LD serialization",
"image": "http://metamaps.cc/assets/missing-map.png",
"permission": "mm:commons",
"featured": false,
"arranged": false,
"dateCreated": "2015-01-24T20:07Z",
"dateModified": "2015-01-24T22:14Z",
"creator": {
"@id": "http://metamaps.cc/explore/mapper/1000497708",
"@type": "Person",
"name": "elf Pavlik",
"image": "http://metamaps.cc/assets/user.png",
"sameAs": [
"http://metamaps.cc/topics/10126",
"https://wwelves.org/perpetual-tripper"
]
},
"contributor": [
{
"@id": "http://metamaps.cc/explore/mapper/1000497524",
"@type": "Person",
"name": "poietic",
"image": "http://metamaps-live.s3.amazonaws.com/users/images/100/049/752/sixtyfour/IMS-NTB_2.png?1417299044",
"sameAs": [
"http://metamaps.cc/topics/295",
"http://notthisbody.com"
]
},
{
"@id": "http://metamaps.cc/explore/mapper/555629996",
"@type": "Person",
"name": "Connor Turland",
"image": "http://metamaps.cc/assets/user.png",
"sameAs": [
"http://metamaps.cc/topics/24",
"http://improv-ed.blogspot.com"
]
}
],
"@graph": [
{
"@id": "http://metamaps.cc/topics/24252",
"@type": [
"Project",
"mmc:1047793150"
],
"name": "Metamaps Project",
"author": [
"http://metamaps.cc/topics/295",
"http://metamaps.cc/topics/24"
],
"event": [
"http://metamaps.cc/topics/24255"
],
"sameAs": [
"https://github.com/metamaps/metamaps_gen002"
]
},
{
"@id": "http://metamaps.cc/topics/24255",
"@type": [
"Event",
"mmc:1047793145"
],
"name": "metamaps hack day 1/24/15",
"attendee": [
"http://metamaps.cc/topics/295",
"http://metamaps.cc/topics/24",
"http://metamaps.cc/topics/10126"
]
},
{
"@id": "http://metamaps.cc/topics/295",
"@type": [
"Person",
"mmc:980190962"
],
"name": "poietic",
"sameAs": [
"http://metamaps.cc/explore/mapper/1000497524",
"http://notthisbody.com"
]
},
{
"@id": "http://metamaps.cc/topics/24",
"@type": [
"Person",
"mmc:980190962"
],
"name": "Connor Turland",
"sameAs": [
"http://metamaps.cc/explore/mapper/555629996",
"http://improv-ed.blogspot.com"
]
},
{
"@id": "http://metamaps.cc/topics/10126",
"@type": [
"Person",
"mmc:980190962"
],
"name": "elf Pavlik",
"sameAs": [
"http://metamaps.cc/explore/mapper/1000497708",
"https://wwelves.org/perpetual-tripper"
]
}
]
}
@jmatsushita
Copy link

Hi @elf-pavlik,

I happened to have installed metamaps locally to be able to map while I was offline and got a bit stuck when I realised I couldn't export back the map in the online version. That led me to stumble upon the import/export hackday hackpad which led me here. Given that I often have to convert from one json representation to another and that so far I was playing with the cool http://trentm.com/json/ I took the opportunity to search for a more robust solution and found jq which is much much better.

I thought that given that there isn't yet a JSON-LD import/export facility for metamaps, that it might be useful to contribute a jq command that helps transform the contains.json links to JSON-LD.

Apart from the sameAs keys the and some minor differences which seem to come from the data itself, the diff below looks pretty good!

This is the one liner that downloads map 1207 and outputs the transformed json-ld on stdout.

curl 'http://metamaps.cc/maps/1207/contains.json' | jq '. | .synapses as $synapses | { name: .map.name, description: .map.desc, image: "http://metamaps.cc\(.map.screenshot_url)", permission: "mm:\(.map.permission)", featured: (if .map.featured then .map.featured else "false" end), arranged: (if .map.arranged then .map.arranged else "false" end), dateCreated: .map.created_at, dateModified: .map.updated_at, creator: { "@id": @uri "http://metamaps.cc/explore/mapper/\(.map.user_id)", "@type": "Person", name: .map.user_name, image: "http://metamaps.cc\(.map.user_image)" }, contributor: [.mappers[] | {"@id": @uri "http://metamaps.cc/explore/mapper/\(.id)", "@type": "Person", name: .name, image: (if .image | startswith("/") then "http://metamaps.cc\(.image)" else .image end) }], "@graph": [.topics[] | .id as $topicid | {"@id": @uri "http://metamaps.cc/topics/\(.id)", "@type": [ .metacode_id | ( if . == 1047793150 then "Project" elif . == 980190962 then "Person" elif . == 1047793145 then "Event" else "" end), "mmc:\(.)"], name: .name } * ( if (($synapses | map(select(.desc == "author" and .node1_id == $topicid)) | length) != 0 ) then { "author": [ ($synapses | map(select(.desc == "author" and .node1_id == $topicid))[] | "http://metamaps.cc/topics/\(.node2_id)") ]} else {} end ) * ( if (($synapses | map(select(.desc == "attendee" and .node1_id == $topicid)) | length) != 0 ) then { "attendee": [ ($synapses | map(select(.desc == "attendee" and .node1_id == $topicid))[] | "http://metamaps.cc/topics/\(.node2_id)") ]} else {} end ) * ( if (($synapses | map(select(.desc == "event" and .node1_id == $topicid)) | length) != 0 ) then { "event": [ ($synapses | map(select(.desc == "event" and .node1_id == $topicid))[] | "http://metamaps.cc/topics/\(.node2_id)") ]} else {} end ) ] }'

And this is it formatted. There's probably some better way to write the lookups for the @graph key. Also given that on metamaps, the link description is an open field, there's clearly some difficulties in mapping them to a vocabulary.

. | .synapses[] as $synapses | 
{ 
  name: .map.name, 
  description: .map.desc, 
  image: @uri "http://metamaps.cc/\(.map.screenshot_url)", 
  permission: "mm:\(.map.permission)", 
  featured: (if .map.featured then .map.featured else "false" end), 
  arranged: (if .map.arranged then .map.arranged else "false" end), 
  dateCreated: .map.created_at, 
  dateModified: .map.updated_at, 
  creator: { 
    "@id": @uri "http://metamaps.cc/explore/mapper/\(.map.user_id)",
    "@type": "Person", 
    name: .map.user_name, 
    image: "http://metamaps.cc\(.map.user_image)" 
  }, 
  contributor: [.mappers[] | {
    "@id": @uri "http://metamaps.cc/explore/mapper/\(.id)", 
    "@type": "Person", 
    name: .name, 
    image: (if .image | startswith("/") then "http://metamaps.cc\(.image)" else .image end) 
  }], 
  "@graph": [.topics[]  | .id as $topicid | {
    "@id": @uri "http://metamaps.cc/topics/\(.id)", 
    "@type": [ .metacode_id | ( 
      if . == 1047793150 then "Project" 
      elif . == 980190962 then "Person" 
      elif . == 1047793145 then "Event" 
      else "" end), 
      "mmc:\(.)" ], 
    name: .name } * 
    ( if (($synapses | map(select(.desc == "author" and .node1_id == $topicid)) | length) != 0 ) then { "author": [ ($synapses | map(select(.desc == "author" and .node1_id == $topicid))[] | "http://metamaps.cc/topics/\(.node2_id)") ]} else {} end ) *
    ( if (($synapses | map(select(.desc == "attendee" and .node1_id == $topicid)) | length) != 0 ) then { "attendee": [ ($synapses | map(select(.desc == "attendee" and .node1_id == $topicid))[] | "http://metamaps.cc/topics/\(.node2_id)") ]} else {} end ) *
    ( if (($synapses | map(select(.desc == "event" and .node1_id == $topicid)) | length) != 0 ) then { "event": [ ($synapses | map(select(.desc == "event" and .node1_id == $topicid))[] | "http://metamaps.cc/topics/\(.node2_id)") ]} else {} end )
  ] 
}

Diff between metamaps-example.jsonld and result of the above jq command

 {
-  "@context": {
-    "@vocab": "http://schema.org/",
-    "mm": "http://ns.metamaps.cc/#",
-    "mmc": "http://metamaps.cc/metacodes/",
-    "permission": { "@type": "@id", "@id": "mm:permission"},
-    "featured": "mm:featured",
-    "arranged": "mm:arranged"
-  },
-  "@id": "http://metamaps.cc/maps/1207",
-  "@type": [
-    "CreativeWork",
-    "mm:Metamap"
-  ],
   "name": "mm json-ld hackday",
   "description": "example map for experimenting with RDF data model and JSON-LD serialization",
   "image": "http://metamaps.cc/assets/missing-map.png",
   "permission": "mm:commons",
   "featured": "false",
   "arranged": "false",
   "dateCreated": "2015-01-24T17:01:28Z",
   "dateModified": "2015-01-24T21:21:21Z",
   "creator": {
     "@id": "http://metamaps.cc/explore/mapper/1000497708",
     "@type": "Person",
     "name": "elf Pavlik",
-    "image": "http://metamaps.cc/assets/user.png",
-    "sameAs": [
-      "http://metamaps.cc/topics/10126",
-      "https://wwelves.org/perpetual-tripper"
-    ]
+    "image": "http://metamaps.cc/assets/user.png"
   },
   "contributor": [
     {
       "@id": "http://metamaps.cc/explore/mapper/1000497524",
       "@type": "Person",
       "name": "poietic",
-      "image": "http://metamaps-live.s3.amazonaws.com/users/images/100/049/752/sixtyfour/IMS-NTB_2.png?1417299044",
-      "sameAs": [
-        "http://metamaps.cc/topics/295",
-        "http://notthisbody.com"
-      ]
+      "image": "http://metamaps-live.s3.amazonaws.com/users/images/100/049/752/sixtyfour/IMS-NTB_2.png?1417299044"
     },
     {
-      "@id": "http://metamaps.cc/explore/mapper/555629996",
+      "@id": "http://metamaps.cc/explore/mapper/1000497708",
       "@type": "Person",
-      "name": "Connor Turland",
-      "image": "http://metamaps.cc/assets/user.png",
+      "name": "elf Pavlik",
+      "image": "http://metamaps.cc/assets/user.png"
-      "sameAs": [
-        "http://metamaps.cc/topics/24",
-        "http://improv-ed.blogspot.com"
-      ]
     }
   ],
   "@graph": [
     {
       "@id": "http://metamaps.cc/topics/24",
       "@type": [
         "Person",
         "mmc:980190962"
       ],
-      "name": "Connor Turland",
-      "sameAs": [
-        "http://metamaps.cc/explore/mapper/555629996",
-        "http://improv-ed.blogspot.com"
-      ]
+      "name": "Connor Turland"
     },
     {
       "@id": "http://metamaps.cc/topics/10126",
       "@type": [
         "Person",
         "mmc:980190962"
       ],
-      "name": "elf Pavlik",
-      "sameAs": [
-        "http://metamaps.cc/explore/mapper/1000497708",
-        "https://wwelves.org/perpetual-tripper"
-      ]
+      "name": "elf Pavlik"
     },
     {
       "@id": "http://metamaps.cc/topics/24255",
       "@type": [
         "Event",
         "mmc:1047793145"
       ],
       "name": "metamaps hack day 1/24/15",
       "attendee": [
         "http://metamaps.cc/topics/24",
         "http://metamaps.cc/topics/295",
         "http://metamaps.cc/topics/10126"
       ]
     },
     {
       "@id": "http://metamaps.cc/topics/24252",
       "@type": [
         "Project",
         "mmc:1047793150"
       ],
       "name": "Metamaps Project",
       "author": [
         "http://metamaps.cc/topics/24",
         "http://metamaps.cc/topics/295"
       ],
       "event": [
         "http://metamaps.cc/topics/24255"
-      ],
-      "sameAs": [
-        "https://github.com/metamaps/metamaps_gen002"
       ]
     },
     {
       "@id": "http://metamaps.cc/topics/295",
       "@type": [
         "Person",
         "mmc:980190962"
       ],
-      "name": "poietic",
-      "sameAs": [
-        "http://metamaps.cc/explore/mapper/1000497524",
-        "http://notthisbody.com"
-      ]
+      "name": "Ishan Shapiro"
     }
   ]
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment