public bool UpdateColorConfig(string user, string dsName, string scenarioName, List <ColorConfig> colorConfigs) { if (!IsDataStoreExist(dsName)) { return(false); } IMongoDatabase db = client.GetDatabase(dsName); IMongoCollection <VisulizationConfig> collection = db.GetCollection <VisulizationConfig>("VisulizationConfigs"); var deleteFilter = Builders <VisulizationConfig> .Filter.Eq("scenario", scenarioName); collection.DeleteOne(deleteFilter); VisulizationConfig vConfig = new VisulizationConfig(); vConfig.scenario = scenarioName; vConfig.labelsOfVertexes = colorConfigs; collection.InsertOne(vConfig); return(true); }
public bool UpdateColorConfig(string user, string dsName, string scenarioName, List <ColorConfig> colorConfigs) { if (string.IsNullOrWhiteSpace(dsName)) { log.Here().Error("Error: The datastore: " + dsName + " doesn't exist."); return(false); } if (string.IsNullOrWhiteSpace(scenarioName)) { log.Here().Error("Error: The scenario: " + scenarioName + " doesn't exist."); return(false); } string vcDir = this.rootPath + Path.DirectorySeparatorChar + dsName + Path.DirectorySeparatorChar; if (string.IsNullOrWhiteSpace(vcDir) || !Directory.Exists(vcDir)) { log.Here().Warning("The path of VCFilePath: " + vcDir + " doesn't exist."); return(false); } string vcPath = vcDir + "Visulization" + Path.DirectorySeparatorChar + "VisulizationConfig_" + scenarioName + ".json"; //VisuliaztionImporter vImporter = new VisuliaztionImporter(vcPath); List <VisulizationConfig> vcList = new List <VisulizationConfig>(); if (File.Exists(vcPath)) { string json = System.IO.File.ReadAllText(vcPath); vcList = JsonConvert.DeserializeObject <List <VisulizationConfig> >(json); } bool replaced = false; foreach (VisulizationConfig config in vcList) { if (string.IsNullOrWhiteSpace(config.scenario) || config.scenario != scenarioName) { continue; } else { config.labelsOfVertexes = colorConfigs; replaced = true; break; } } if (!replaced) { VisulizationConfig vc = new VisulizationConfig(); vc.scenario = scenarioName; vc.labelsOfVertexes = colorConfigs; vcList.Add(vc); } using (StreamWriter file = File.CreateText(vcPath)) { JsonSerializer serializer = new JsonSerializer(); serializer.Serialize(file, vcList); } log.Here().Information("Visulization Config data has been parsed from Files."); return(true); }
private (List <NLUIntentRule>, List <EntityData>, VisulizationConfig) GenerateNLUAndConfig(List <Vertex> vertexes, List <Edge> edges, string scenario, string configPath) { VisulizationConfig vConfig = new VisulizationConfig(); vConfig.scenario = scenario; vConfig.labelsOfVertexes = new List <ColorConfig>(); vConfig.relationTypesOfEdges = new List <ColorConfig>(); string hexFilePath = configPath + Path.DirectorySeparatorChar + "HexColorCodeDict.tsv"; string pdFilePath = configPath + Path.DirectorySeparatorChar + "PreDefinedVertexColor.tsv"; Dictionary <string, string> hexDict = new Dictionary <string, string>(); foreach (var line in System.IO.File.ReadLines(hexFilePath)) { string[] tmps = line.Split('\t'); if (hexDict.ContainsKey(tmps[0])) { hexDict[tmps[0]] = tmps[1]; } else { hexDict.Add(tmps[0], tmps[1]); } } Dictionary <string, string> predefinedDict = new Dictionary <string, string>(); foreach (var line in System.IO.File.ReadLines(pdFilePath)) { string[] tmps = line.Split('\t'); if (predefinedDict.ContainsKey(tmps[0])) { predefinedDict[tmps[0]] = tmps[1]; } else { predefinedDict.Add(tmps[0], tmps[1]); } } // --- HashSet <string> entityNameSet = new HashSet <string>(); HashSet <string> entityTypeSet = new HashSet <string>(); HashSet <string> propertyNameSet = new HashSet <string>(); foreach (Vertex vertex in vertexes) { entityTypeSet.Add(vertex.label); entityNameSet.Add(vertex.name); if (vertex.properties != null && vertex.properties.Count > 0) { foreach (VertexProperty p in vertex.properties) { propertyNameSet.Add(p.name); } } } HashSet <string> relationTypeSet = new HashSet <string>(); foreach (Edge edge in edges) { relationTypeSet.Add(edge.relationType); } List <EntityData> entityDatas = new List <EntityData>(); List <NLUIntentRule> intentRuleList = new List <NLUIntentRule>(); NLUIntentRule intentRule = new NLUIntentRule(); intentRule.id = Guid.NewGuid().ToString(); intentRule.intentName = scenario; intentRule.type = IntentRuleType.POSITIVE; intentRule.ruleSecs = new List <string>(); string entityRule = ""; int count = 0; foreach (string entityName in entityNameSet) { if (count % 20 == 0 && count > 0) { entityRule = entityRule.Substring(0, entityRule.Length - 1); intentRule.ruleSecs.Add(entityRule); intentRuleList.Add(intentRule); intentRule = new NLUIntentRule(); intentRule.id = Guid.NewGuid().ToString(); intentRule.intentName = scenario; intentRule.type = IntentRuleType.POSITIVE; intentRule.ruleSecs = new List <string>(); entityRule = ""; } entityRule += entityName + "|"; entityDatas.Add(CreateEntityData(scenario, "NodeName", entityName)); count++; } entityRule = entityRule.Substring(0, entityRule.Length - 1); intentRule.ruleSecs.Add(entityRule); intentRuleList.Add(intentRule); foreach (string entityType in entityTypeSet) { vConfig.labelsOfVertexes.Add(GetColor(hexDict, predefinedDict, entityType)); } foreach (string pName in propertyNameSet) { entityDatas.Add(CreateEntityData(scenario, "PropertyName", pName)); } foreach (string rType in relationTypeSet) { entityDatas.Add(CreateEntityData(scenario, "RelationType", rType)); vConfig.relationTypesOfEdges.Add(GetColor(hexDict, predefinedDict, rType)); } return(intentRuleList, entityDatas, vConfig); }