(Code checked with Doctest.js)

RDFa API Comparisons


Places with coordinates

Source


Access using JSON extraction

var ctx = {"@vocab": "http://schema.org/"}

var data = LD.connect(RDFaJSON.extract(document), ctx)
data.byType.Place.forEach(function (place) {
  print(place['@type'])
  print(place.name)
  var geo = place.geo
  print(geo.longitude, geo.latitude)
})

/* =>
Place
Tsujido
139.447083 35.336833
Place
Meguro
139.71600 35.633983
*/

Access using Graph API

var graph = RDF.toGraph(RDFaJSON.extract(document), "http://schema.org/")

graph.getByType('Place').forEach(function (place) {
  print(place.getType())
  print(place.get('name'))
  print(place.get('geo').get('longitude'))
  print(place.get('geo / longitude'))
  print(place.get('geo / latitude'))
  print(place.get('geo').getInverseOf('geo').get('name'))
  print(place.get('geo / ^geo / name'))
})

/* =>
http://schema.org/Place
Tsujido
139.447083
139.447083
35.336833
Tsujido
Tsujido
http://schema.org/Place
Meguro
139.71600
139.71600
35.633983
Meguro
Meguro
*/