Difference between revisions of "SimpleGraph-JSON"
Jump to navigation
Jump to search
(→Goal) |
|||
Line 9: | Line 9: | ||
=== Result === | === Result === | ||
=== Explanation === | === Explanation === | ||
+ | <source lang='java'> | ||
+ | @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")); | ||
+ | } | ||
+ | </source> | ||
[[Category:frontend]] | [[Category:frontend]] | ||
[[Category:SimpleGraph]] | [[Category:SimpleGraph]] |
Revision as of 08:08, 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
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"));
}