graiph-dist

graiph distribution parent module

License

License

GroupId

GroupId

com.github.grapheco
ArtifactId

ArtifactId

graiph-dist
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

pom
Description

Description

graiph-dist
graiph distribution parent module

Download graiph-dist

Filename Size
graiph-dist-0.1.0.pom 3 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.grapheco/graiph-dist/ -->
<dependency>
    <groupId>com.github.grapheco</groupId>
    <artifactId>graiph-dist</artifactId>
    <version>0.1.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.grapheco/graiph-dist/
implementation 'com.github.grapheco:graiph-dist:0.1.0'
// https://jarcasting.com/artifacts/com.github.grapheco/graiph-dist/
implementation ("com.github.grapheco:graiph-dist:0.1.0")
'com.github.grapheco:graiph-dist:pom:0.1.0'
<dependency org="com.github.grapheco" name="graiph-dist" rev="0.1.0">
  <artifact name="graiph-dist" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.grapheco', module='graiph-dist', version='0.1.0')
)
libraryDependencies += "com.github.grapheco" % "graiph-dist" % "0.1.0"
[com.github.grapheco/graiph-dist "0.1.0"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

  • graiph-client-shade
  • graiph-database-shade

GitHub releases GitHub downloads GitHub issues GitHub forks GitHub stars GitHub license

GraiphDB

GraiphDB is an AI native graph database.

GraiphDB uses graiph-neo4j, which enables Neo4j with BLOB handling functions.

Building GraiphDB

mvn clean install

this will install all artifacts in local maven repository.

Quick start

STEP 1. download package

visit https://github.com/grapheco/graiph-dist/releases to get GraiphDB binary distributions.

unpack graiph-server-x.x.zip in your local directory, e.g. /usr/local/.

cd /usr/local/graiph-server-x.x

STEP 2. start server

  • bin/neo4j console: start a graiph server
  • bin/neo4j start: start a graiph server silently

Once successfully startup, infos will be shown as below:

[17:12:24:866] DEBUG CypherInjection$     :: injecting cypher expression extensions...
2019-07-31 09:12:25.339+0000 WARN  WARNING! Deprecated configuration options used. See manual for details
2019-07-31 09:12:25.341+0000 WARN  dbms.allow_format_migration has been replaced with dbms.allow_upgrade.
2019-07-31 09:12:25.342+0000 WARN  dbms.active_database is deprecated.
2019-07-31 09:12:25.353+0000 INFO  ======== Graiph (Neo4j-3.5.6-BLOB) ========
   _____             _____       _     _____  ____
  / ____|      /\   |_   _|     | |   |  __ \|  _ \
 | |  __ _ __ /  \    | |  _ __ | |__ | |  | | |_) |
 | | |_ | '__/ /\ \   | | | '_ \| '_ \| |  | |  _ <
 | |__| | | / ____ \ _| |_| |_) | | | | |__| | |_) |
  \_____|_|/_/    \_\_____| .__/|_| |_|_____/|____/
                          | |
                          |_|

STEP 3. connect remote GraiphServer

clients communicate with GraiphServer via Cypher over Bolt protocol.

  • bin/cypher-shell: open a graiph client to a remote server

Also, you may visit http://localhost:7474 to browse graph data in neo4j-browser.

NOTE: cypher-shell will recognize // as starting of comments, so some commands with // are recommended to be tested in neo4j-browser.

STEP 4. querying on GraiphDB

in neo4j-browser, users can input Cypher commands to query on GraiphDB.

create (bluejoe:Person {name: 'bluejoe', mail:'[email protected]', photo: <https://bluejoe2008.github.io/bluejoe3.png>, car: <http://s5.sinaimg.cn/middle/005AE7Quzy7rL9U08Pa24&690>}) 

this command will create a Person node with a BLOB property, which content come from the Web URL. If you like, <file://...> or <ftp://...> is ok.

the match command returns:

neo4j@<default_database>> match (n) return n;
+--------------------------------------------------------------------------------------------------------------------------------+
| n                                                                                                                              |
+--------------------------------------------------------------------------------------------------------------------------------+
| (:Person {name: "bluejoe", photo: BoltBlobValue(blob=blob(length=250159,mime-type=image/png)), mail: "[email protected]", car: BoltBlobValue(blob=blob(length=36379,mime-type=image/jpeg))}) |
+--------------------------------------------------------------------------------------------------------------------------------+

in neo4j-browser, a BLOB property will be displayed as an image icon:

NOTE: if user/password is required, try default values: neo4j/neo4j.

CypherPlus

GraiphDB enhances Cypher grammar, naming CypherPlus. CypherPlus allows writing BLOB literals in query commands, also it allows semantic operations on properties, especially BLOB properties.

BLOB literals

BlobLiteral is defined in Cypher grammar in form of: <schema://path>

Following schema is ok:

  • file: local files in Neo4j server
  • http
  • https
  • ftp
  • base64: path should be a BASE64 encoding string, for example: <base64://dGhpcyBpcyBhbiBleGFtcGxl> represents a string with content this is an example

Next code illustrates how to use blob in Cypher query:

return <https://bluejoe2008.github.io/bluejoe3.png>

more details, see https://github.com/bluejoe2008/graiph-neo4j/blob/cypher-extension/README.md

property extration

neo4j@<default_database>> match (n {name:'bluejoe'}) return n.photo->mime, n.car->width;
+------------------------------+
| n.photo->mime | n.car->width |
+------------------------------+
| "image/png"   | 640          |
+------------------------------+

retrieving plate number of the car:

neo4j@<default_database>> match (n {name:'bluejoe'}) return n.car->plateNumber;
+--------------------+
| n.car->plateNumber |
+--------------------+
| "苏B56789"          |
+--------------------+

NOTE: some semantic operation requires an AIPM service at aipm-host (modify this setting in neo4j.conf), if it is unavailable, exceptions will be thrown:

neo4j@<default_database>> match (n {name:'bluejoe'}) return n.car->plateNumber;
Failed connect to http://aipm-host:8081

semantic comparison

CypherPlus allows semantic comparison on two properties.

Following example query compares two text:

neo4j@<default_database>> return 'abc' :: 'abcd', 'abc' ::jaccard 'abcd', 'abc' ::jaro 'abcd', 'hello world' ::cosine 'bye world';
+--------------------------------------------------------------------------------------------------------+
| 'abc' :: 'abcd'    | 'abc' ::jaccard 'abcd' | 'abc' ::jaro 'abcd' | 'hello world' ::cosine 'bye world' |
+--------------------------------------------------------------------------------------------------------+
| 0.9416666805744172 | 0.5                    | 0.9416666805744172  | 0.5039526306789696                 |
+--------------------------------------------------------------------------------------------------------+

A good idea is to determine if a person appear in another photo:

return <http://s12.sinaimg.cn/mw690/005AE7Quzy7rL8kA4Nt6b&690> ~:0.5 <http://s15.sinaimg.cn/mw690/005AE7Quzy7rL8j2jlIee&690>

developers' manual

connecting remote GraiphServer

import graiph-client-all dependency first:

   <dependency>
      <groupId>com.github.grapheco</groupId>
      <artifactId>graiph-client-all</artifactId>
      <version>0.1.0</version>
   </dependency>

use object RemoteGraiph.connect():

  • def connect(url: String, user: String = "", pass: String = ""): CypherService

CypherService has a set of methods:

  • def queryObjects[T: ClassTag](queryString: String, fnMap: (Record => T)): Iterator[T];

  • def execute[T](f: (Session) => T): T;

  • def executeQuery[T](queryString: String, fn: (StatementResult => T)): T;

  • def executeQuery[T](queryString: String, params: Map[String, AnyRef], fn: (StatementResult => T)): T;

  • def executeUpdate(queryString: String);

  • def executeUpdate(queryString: String, params: Map[String, AnyRef]);

  • def executeQuery[T](queryString: String, params: Map[String, AnyRef])

  • def querySingleObject[T](queryString: String, fnMap: (Record => T)): T

  • def querySingleObject[T](queryString: String, params: Map[String, AnyRef], fnMap: (Record => T)): T

A simple example:

    val conn = RemoteGraiph.connect("bolt://localhost:7687", "neo4j", "123");
    //a non-blob
    val (node, name, age) = conn.querySingleObject("match (n) where n.name='bob' return n, n.name, n.age", (result: Record) => {
      (result.get("n").asNode(), result.get("n.name").asString(), result.get("n.age").asInt())
    });

more example code, see https://github.com/grapheco/graiph-dist/tree/master/graiph-client-test

using embedded graiph database

import graiph-database-all dependency first:

   <dependency>
      <groupId>com.github.grapheco</groupId>
      <artifactId>graiph-database-all</artifactId>
      <version>0.1.0</version>
   </dependency>

using object GraiphDB:

  • def openDatabase(dbDir: File, propertiesFile: File): GraphDatabaseService

  • def connect(dbs: GraphDatabaseService): CypherService

An example of openDatabase:

   val db = GraiphDB.openDatabase(new File("./testdb"), new File("./neo4j.conf"));
   val tx = db.beginTx();
   //create a node
   val node1 = db.createNode();

   node1.setProperty("name", "bob");
   node1.setProperty("age", 40);

   //with a blob property
   node1.setProperty("photo", Blob.fromFile(new File("./testdata/test.png")));
   ...

An example of connect:

   val db = GraiphDB.openDatabase(new File("./testdb"), new File("./neo4j.conf"));
   val conn = GraiphDB.connect(db);
   //a non-blob
    val (node, name, age) = conn.querySingleObject("match (n) where n.name='bob' return n, n.name, n.age", (result: Record) => {
      (result.get("n").asNode(), result.get("n.name").asString(), result.get("n.age").asInt())
    });

YES! GraiphDB.connect() returns a CypherService too, just like that of RemoteGraiph.connect().

more example code, see https://github.com/grapheco/graiph-dist/tree/master/graiph-database-test

handling BLOBs

graiph-neo4j enhances Neo4j with a set of blob operation functions which makes it possible and convenient to store and use the BLOB in neo4j.

more details, see https://github.com/bluejoe2008/graiph-neo4j/blob/cypher-extension/blob.md

Licensing

Following Neo4j Community Edition, graiph-neo4j is an open source product licensed under GPLv3.

com.github.grapheco

grapheco

graph ecosytem including graphdb, RDF, Linked Data, Knowledge Graph

Versions

Version
0.1.0