3

I am working on a recommendation engine. The user data is collected (Their friendship, locations, likes,education,...) and is already stored in mongodb. I need to recommend relevant products to these users. I am planning on using neo4j for the recommender engine for obvious reasons (ease of traversal between nodes, path information,..). The problem is that I have to first convert the mongodb data into neo4j nodes/relationships, process the data and send the results back to the mongodb database. The main problems is that we will end up maintaining two databases, something that the development team will not be happy. I have already looked into similar posts mongodb-neo4j and spring data but not sure what to make of them for this problem. these are my questions
1- Is it worth it to add another DB just for the sake of a Recommendation engine(we are dealing with a large network), although neo4j is a perfect fit for such task.
2- I am using cypher for queries and don't know much about java, rest API and spring data. What kind of API should I use for mongodb-neo4j communications? My current solution is to use R and use it as the platform to connect to both mongodb and neo4j.
3- How about other graph databases, is there one that is ore fit to integrate with Mongo?

4

5 に答える 5

4

mongodb と Neo4j を統合する 2 つの方法を見つけました。最初のものは、 Gmongoと一緒に Gremlin を使用してryan1234によって提案されました。この優れたブログによると、手順は次のとおりです。1- GmongoJava mongo ドライバー
を ダウンロードします 。2- neo4j/lib ディレクトリの下に 2 つの jar ファイルをコピーします。3- これは一例です。mongodb にこのコレクション (以下と呼ばれる) があるとします。

{ "_id" : ObjectId("4ff74c4ae4b01be7d54cb2d3"), "followed" : "1", "followedBy" : "3", "createdAt" : ISODate("2013-01-01T20:36:26.804Z") }
{ "_id" : ObjectId("4ff74c58e4b01be7d54cb2d4"), "followed" : "2", "followedBy" : "3", "createdAt" : ISODate("2013-01-15T20:36:40.211Z") }
{ "_id" : ObjectId("4ff74d13e4b01be7d54cb2dd"), "followed" : "1", "followedBy" : "2", "createdAt" : ISODate("2013-01-07T20:39:47.283Z") }

Neo4j の Gremlin シェルから次のコマンドを実行します。

import com.gmongo.GMongo
mongo = new GMongo() 
db = mongo.getDB("local")
db.follows.findOne().followed
x=[] as Set; db.follows.find().each{x.add(it.followed); x.add(it.followedBy)}
x.each{g.addVertex(it)}
db.follows.find().each{g.addEdge(g.v(it.followedBy),g.v(it.followed),'follows',[followsTime:it.createdAt.getTime()])} 

これで、neo4j で同等のグラフが作成されました。

于 2013-03-19T20:15:50.603 に答える
2

https://github.com/tinkerpop/gremlin/wiki

グレムリン!

特に Neo4j/graph データベースで動作するように設計されています。また、GMongo を簡単にダウンロードして、Mongo に接続することもできます。

Gremlin で多言語データを操作する方法について説明しているこの記事を確認してください。

http://thinkaurelius.com/2013/02/04/polyglot-persistence-and-query-with-gremlin/

于 2013-03-18T19:15:02.307 に答える
0

R を使用する場合は、別の解決策があります。次の R コードは、mongodb からデータを取得します。

library(RMongo)
library('bitops')
library('RCurl')
library('RJSONIO')
mg <- mongoDbConnect("local", "127.0.0.1", 27017)
mongoData <- dbGetQuery(mg, 'follows',"{}")

結果は次のようになります

  followed followedBy                    createdAt
1        1          3 Tue Jan 01 15:36:26 EST 2013
2        2          3 Tue Jan 15 15:36:40 EST 2013
3        1          2 Mon Jan 07 15:39:47 EST 2013

次の R コードは、Neo4j に接続してグラフを作成します。効率的ではありませんが、機能します

query <- function(querystring) {
  h = basicTextGatherer()
  curlPerform(url="http://localhost:7474/db/data/ext/CypherPlugin/graphdb/execute_query",
    postfields=paste('query',curlEscape(querystring), sep='='),
    writefunction = h$update,
    verbose = TRUE
  )

  result <- fromJSON(h$value())
  data <- data.frame(t(sapply(result$data, unlist)))
  names(data) <- result$columns
   data

}

nodes<-unique(c(mongoData$followed,mongoData$followedBy))
nodes=paste("_",nodes,sep="")
nodes<-paste(paste("(",nodes,collapse="),"),")")

edges<-apply(mongoData[,3:2],1,function(x) paste("_",x,sep="",collapse="-[:follows]->"))
edges<-paste(edges,collapse=",")    

cmd<-paste(nodes,edges,sep=",")
cmd=paste("create",cmd)
query(cmd)
于 2013-03-19T20:25:37.460 に答える
0

Did you take a look at Reco4j? It uses neo4j as underlying graph database. They have implemented few algorithms as part of project. Here is link reco4j. The link is currently unavailable but I found the features good when I had visited the site.

于 2014-02-17T11:54:27.453 に答える