コード例 #1
0
        private List <NodeGroup> PlaneNodeGroupByQuerySparqlId(String querySparqlId, NodeGroup startingState)
        {
            // get every instance of the given type.
            List <Node>      classInstances_temp = this.resultNodesBySparqlId[querySparqlId];
            List <NodeGroup> tempDisplayNgs      = new List <NodeGroup>();

            // need to check the starting state against the classinstances. otherwise, we get some weird results:
            List <Node> classInstances = new List <Node>();
            List <Node> checkList      = startingState.GetNodeList();

            foreach (Node ndCheck in classInstances_temp)
            {
                if (checkList.Contains(ndCheck))
                {
                    classInstances.Add(ndCheck);
                }
            }


            // we need to create a blackList precursor that selectively contains the proper classes. it has to remove all of the instances
            // of the class instances that does not also labeled to another query SparqlID. Any with multiple bindings may still be valid.

            List <Node> blackListPrecursor = new List <Node>();

            foreach (Node nd in classInstances)
            {   // if the node has more than one query sparqlId, leave it off the blacklist.
                if (nd.GetOriginalSparqlIdsFromInstanceData() != null && nd.GetOriginalSparqlIdsFromInstanceData().Count > 1)
                {
                    continue;
                }
                else
                {
                    blackListPrecursor.Add(nd);
                }
            }

            // create a new NodeGroup for each of the instances, as they are planed this way
            foreach (Node currInst in classInstances)
            {   // create the basics and add the base node itself
                NodeGroup nxt = new NodeGroup();
                nxt.AddOrphanedNode(currInst);

                // add this nodeGroup to the collection of ones of interest:
                tempDisplayNgs.Add(nxt);

                // get all the descentends of the current instance.
                List <Node> instDescendents = startingState.GetSubNodes(currInst);

                // get all of the parents of the current instance.
                List <Node> instAncestors = this.GetUpstreamNodes(currInst);

                // get all of the parent's descendents (except the values in the classInstances list)
                List <Node> blackList = new List <Node>();



                blackList.AddRange(classInstances);
                blackList.AddRange(instDescendents);

                List <Node> additionalFamilyTree = this.GetDescendentsNotInBlackList(instAncestors, blackList);

                // add everything to the new NodeGroup.
                foreach (Node dn in instDescendents)
                {
                    nxt.AddOrphanedNode(dn);
                }
                foreach (Node pn in instAncestors)
                {
                    nxt.AddOrphanedNode(pn);
                }
                foreach (Node fm in additionalFamilyTree)
                {
                    nxt.AddOrphanedNode(fm);
                }
            }

            tempDisplayNgs = this.PrunePlanedNodeGroups(tempDisplayNgs);

            Debug.WriteLine("Processed " + this.planedNodeGroups.Count + " islands from a total of " + startingState.GetNodeCount() + " instance nodes using " + querySparqlId + " to perform the splits.");

            // lets learn a bit about each:
            int ngCount = 0;

            foreach (NodeGroup island in tempDisplayNgs)
            {
                Debug.WriteLine("NodeGroup ID:" + ngCount + " has " + island.GetNodeCount() + " total nodes. it has " + " instances of " + querySparqlId + ". ");
                Debug.WriteLine("content was: ");
                foreach (Node nd in island.GetNodeList())
                {
                    Debug.WriteLine("-- " + nd.GetInstanceValue() + "[" + nd.GetFullUriName() + "]");
                }
                ngCount++;
            }

            return(tempDisplayNgs);
        }