Exemple #1
0
        public void TestAddIgnoresDuplicates()
        {
            var c = new TripleCollection();

            c.Add(T1);
            c.Add(T1);
            Assert.AreEqual(1, c.Count());
            Assert.IsTrue(c.Items.Any(x => x.Equals(T1)));
        }
Exemple #2
0
        /// <summary>
        /// Internal method which generates the HTML Output for the Graph
        /// </summary>
        /// <param name="context">Writer Context</param>
        private void GenerateOutput(HtmlWriterContext context)
        {
            // Page Header
            context.HtmlWriter.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\">");
            context.HtmlWriter.WriteLine();
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Html);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Head);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Title);
            context.HtmlWriter.WriteEncodedText("RDF Graph");
            if (context.Graph.BaseUri != null)
            {
                context.HtmlWriter.WriteEncodedText(" - " + context.Graph.BaseUri.AbsoluteUri);
            }
            context.HtmlWriter.RenderEndTag();
            if (!Stylesheet.Equals(String.Empty))
            {
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, Stylesheet);
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Link);
                context.HtmlWriter.RenderEndTag();
            }
            // TODO: Add <meta> for charset?
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.WriteLine();

            // Start Body
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Body);

            // Title
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H3);
            context.HtmlWriter.WriteEncodedText("RDF Graph");
            if (context.Graph.BaseUri != null)
            {
                context.HtmlWriter.WriteEncodedText(" - " + context.Graph.BaseUri.AbsoluteUri);
            }
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.WriteLine();

            // Create a Table for the Graph
            context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Table);

            // Create a Table Header
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Thead);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);
            context.HtmlWriter.WriteEncodedText("Subject");
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);
            context.HtmlWriter.WriteEncodedText("Predicate");
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);
            context.HtmlWriter.WriteEncodedText("Object");
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.WriteLine();

            // Create a Table Body for the Triple
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);

            TripleCollection triplesDone = new TripleCollection();

            foreach (INode subj in context.Graph.Triples.SubjectNodes)
            {
                IEnumerable <Triple> ts = context.Graph.GetTriplesWithSubject(subj);

                // Start a Row
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

                // Then a Column for the Subject which spans the correct number of Rows
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rowspan, ts.Count().ToString());

                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);
                context.HtmlWriter.WriteLine();

                // For each Subject add an anchor if it can be reduced to a QName
                if (subj.NodeType == NodeType.Uri)
                {
                    String qname;
                    if (context.QNameMapper.ReduceToQName(subj.ToString(), out qname))
                    {
                        if (!qname.EndsWith(":"))
                        {
                            qname = qname.Substring(qname.IndexOf(':') + 1);
                            context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Name, qname);
                            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A);
                            context.HtmlWriter.RenderEndTag();
                        }
                    }
                }

                GenerateNodeOutput(context, subj);
                context.HtmlWriter.WriteLine();
                context.HtmlWriter.RenderEndTag();
                context.HtmlWriter.WriteLine();

                bool firstPred = true;
                foreach (Triple t in ts)
                {
                    if (triplesDone.Contains(t))
                    {
                        continue;
                    }
                    if (!firstPred)
                    {
                        // If not the first Triple start a new row
                        context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                        context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
                    }

                    // Then a Column for the Predicate
                    IEnumerable <Triple> predTriples = context.Graph.GetTriplesWithSubjectPredicate(t.Subject, t.Predicate);
                    context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rowspan, predTriples.Count().ToString());
                    context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);
                    context.HtmlWriter.WriteLine();
                    GenerateNodeOutput(context, t.Predicate);
                    context.HtmlWriter.WriteLine();
                    context.HtmlWriter.RenderEndTag();
                    context.HtmlWriter.WriteLine();

                    // Then we write out all the Objects
                    bool firstObj = true;
                    foreach (Triple predTriple in predTriples)
                    {
                        if (triplesDone.Contains(predTriple))
                        {
                            continue;
                        }
                        if (!firstObj)
                        {
                            // If not the first Triple start a new row
                            context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
                        }

                        // Object Column
                        context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);
                        context.HtmlWriter.WriteLine();
                        GenerateNodeOutput(context, predTriple.Object, predTriple);
                        context.HtmlWriter.WriteLine();
                        context.HtmlWriter.RenderEndTag();
                        context.HtmlWriter.WriteLine();

                        // End of Row
                        context.HtmlWriter.RenderEndTag();
                        context.HtmlWriter.WriteLine();
                        firstObj = false;

                        triplesDone.Add(predTriple);
                    }
                    firstPred = false;
                }
            }


            // End Table Body
            context.HtmlWriter.RenderEndTag();

            // End Table
            context.HtmlWriter.RenderEndTag();

            // End of Page
            context.HtmlWriter.RenderEndTag(); //End Body
            context.HtmlWriter.RenderEndTag(); //End Html
        }
Exemple #3
0
        /// <summary>
        /// Internal method which generates the HTML Output for the Graph
        /// </summary>
        /// <param name="context">Writer Context</param>
        private void GenerateOutput(HtmlWriterContext context)
        {
            //Page Header
            context.HtmlWriter.Write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML+RDFa 1.0//EN\" \"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd\">");
            context.HtmlWriter.WriteLine();
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Html);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Head);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Title);
            context.HtmlWriter.WriteEncodedText("RDF Graph");
            if (context.Graph.BaseUri != null)
            {
                context.HtmlWriter.WriteEncodedText(" - " + context.Graph.BaseUri.ToString());
            }
            context.HtmlWriter.RenderEndTag();
            if (!this.Stylesheet.Equals(String.Empty))
            {
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Href, this.Stylesheet);
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Type, "text/css");
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rel, "stylesheet");
                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Link);
                context.HtmlWriter.RenderEndTag();
            }
            //TODO: Add <meta> for charset?
            context.HtmlWriter.RenderEndTag();
#if !NO_WEB
            context.HtmlWriter.WriteLine();
#endif

            //Start Body
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Body);

            //Title
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.H3);
            context.HtmlWriter.WriteEncodedText("RDF Graph");
            if (context.Graph.BaseUri != null)
            {
                context.HtmlWriter.WriteEncodedText(" - " + context.Graph.BaseUri.ToString());
            }
            context.HtmlWriter.RenderEndTag();
#if !NO_WEB
            context.HtmlWriter.WriteLine();
#endif

            //Create a Table for the Graph
            context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Width, "100%");
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Table);

            //Create a Table Header
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Thead);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);
            context.HtmlWriter.WriteEncodedText("Subject");
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);
            context.HtmlWriter.WriteEncodedText("Predicate");
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Th);
            context.HtmlWriter.WriteEncodedText("Object");
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderEndTag();
            context.HtmlWriter.RenderEndTag();
#if !NO_WEB
            context.HtmlWriter.WriteLine();
#endif

            //Create a Table Body for the Triple
            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tbody);

            TripleCollection triplesDone = new TripleCollection();
            foreach (INode subj in context.Graph.Triples.SubjectNodes)
            {
                IEnumerable<Triple> ts = context.Graph.GetTriplesWithSubject(subj);

                //Start a Row
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);

                //Then a Column for the Subject which spans the correct number of Rows
                context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rowspan, ts.Count().ToString());

                context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);
#if !NO_WEB
                context.HtmlWriter.WriteLine();
#endif
                //For each Subject add an anchor if it can be reduced to a QName
                if (subj.NodeType == NodeType.Uri)
                {
                    String qname;
                    if (context.QNameMapper.ReduceToQName(subj.ToString(), out qname))
                    {
                        if (!qname.EndsWith(":"))
                        {
                            qname = qname.Substring(qname.IndexOf(':') + 1);
                            context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Name, qname);
                            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.A);
                            context.HtmlWriter.RenderEndTag();
                        }
                    }
                }

                this.GenerateNodeOutput(context, subj);
#if !NO_WEB
                context.HtmlWriter.WriteLine();
#endif
                context.HtmlWriter.RenderEndTag();
#if !NO_WEB
                context.HtmlWriter.WriteLine();
#endif

                bool firstPred = true;
                foreach (Triple t in ts)
                {
                    if (triplesDone.Contains(t)) continue;
                    if (!firstPred)
                    {
                        //If not the first Triple start a new row
                        context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                        context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
                    }

                    //Then a Column for the Predicate
                    IEnumerable<Triple> predTriples = context.Graph.GetTriplesWithSubjectPredicate(t.Subject, t.Predicate);
                    context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Rowspan, predTriples.Count().ToString());
                    context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);
#if !NO_WEB
                    context.HtmlWriter.WriteLine();
#endif
                    this.GenerateNodeOutput(context, t.Predicate);
#if !NO_WEB
                    context.HtmlWriter.WriteLine();
#endif
                    context.HtmlWriter.RenderEndTag();
#if !NO_WEB
                    context.HtmlWriter.WriteLine();
#endif

                    //Then we write out all the Objects
                    bool firstObj = true;
                    foreach (Triple predTriple in predTriples)
                    {
                        if (triplesDone.Contains(predTriple)) continue;
                        if (!firstObj)
                        {
                            //If not the first Triple start a new row
                            context.HtmlWriter.AddAttribute(HtmlTextWriterAttribute.Valign, "top");
                            context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Tr);
                        }

                        //Object Column
                        context.HtmlWriter.RenderBeginTag(HtmlTextWriterTag.Td);
#if !NO_WEB
                        context.HtmlWriter.WriteLine();
#endif
                        this.GenerateNodeOutput(context, predTriple.Object, predTriple);
#if !NO_WEB
                        context.HtmlWriter.WriteLine();
#endif
                        context.HtmlWriter.RenderEndTag();
#if !NO_WEB
                        context.HtmlWriter.WriteLine();
#endif

                        //End of Row
                        context.HtmlWriter.RenderEndTag();
#if !NO_WEB
                        context.HtmlWriter.WriteLine();
#endif
                        firstObj = false;

                        triplesDone.Add(predTriple);
                    }
                    firstPred = false;
                }
            }


            //End Table Body
            context.HtmlWriter.RenderEndTag();

            //End Table
            context.HtmlWriter.RenderEndTag();

            //End of Page
            context.HtmlWriter.RenderEndTag(); //End Body
            context.HtmlWriter.RenderEndTag(); //End Html
        }
Exemple #4
0
        public void TestAddRaisesArgumentNullException()
        {
            var c = new TripleCollection();

            c.Add(null);
        }