# HG changeset patch
# User one
# Date 1345660848 -32400
# Node ID bf7863a55cd6b1d4420ec94899898a6835fa8eac
# Parent b56ff507cdb4e2db3ab9673a636e980adab892ee
add wikigraph.Neo4jTest.java
diff -r b56ff507cdb4 -r bf7863a55cd6 .classpath
--- a/.classpath Wed Aug 22 16:18:09 2012 +0900
+++ b/.classpath Thu Aug 23 03:40:48 2012 +0900
@@ -36,5 +36,6 @@
+
diff -r b56ff507cdb4 -r bf7863a55cd6 src/begin/MakeNode.java
--- a/src/begin/MakeNode.java Wed Aug 22 16:18:09 2012 +0900
+++ b/src/begin/MakeNode.java Thu Aug 23 03:40:48 2012 +0900
@@ -4,15 +4,20 @@
import javax.ws.rs.core.MediaType;
-import org.json.simple.JSONObject;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource;
public class MakeNode {
final static String SERVER_ROOT_URI = "http://localhost:7474";
final static String nodeEntryPointUri = "http://localhost:7474/db/data/node";
+ final static String nodeIndexEntryPointUri = "http://localhost:7474/db/data/index/node";
public static URI createNode() {
WebResource resource = Client.create().resource(nodeEntryPointUri);
@@ -24,7 +29,7 @@
return response.getLocation();
}
- public static ClientResponse getNode(String nodeUri) {
+ public static ClientResponse getNode(String nodeUri) {
WebResource resource = Client.create().resource(nodeUri);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
System.out.println(String.format("GET on [%s], status code [%d]",nodeUri, response.getStatus() ));
@@ -50,7 +55,7 @@
return "\"" + str + "\"";
}
- public static void createRelationship(String uri1, String uri2, String typeValue) {
+ public static void createRelationship(String uri1, String uri2, String typeValue) throws JSONException {
String relationshipUri = uri1 + "/relationships";
WebResource resource = Client.create().resource(relationshipUri);
JSONObject obj = new JSONObject();
@@ -64,17 +69,67 @@
System.out.println(String.format("POST to [%s], status code [%d]",relationshipUri , response.getStatus()));
}
- public static void main(String[] args) {
+ public static void deleteNode(String uri) {
+ WebResource resource = Client.create().resource(uri);
+ ClientResponse response = resource.accept(MediaType.APPLICATION_JSON).delete(ClientResponse.class);
+ System.out.println(String.format(
+ "DELETE to [%s], status code [%d]", uri, response.getStatus()));
+ }
+
+ public static URI createIndexNode(String indexName) throws JSONException {
+ WebResource resource = Client.create().resource(nodeIndexEntryPointUri);
+ JSONObject obj = new JSONObject();
+ obj.put("name",indexName);
+ ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
+ .type(MediaType.APPLICATION_JSON)
+ .entity(obj.toString())
+ .post(ClientResponse.class);
+ System.out.println(String.format(
+ "POST to [%s], status code [%d], location header [%s]",
+ nodeIndexEntryPointUri, response.getStatus(), response.getLocation()
+ .toString()));
+ return response.getLocation();
+ }
+
+ public static URI addNodeToIndex(String indexUri, String value, String uri, String key) throws JSONException {
+ WebResource resource = Client.create().resource(indexUri);
+ JSONObject obj = new JSONObject();
+ obj.put("value", value);
+ obj.put("uri",uri);
+ obj.put("key",key);
+
+ ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
+ .type(MediaType.APPLICATION_JSON)
+ .entity(obj.toString())
+ .post(ClientResponse.class);
+ System.out.println(String.format(
+ "POST to [%s], status code [%d], location header [%s]",
+ nodeIndexEntryPointUri, response.getStatus(), response.getLocation()
+ .toString()));
+ return response.getLocation();
+ }
+
+ public static void main(String[] args) throws ClientHandlerException, UniformInterfaceException, JSONException {
final String uri1 = "http://localhost:7474/db/data/node/1";
final String uri2 = "http://localhost:7474/db/data/node/2";
+
+ final String indexUri = "http://localhost:7474/db/data/index/node/hogehoge";
+ addNodeToIndex(indexUri, "test_value", uri1, "test_key");
- getNode(uri1);
+ ClientResponse response = getNode(uri1);
+ // System.out.println(response.getEntity(String.class));
+ JSONObject obj = new JSONObject(response.getEntity(String.class));
+ System.out.println(obj.toString());
+
+
+/*
+
getNode(uri2);
createRelationship(uri1, uri2, "RELATED_TO");
+*/
-
/*
URI firstNode = createNode();
addProperty(firstNode, "name", "Joe Strummer");
diff -r b56ff507cdb4 -r bf7863a55cd6 src/howtouse/CharReader.java
--- a/src/howtouse/CharReader.java Wed Aug 22 16:18:09 2012 +0900
+++ b/src/howtouse/CharReader.java Thu Aug 23 03:40:48 2012 +0900
@@ -68,6 +68,7 @@
} else if (ch == VERBAR) {
index = buf.length();
buf.append(ch);
+// buf.delete(0,buf.length());
} else {
buf.append(ch);
}
diff -r b56ff507cdb4 -r bf7863a55cd6 src/howtouse/TestSaxParser.java
--- a/src/howtouse/TestSaxParser.java Wed Aug 22 16:18:09 2012 +0900
+++ b/src/howtouse/TestSaxParser.java Thu Aug 23 03:40:48 2012 +0900
@@ -17,8 +17,9 @@
public static void main(String[] args) {
try {
- FileInputStream fis = new FileInputStream("./resource/article.xml");
-
+// final String filename = "/Users/aotokage/testProgram/wiki/ja-pages_current.xml";
+ final String filename = "./resource/article3.xml";
+ FileInputStream fis = new FileInputStream(filename);
TestSaxParser sample = new TestSaxParser();
SAXParserFactory factory = SAXParserFactory.newInstance();
diff -r b56ff507cdb4 -r bf7863a55cd6 src/wikigraph/Neo4jTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/wikigraph/Neo4jTest.java Thu Aug 23 03:40:48 2012 +0900
@@ -0,0 +1,47 @@
+package wikigraph;
+
+import org.neo4j.graphdb.GraphDatabaseService;
+import org.neo4j.graphdb.Node;
+import org.neo4j.graphdb.Transaction;
+import org.neo4j.kernel.EmbeddedGraphDatabase;
+import org.neo4j.tooling.GlobalGraphOperations;
+
+public class Neo4jTest {
+
+ public static void main(String[] args) {
+
+ GraphDatabaseService graphDb = new EmbeddedGraphDatabase("db");
+ GlobalGraphOperations graphOpe = GlobalGraphOperations.at(graphDb);
+
+ Transaction tx = graphDb.beginTx();
+
+ Node firstNode = graphDb.createNode();
+ firstNode.setProperty("name", "Jason Kidd");
+ firstNode.setProperty("number", "2");
+
+ tx.success();
+
+ tx.finish();
+
+
+ for (Node node: graphOpe.getAllNodes()) {
+ System.out.println("ID="+ node.getId());
+ for (String key: node.getPropertyKeys()) {
+ System.out.println(key + "=" + node.getProperty(key));
+ }
+ System.out.println("--");
+ }
+
+
+
+
+
+
+ graphDb.shutdown();
+
+
+
+
+ }
+
+}