Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>package com.infinitegraph.samples.hellograph; // Import all InfiniteGraph packages import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import com.infinitegraph.*; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; // Import SLF4J logging packages import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.infinitegraph.BaseVertex; import java.util.HashMap; public class HelloGraph { public static void main(String[] args) { BufferedReader br = null; JSONParser parser = new JSONParser(); // Set up logging for the HelloGraph class Logger logger = LoggerFactory.getLogger(HelloGraph.class); // Create null transaction, null graph database instance Transaction tx = null; GraphDatabase helloGraphDB = null; // Name for graph database and property file String graphDbName = "HelloGraph"; String propertiesFileName = "HelloGraph.properties"; try { try { // Delete graph database if it already exists GraphFactory.delete(graphDbName, propertiesFileName); } catch (StorageException sE) { logger.info(sE.getMessage()); } // HINT: Add code to create graph database and its contents // Create graph database logger.info("&gt; Creating graph database ..."); GraphFactory.create(graphDbName, propertiesFileName); // Open graph database logger.info("&gt; Opening graph database ..."); helloGraphDB = GraphFactory.open(graphDbName, propertiesFileName); // Begin transaction logger.info("&gt; Starting a read/write transaction ..."); tx = helloGraphDB.beginTransaction(AccessMode.READ_WRITE); //create head vertex HeaderVertex head = new HeaderVertex("JSON File"); helloGraphDB.addVertex(head); try { String sCurrentLine; br = new BufferedReader(new FileReader("C:/Users/ji/Desktop/example3.json")); HashMap&lt;String, Integer&gt; map = new HashMap &lt;String, Integer&gt;(); while ((sCurrentLine = br.readLine()) != null) { Object obj; try { obj = parser.parse(sCurrentLine); JSONObject jsonObject = (JSONObject) obj; //code to create vertex logger.info("&gt; Creating Start vertices ..."); String start = (String) jsonObject.get("start"); StartVertex startV = new StartVertex(start); if (!map.containsKey(start)) { map.put(start,1); helloGraphDB.addVertex(startV); } //System.out.println(end); String end = (String) jsonObject.get("end"); EndVertex endV = new EndVertex(end); helloGraphDB.addVertex(endV); String rel = (String) jsonObject.get("rel"); //System.out.println(rel); logger.info("&gt; Creating Relationship edge ..."); Relationship relationship1 = new Relationship(""); Relationship relationship2 = new Relationship(rel); // Connect edges logger.info("&gt; Connecting vertices ..."); startV.addEdge(relationship1, head, EdgeKind.BIDIRECTIONAL, (short) 0); endV.addEdge(relationship2, startV, EdgeKind.BIDIRECTIONAL, (short) 0); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (IOException e) { e.printStackTrace(); } finally { try { if (br != null)br.close(); } catch (IOException ex) { ex.printStackTrace(); } } // Specify a named root for traversal logger.info("&gt; Naming a root vertex ..."); helloGraphDB.nameVertex("JSON File", head); // Commit to save your changes to the graph database logger.info("&gt; Committing changes ..."); tx.commit(); } catch (ConfigurationException cE) { logger.warn("&gt; Configuration Exception was thrown ... "); logger.error(cE.getMessage()); } finally { // If the transaction was not committed, complete // will roll it back if (tx != null) tx.complete(); if (helloGraphDB != null) { helloGraphDB.close(); logger.info("&gt; On Exit: Closed graph database"); } } } } // HINT: Add class definitions for Person and Meeting classes here. class HeaderVertex extends BaseVertex { private String header; public HeaderVertex (String header) { setStartName(header); } public void setStartName (String header) { markModified(); this.header = header; } public String toString() { fetch(); return this.header; } } class StartVertex extends BaseVertex { private String start; public StartVertex (String start) { setStartName(start); } public void setStartName (String start) { markModified(); this.start = start; } public String toString() { fetch(); return this.start; } } class EndVertex extends BaseVertex { private String end; public EndVertex (String end) { setEndVertex(end); } public void setEndVertex (String end) { markModified(); this.end = end; } public String toString() { fetch(); return this.end; } } class Relationship extends BaseEdge { private String rel; public Relationship (String rel) { setRelationship(rel); } public void setRelationship (String rel) { markModified(); this.rel = rel; } public String toString() { fetch(); return this.rel; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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