Difference between revisions of "SimpleGraph-JSON"

From BITPlan Wiki
Jump to navigation Jump to search
Line 8: Line 8:
  
 
=== Result ===
 
=== Result ===
 +
50.9412
 +
 
=== Explanation ===
 
=== Explanation ===
 
<source lang='java'>
 
<source lang='java'>

Revision as of 08:09, 14 February 2018

SimpleGraph JSON module

The SimpleGraph JSON module makes JSON parse results accessible to Graph processing.

Example

Goal

We would like to retrieve the latitute of cologne cathedral from the Google Maps API. The query returns JSON data for the location of cologne cathedral.

Result

50.9412

Explanation

@Test
  public void testGoogleMapsJsonApi() throws Exception {
    String url="https://maps.googleapis.com/maps/api/geocode/json?address=Cologne%20Cathedral";
    String json=IOUtils.toString(new URL(url),"UTF-8");
    debug=true;
    if (debug)
      System.out.println(json);
    JsonSystem js = new JsonSystem();
    SimpleSystem dom = js.connect("json", json);
    if (debug)
      js.getStartNode().forAll(SimpleNode.printDebug);
    Holder<String> latHolder=new Holder<String>();
    dom.g().V().hasLabel("location").forEachRemaining(v->latHolder.add(v.property("lat").value().toString()));
    String lat=latHolder.getFirstValue();
    if (debug)
      System.out.println(lat);
    assertTrue(lat.startsWith("50.9412"));
  }