public static WeightedGraph <ReadingTag> createWeightedGraph(int projectId, bool includeReadingTags, bool includeHighlightTags)
        {
            string str = DatabaseInterface.databaseConnectionStr;

            using (SqlConnection con = new SqlConnection(str))
            {
                WeightedGraph <ReadingTag>        graph;
                List <Vertex <ReadingTag> >       vertices = new List <Vertex <ReadingTag> >();
                List <WeightedEdge <ReadingTag> > edges    = new List <WeightedEdge <ReadingTag> >();
                DatabaseInterface.getReadingLinks(con, false);
                List <ReadingTag>   tags  = DatabaseInterface.getReadingTags(null, con, false);
                List <HighlightTag> hTags = DatabaseInterface.getHighlightTags(null, con, false);
                int            numTags    = tags.Count();
                List <TagLink> tagLinks   = DatabaseInterface.getReadingLinks(con, false);
                //List<List<List<int>>> table = new List<List<List<int>>>();
                List <int>[,] table = new List <int> [numTags, numTags];

                foreach (TagLink l in tagLinks)
                {
                    if (table[l.t1, l.t2] == null)
                    {
                        table[l.t1, l.t2] = new List <int>();
                    }
                    table[l.t1, l.t2].Add(l.rId);
                }

                Dictionary <string, Vertex <ReadingTag> > dick = new Dictionary <string, Vertex <ReadingTag> >();

                foreach (ReadingTag t in tags)
                {
                    Vertex <ReadingTag> v = new Vertex <ReadingTag>(t);
                    dick.Add(t.tagId.ToString(), v);
                    vertices.Add(v);
                }

                for (int i = 0; i < tags.Count(); i++)
                {
                    for (int j = 0; j < tags.Count(); j++)
                    {
                        if (table[i, j] != null && table[i, j].Count() > 0)
                        {
                            WeightedEdge <ReadingTag> edge = new WeightedEdge <ReadingTag>(dick[i.ToString()], dick[j.ToString()], table[i, j].Count());
                            edge.ReadingIds = table[i, j];
                            edges.Add(edge);
                        }
                    }
                }
                graph = new WeightedGraph <ReadingTag>(vertices, edges);
                return(graph);
            }
        }
示例#2
0
        private WeightedGraph <ReadingTag> createTagGraph()
        {
            string str = DatabaseInterface.databaseConnectionStr;
            WeightedGraph <ReadingTag> graph;

            using (SqlConnection con = new SqlConnection(str))
            {
                // Vertex<ReadingTag> startTag = null;
                List <Vertex <ReadingTag> >       vertices = new List <Vertex <ReadingTag> >();
                List <WeightedEdge <ReadingTag> > edges    = new List <WeightedEdge <ReadingTag> >();
                List <ReadingTag> tags = DatabaseInterface.getReadingTags(null, con, false);
                tags = DatabaseInterface.getHighlight_ReadingTags(tags, null, con, false);
                int            numTags  = tags.Count();
                List <TagLink> tagLinks = DatabaseInterface.getReadingLinks(con, false);
                tagLinks.AddRange(DatabaseInterface.getHighlightLinks(con, false));
                //List<List<List<int>>> table = new List<List<List<int>>>();
                List <int>[,] table = new List <int> [numTags, numTags];

                foreach (TagLink l in tagLinks)
                {
                    if (table[l.t1, l.t2] == null)
                    {
                        table[l.t1, l.t2] = new List <int>();
                    }
                    table[l.t1, l.t2].Add(l.rId);
                }

                Dictionary <string, Vertex <ReadingTag> > dict = new Dictionary <string, Vertex <ReadingTag> >();

                foreach (ReadingTag t in tags)
                {
                    Vertex <ReadingTag> v = new Vertex <ReadingTag>(t);
                    if (!dict.ContainsKey(t.tagId.ToString()))
                    {
                        dict.Add(t.tagId.ToString(), v);
                        vertices.Add(v);
                    }
                }

                for (int i = 0; i < tags.Count(); i++)
                {
                    for (int j = 0; j < tags.Count(); j++)
                    {
                        if (table[i, j] != null && table[i, j].Count() > 0)
                        {
                            //TODO: might have error here with readingIds array
                            WeightedEdge <ReadingTag> edge  = new WeightedEdge <ReadingTag>(dict[i.ToString()], dict[j.ToString()], table[i, j].Count());
                            WeightedEdge <ReadingTag> edge2 = new WeightedEdge <ReadingTag>(dict[j.ToString()], dict[i.ToString()], table[i, j].Count());
                            edge.ReadingIds  = table[i, j];
                            edge2.ReadingIds = table[i, j];
                            edges.Add(edge2);
                            edges.Add(edge);
                            dict[i.ToString()].AddEdge(edge);
                            dict[j.ToString()].AddEdge(edge2);
                        }
                    }
                }


                graph = new WeightedGraph <ReadingTag>(vertices, edges);
                beginningTag.DataSource    = graph.vertices;
                beginningTag.DisplayMember = "Value";

                return(graph);
            }
        }