private static CypherResult ExecuteMirrorGremlin(string script, AlgoContext context, int[] productIds) { try { Neo4jContext client = new Neo4jContext(false); Dictionary <string, object> parameters = new Dictionary <string, object>(); foreach (RecommendationContext item in context.Context.Keys) { parameters["pMap" + item.ToString()] = context.Context[item]; } if (productIds != null && productIds.Count() > 0) { parameters["pMapProductsId"] = productIds; } string response = client.ExecuteGremlinScript(new Script { ScriptStr = script, ParameterMap = parameters }); return(JsonConvert.DeserializeObject <CypherResult>(response)); } catch (Exception e) { Log.Error("ExecuteMirrorQuery", "Error executing query", e); throw; } }
public static bool SendData(IEnumerable <AntVoice.Common.Entities.Neo.GraphNode> nodes) { Neo4jContext _context = new Neo4jContext(true); string json = JsonConvert.SerializeObject(new { data = JsonConvert.SerializeObject(new { nodes = nodes }) }); string result = _context.InsertData(json); try { InsertDataResult res = (InsertDataResult)JsonConvert.DeserializeObject(result, typeof(InsertDataResult)); if (res.Status == "OK") { Log.Debug("NodeHandler.Handle", "The data insertion went fine"); return(true); } else { Log.Error("NodeHandler.Handle", "An error occured while inserting the data", res.Message); return(false); } } catch (Exception e) { MonitoringTimers.Current.AddError(Counters.Neo4j_InsertDataPluginError); Log.Error("GraphDataAccess.SendData", "An error occured while deserializing the following Neo4j response", result); } return(false); }
public CypherHandler(BaseNode node, IEnumerable <Relationship> rels) { _actions = new List <GraphAction>(); _context = new Neo4jContext(true); _node = node; _rels = rels; }
public GremlinHandler(BaseNode node, IEnumerable <Relationship> rels) : base() { Rels = new List <Relationship>(); _context = new Neo4jContext(false); Node = node; Rels.AddRange(rels); }
private static CypherResult ExecuteMirrorCypherQuery(string query, AlgoContext context, int[] productIds) { try { Log.Debug("ExecuteMirrorQuery", "Building query from parameters", query); string filteredQuery = BuildMirrorQuery(query, productIds); Log.Debug("ExecuteMirrorQuery", "Query built from parameters", filteredQuery); Neo4jContext client = new Neo4jContext(false); Dictionary <string, string> parameters = new Dictionary <string, string>(); foreach (RecommendationContext item in context.Context.Keys) { parameters[item.ToString()] = context.Context[item]; } string response = client.GetWithCypherQuery(filteredQuery, parameters); return(JsonConvert.DeserializeObject <CypherResult>(response)); } catch (Exception e) { Log.Error("ExecuteMirrorQuery", "Error executing query", e); throw; } }
private static CypherResult ExecuteCypherRecommendation(string query, ContentTypeDistribution distribution, AggregateFilter filters, AlgoContext context, out string requestString) { try { Log.Debug("ExecuteRecommendationQuery", "Building query from parameters", query); string filteredQuery = BuildCypherRecommendationQuery(query, filters, distribution); Log.Debug("ExecuteRecommendationQuery", "Query built from parameters", filteredQuery); Neo4jContext client = new Neo4jContext(false); Dictionary <string, string> parameters = new Dictionary <string, string>(); foreach (RecommendationContext item in context.Context.Keys) { parameters[item.ToString()] = context.Context[item]; } string response = client.GetWithCypherQuery(filteredQuery, parameters, out requestString); return(JsonConvert.DeserializeObject <CypherResult>(response)); } catch (Exception e) { Log.Error("ExecuteRecommendationQuery", "Error executing query", e); throw; } }
public static CypherResult ExecuteGremlinRecommendation(string query, ContentTypeDistribution distribution, AggregateFilter filters, AlgoContext context, out string requestString) { try { string filteredQuery = BuildGremlinQuery(query, filters, distribution); Log.Debug("ExecuteGremlinRecommendation", "Query built from parameters"); Neo4jContext client = new Neo4jContext(false); Dictionary <string, object> parameters = new Dictionary <string, object>(); foreach (RecommendationContext item in context.Context.Keys) { parameters["pMap" + item.ToString()] = context.Context[item]; } Script gremlinScript = new Script { ScriptStr = filteredQuery, ParameterMap = parameters }; string response = client.ExecuteGremlinScript(gremlinScript, out requestString); if (!string.IsNullOrEmpty(response)) { return(JsonConvert.DeserializeObject <CypherResult>(response)); } else { return(null); } } catch (Exception e) { Log.Error("ExecuteRecommendationQuery", "Error executing query", e); throw; } }
public Neo4jRepository(IOptions <Settings> settings) { _context = new Neo4jContext(settings); }
protected BaseHandler() { Actions = new List <GraphAction>(); _context = new Neo4jContext(true); }