Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can also use HashMap instead of array list.</p> <p>It would be more efficient than linearly checking into ArrayList.</p> <p>You'll have to just check whether you have a start(eg "audi") in a HashMap,if not you can add it to the Graph and also the HashMap,if it is already there in HashMap you can skip adding it both.</p> <pre><code>String a = "{\"rel\": \"AtLocation\", \"weight\": 0.5, \"dataset\": \"/d/dbpedia/en\", \"sources\": [\"/s/dbpedia/3.7\"], \"id\": \"0209765bf7185615ef242513f61ca0f61efe2a04\", \"features\": [\"audi AtLocation -\", \"audi - curitiba\", \"- AtLocation curitiba\"], \"end\": \"curitiba\", \"license\": \"/l/CC/By-SA\", \"uri\": \"/a/[AtLocation/,audi/,curitiba/]\", \"start\": \"audi\", \"context\": \"/ctx/all\", \"surfaceText\": null}"; String b = "{\"rel\": \"AtLocation\", \"weight\": 0.5, \"dataset\": \"/d/dbpedia/en\", \"sources\": [\"/s/dbpedia/3.7\"], \"id\": \"5158d1cfce728efb3e42840d166ec06153a3d77d\", \"features\": [\"audi AtLocation -\", \"audi - ingolstadt\", \"- AtLocation ingolstadt\"], \"end\": \"unite_state\", \"license\": \"/l/CC/By-SA\", \"uri\": \"/a/[AtLocation/,audi/,ingolstadt/]\", \"start\": \"audi\", \"context\": \"/ctx/all\", \"surfaceText\": null}"; JSONParser p = new JSONParser(); JSONObject jsonA = (JSONObject) p.parse( a ); JSONObject jsonB = (JSONObject) p.parse( b ); HashMap&lt;String, Integer&gt; map = new HashMap&lt;String, Integer&gt;(); String start = (String) jsonA.get( "start" ); System.out.println( "Does map contains 'audi' for start:" + map.containsKey( start ) ); if( !map.containsKey( start ) ) { map.put( start, 1 ); System.out.println( "Adding to graph" ); } System.out.println( "Does map contains 'audi' for start:" + map.containsKey( start ) ); start = (String) jsonB.get( "start" ); if( !map.containsKey( start ) ) { map.put( start, 2 ); System.out.println( "Adding to graph" ); } System.out.println( "Does map contains 'audi' for start:" + map.containsKey( start ) ); </code></pre> <p>The Output that i got:</p> <pre><code>Does map contains 'audi' for start:false Adding to graph Does map contains 'audi' for start:true Does map contains 'audi' for start:true </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload