コード例 #1
0
        public void TestWriteFormulaWithTwoStatements()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);

            BNode statementId = new BNode("s");

            instance.Add(new Statement("A", "b", (Entity)"C", statementId));
            instance.Add(new Statement("D", "e", (Entity)"F", statementId));
            instance.Close();

            // should not repeat "_:s a log:Formula"
            string expected = "_:s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/10/swap/log#Formula>.\n" +
                              "_:s <http://www.w3.org/2000/10/swap/log#includes> _:bnode.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <A>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <b>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> <C>.\n" +
                              "_:s <http://www.w3.org/2000/10/swap/log#includes> _:bnode.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <D>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <e>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> <F>.\n";

            Assert.AreEqual(expected, Regex.Replace(writer.ToString(), @"_:bnode\d+", "_:bnode"));
        }
コード例 #2
0
        public void TestWriteStatementWithLiteralHavingDataType()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);

            instance.Add(new Statement("A", "b", Literal.FromValue("C")));
            instance.Close();

            string expected = "<A> <b> \"C\"^^<http://www.w3.org/2001/XMLSchema#string>.\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #3
0
        public void TestWriteStatementWithLiteralHavingLanguage()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);

            instance.Add(new Statement("A", "b", new Literal("C", "en", "http://www.w3.org/2001/XMLSchema#string")));
            instance.Close();

            string expected = "<A> <b> \"C\"@en.\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #4
0
        public void TestWriteStatementWithLiteral()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);

            instance.Add(new Statement("A", "b", new Literal("C")));
            instance.Close();

            string expected = "<A> <b> \"C\".\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #5
0
        public void TestWriteStatementWithAnonymousBNode()
        {
            BNode          bNode    = new BNode();
            NTriplesWriter instance = new NTriplesWriter(writer);

            instance.Add(new Statement(bNode, "b", (Entity)"C"));
            instance.Close();

            string expected = bNode + " <b> <C>.\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #6
0
        public void TestWriteEscapesAllResources()
        {
            // note: should test for unicode characters >= \U0001000,
            //       but Mono on Linux does not support this. (works in Windows .Net)
            string subject = "http://\u00E9xampl\u00E8.org/\t\n\u000B\u000C\r\u000E\u0012\u001F";

            NTriplesWriter instance = new NTriplesWriter(writer);
            instance.Namespaces.AddNamespace("http://\u00E9xampl\u00E8.org/", "ex");
            instance.Add(new Statement(subject, "\uABCD", (Literal)"\u0020\u0021\u000A"));
            instance.Close();

            string expected = @"<http://\u00E9xampl\u00E8.org/\t\n\u000B\u000C\r\u000E\u0012\u001F> <\uABCD> " + "\" !\\n\".\n";
            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #7
0
        public void TestWriteEscapesAllResources()
        {
            // note: should test for unicode characters >= \U0001000,
            //       but Mono on Linux does not support this. (works in Windows .Net)
            string subject = "http://\u00E9xampl\u00E8.org/\t\n\u000B\u000C\r\u000E\u0012\u001F";

            NTriplesWriter instance = new NTriplesWriter(writer);

            instance.Namespaces.AddNamespace("http://\u00E9xampl\u00E8.org/", "ex");
            instance.Add(new Statement(subject, "\uABCD", (Literal)"\u0020\u0021\u000A"));
            instance.Close();

            string expected = @"<http://\u00E9xampl\u00E8.org/\t\n\u000B\u000C\r\u000E\u0012\u001F> <\uABCD> " + "\" !\\n\".\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #8
0
        public void TestWriteFormulaWithOneStatement()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);

            BNode statementId = new BNode("s");
            instance.Add(new Statement("A", "b", (Entity)"C", statementId));
            instance.Close();

            string expected = "_:s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/10/swap/log#Formula>.\n" +
                              "_:s <http://www.w3.org/2000/10/swap/log#includes> _:bnode.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#subject> <A>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate> <b>.\n" +
                              "_:bnode <http://www.w3.org/1999/02/22-rdf-syntax-ns#object> <C>.\n";
            Assert.AreEqual(expected, Regex.Replace(writer.ToString(), @"_:bnode\d+", "_:bnode"));
        }
コード例 #9
0
        public void TestWriteSimpleStatements()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);

            instance.Add(new Statement("S", Predicate.RdfType, (Entity)"X"));
            instance.Add(new Statement("S", Predicate.RdfType, (Entity)"Y"));
            instance.Add(new Statement("S", "o", (Entity)"Z"));
            instance.Add(new Statement("P", "o", (Literal)"s"));
            instance.Close();

            string expected = "<S> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <X>.\n" +
                              "<S> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <Y>.\n" +
                              "<S> <o> <Z>.\n" +
                              "<P> <o> \"s\".\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #10
0
        public virtual void TestWriteStatementWithLiteral()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);
            instance.Add(new Statement("A", "b", new Literal("C")));
            instance.Close();

            string expected = "<A> <b> \"C\".\n";
            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #11
0
ファイル: validator.cs プロジェクト: JoshData/semweb-dotnet
    public Hashtable Validate()
    {
        string content = HttpContext.Current.Request.Form["content"];
        string format = HttpContext.Current.Request.Form["format"];
        if (content == null || content.Trim() == "" || format == null) {
            HttpContext.Current.Response.Redirect("index.xpd");
            throw new InvalidOperationException();
        }

        StringWriter output = new StringWriter();

        RdfReader reader;
        RdfWriter writer;

        Hashtable response = new Hashtable();

        response["InDocument"] = AddLineNumbers(content);

        if (format == "xml") {
            reader = new RdfXmlReader(new StringReader(content));
            writer = new N3Writer(output);
            response["InFormat"] = "RDF/XML";
            response["OutFormat"] = "Notation 3";
        } else if (format == "n3") {
            reader = new N3Reader(new StringReader(content));
            writer = new RdfXmlWriter(output);
            response["OutFormat"] = "RDF/XML";
            response["InFormat"] = "Notation 3";
        } else {
            throw new Exception("Invalid format.");
        }

        response["Validation"] = "Syntax validated OK.";

        response["OutDocument"] = "";
        response["Triples"] = "";

        MemoryStore data = new MemoryStore();
        try {
            data.Import(reader);
        } catch (Exception e) {
            response["Validation"] = "Validation failed: " + e.Message + ".";
            return response;
        } finally {
            if (reader.Warnings.Count > 0) {
                response["Validation"] += "  There were warnings: ";
                foreach (string warning in reader.Warnings)
                    response["Validation"] += " " + warning + ".";
            }
        }

        writer.Namespaces.AddFrom(reader.Namespaces);

        try {
            writer.Write(data);
            writer.Close();
            response["OutDocument"] = output.ToString();
        } catch (Exception e) {
            response["OutDocument"] = e.Message;
        }

        StringWriter triplesoutput = new StringWriter();
        using (NTriplesWriter tripleswriter = new NTriplesWriter(triplesoutput)) {
            tripleswriter.Write(data);
        }
        response["Triples"] = triplesoutput.ToString();

        return response;
    }
コード例 #12
0
        public void TestWriteSimpleStatements()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);
            instance.Add(new Statement("S", Predicate.RdfType, (Entity)"X"));
            instance.Add(new Statement("S", Predicate.RdfType, (Entity)"Y"));
            instance.Add(new Statement("S", "o", (Entity)"Z"));
            instance.Add(new Statement("P", "o", (Literal)"s"));
            instance.Close();

            string expected = "<S> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <X>.\n" +
                              "<S> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <Y>.\n" +
                              "<S> <o> <Z>.\n" +
                              "<P> <o> \"s\".\n";

            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #13
0
        public void TestWriteStatementWithLiteralHavingLanguage()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);
            instance.Add(new Statement("A", "b", new Literal("C", "en", "http://www.w3.org/2001/XMLSchema#string")));
            instance.Close();

            string expected = "<A> <b> \"C\"@en.\n";
            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #14
0
        public void TestWriteStatementWithLiteralHavingDataType()
        {
            NTriplesWriter instance = new NTriplesWriter(writer);
            instance.Add(new Statement("A", "b", Literal.FromValue("C")));
            instance.Close();

            string expected = "<A> <b> \"C\"^^<http://www.w3.org/2001/XMLSchema#string>.\n";
            Assert.AreEqual(expected, writer.ToString());
        }
コード例 #15
0
        public void TestWriteStatementWithAnonymousBNode()
        {
            BNode bNode = new BNode();
            NTriplesWriter instance = new NTriplesWriter(writer);
            instance.Add(new Statement(bNode, "b", (Entity)"C"));
            instance.Close();

            string expected = bNode + " <b> <C>.\n";
            Assert.AreEqual(expected, writer.ToString());
        }