Пример #1
0
        public (bool, List <VisulizedVertex>, List <VisulizedEdge>) GetFirstLevelRelationships(string vId)
        {
            if (this.kgDF == null)
            {
                return(false, null, null);
            }

            Vertex vertex = this.kgDF.GetVertexById(vId);

            if (vertex == null)
            {
                return(true, null, null);
            }

            List <VisulizedVertex> rVVs = new List <VisulizedVertex>();
            List <VisulizedEdge>   rVEs = new List <VisulizedEdge>();

            if (vertex.properties != null && vertex.properties.Count > 0)
            {
                foreach (VertexProperty property in vertex.properties)
                {
                    VisulizedVertex vP = KGUtility.GeneratePropertyVVertex(vertex.label, property.name, property.value);
                    rVVs.Add(vP);

                    VisulizedEdge vEdge = new VisulizedEdge();
                    vEdge.value    = vP.displayName;
                    vEdge.sourceId = vertex.id;
                    vEdge.targetId = vP.id;

                    rVEs.Add(vEdge);
                }
            }

            List <VisulizedVertex> tmpRVVs;
            List <VisulizedEdge>   tmpRVEs;

            Dictionary <RelationLink, List <string> > childrenLinkDict = this.kgDF.GetChildrenLinkDict(vId);

            HashSet <string> addedIDs = new HashSet <string>();

            if (childrenLinkDict != null)
            {
                (tmpRVVs, tmpRVEs) = GetConnectedVertexesAndEdges(addedIDs, vId, childrenLinkDict, true);

                rVVs.AddRange(tmpRVVs);
                rVEs.AddRange(tmpRVEs);
            }

            Dictionary <RelationLink, List <string> > parentLinkDict = this.kgDF.GetParentLinkDict(vId);

            if (parentLinkDict != null)
            {
                (tmpRVVs, tmpRVEs) = GetConnectedVertexesAndEdges(addedIDs, vId, parentLinkDict, false);

                rVVs.AddRange(tmpRVVs);
                rVEs.AddRange(tmpRVEs);
            }

            return(true, rVVs, rVEs);
        }
Пример #2
0
        public async Task <ActionResult <IResult> > Filter(string datastoreName, string name, string value)
        {
            RelationResult filterResult;

            if (string.IsNullOrWhiteSpace(datastoreName) || string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(value))
            {
                filterResult = new RelationResult(false, "datastoreName, 属性名和属性值都不能为空");
            }
            else
            {
                name  = name.ToLower();
                value = value.ToLower();

                GraphExecutor executor = new GraphExecutor(datastoreName);
                (bool isDSExist, List <VisulizedVertex> vvs) = executor.FilterVertexesByProperty(name, value);

                if (!isDSExist)
                {
                    filterResult = new RelationResult(false, "Datastore " + datastoreName + "不存在,或没有数据导入。");
                }
                else
                {
                    if (vvs == null || vvs.Count == 0)
                    {
                        filterResult = new RelationResult(true, "根据\"" + name + " = " + value + ",\"未能找到任何符合条件的节点。");
                    }
                    else
                    {
                        VisulizedVertex propertyVV = KGUtility.GeneratePropertyVVertex("", name, value);
                        filterResult = new RelationResult(true, "根据\"" + name + " = " + value + ",\"为您搜索到以下节点:");

                        List <VisulizedEdge> ves = new List <VisulizedEdge>();

                        foreach (VisulizedVertex vv in vvs)
                        {
                            VisulizedEdge ve = new VisulizedEdge();

                            ve.value    = name;
                            ve.sourceId = propertyVV.id;
                            ve.targetId = vv.id;

                            ves.Add(ve);
                        }

                        vvs.Insert(0, propertyVV);

                        filterResult.nodes     = vvs;
                        filterResult.relations = ves;
                    }
                }
            }

            log.Here().Information("[Response]: " + JsonConvert.SerializeObject(filterResult));

            return(Ok(filterResult));
        }