Пример #1
0
 protected void ExportToN3(DalcRdfStore store)
 {
     using (var n3wr = new N3Writer(Console.Out)) {
         n3wr.Namespaces.AddNamespace("http://www.nreco.qsh.eu/rdf/", "nreco");
         n3wr.Namespaces.AddNamespace("http://www.nreco.qsh.eu/rdf/persons#", "p");
         n3wr.Namespaces.AddNamespace(NS.Rdf.BASE, "rdf");
         n3wr.Namespaces.AddNamespace(NS.Rdfs.BASE, "rdfs");
         store.Select(n3wr);
     }
 }
Пример #2
0
    public static void Main()
    {
        MemoryStore store = new MemoryStore();

        store.Import(new RdfXmlReader(Console.In));

        // The 'using' is important because it is necessary
        // to Close or Dispose the writer once writing is
        // complete so that the final statement is closed
        // with a period.
        using (RdfWriter writer = new N3Writer(Console.Out))
            writer.Write(store);
    }
Пример #3
0
        public void InteropSemWebGraphSource()
        {
            Graph g = new Graph();
            //FileLoader.Load(g, "InferenceTest.ttl");
            GraphSource source = new GraphSource(g);

            Console.WriteLine("Reading the input using SemWeb");
            N3Reader reader = new N3Reader("InferenceTest.ttl");

            reader.Select(source);
            Console.WriteLine();

            Console.WriteLine("Outputting all Triples using N3Writer");
            N3Writer writer = new N3Writer(Console.Out);

            source.Select(writer);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?type");
            Statement template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Variable());

            source.Select(template, writer);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Outputting all Triples of the form ?s rdf:type ?car");
            template = new Statement(new Variable(), new Entity(RdfSpecsHelper.RdfType), new Entity("http://example.org/vehicles/Car"));
            source.Select(template, writer);
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Outputting all Triples for Cars and Planes");
            SelectFilter filter = new SelectFilter();

            filter.Predicates = new Entity[] { new Entity(RdfSpecsHelper.RdfType) };
            filter.Objects    = new Entity[] { new Entity("http://example.org/vehicles/Car"), new Entity("http://example.org/vehicles/Plane") };
            source.Select(filter, writer);
            Console.WriteLine();
            Console.WriteLine();

            writer.Close();
        }
Пример #4
0
        public static string storeToString(Store store)
        {
            StringWriter buf = new StringWriter();

            try
            {
                using (RdfWriter writer = new N3Writer(buf))
                {
                    writer.Namespaces.AddNamespace("http://semanticscience.org/resource/", "sio");
                    writer.Namespaces.AddNamespace("http://purl.oclc.org/SADI/LSRN/", "lsrn");
                    writer.Write(store);
                }
            }
            catch (Exception e)
            {
                buf.WriteLine(e.ToString());
            }
            return(buf.ToString().Replace("\n", Environment.NewLine));
        }
Пример #5
0
        public MemoryStore invokeService(Store input)
        {
            //SADIHelper.debug("SADIService", "sending data to  " + uri, input);
            WebRequest request = WebRequest.Create(this.uri);

            request.ContentType = "text/rdf+n3";
            request.Method      = "POST";
            Stream       stream = request.GetRequestStream();
            StreamWriter writer = new StreamWriter(stream);

///            using (RdfWriter rdfWriter = new RdfXmlWriter("C:\\Users\\Luke\\Desktop\\input.rdf"))
///            {
///                rdfWriter.Write(input);
///            }
///            using (RdfWriter rdfWriter = new RdfXmlWriter(writer))
            using (N3Writer rdfWriter = new N3Writer(writer))
            {
                rdfWriter.Write(input);
            }
            writer.Close();
            stream.Close();

            MemoryStore output   = new MemoryStore();
            WebResponse response = request.GetResponse();

            stream = response.GetResponseStream();
            StreamReader reader = new StreamReader(stream);

            using (RdfReader rdfReader = new RdfXmlReader(reader))
            {
                output.Import(rdfReader);
            }
            reader.Close();
            stream.Close();
            response.Close();
            //SADIHelper.debug("SADIService", "read data from  " + uri, output);

            if (((HttpWebResponse)response).StatusCode == HttpStatusCode.Accepted)
            {
                resolveAsynchronousData(output);
            }
            return(output);
        }
Пример #6
0
    public static void Main(string[] args)
    {
        string uri = "http://www.mozilla.org/news.rdf";

        if (args.Length > 0)
        {
            uri = args[0];
        }

        MemoryStore store = new MemoryStore();

        // Here's one way...

        store.Import(RdfReader.LoadFromUri(new Uri(uri)));

        using (RdfWriter writer = new N3Writer(Console.Out))
            store.Select(writer);

        // Or....

        RdfReader file = RdfReader.LoadFromUri(new Uri(uri));

        file.Select(new StatementPrinter());
    }
Пример #7
0
    public static void Main()
    {
        MemoryStore store = new MemoryStore();

        Entity container = new Entity("http://www.example.org/#container");

        store.Add(new Statement(container, RDF + "type", (Entity)(RDF + "Bag")));
        store.Add(new Statement(container, RDF + "_3", (Literal)"Three"));
        store.Add(new Statement(container, RDF + "_2", (Literal)"Two"));
        store.Add(new Statement(container, RDF + "_1", (Literal)"One"));

        // use the rdfs:member property to match for any rdf:_### predicates.
        Entity rdfs_member = (Entity)(RDFS + "member");

        using (RdfWriter writer = new N3Writer(Console.Out)) {
            writer.Namespaces.AddNamespace(RDF, "rdf");
            store.Select(new Statement(container, rdfs_member, null), writer);
        }

        foreach (Resource r in store.SelectObjects(container, rdfs_member))
        {
            Console.WriteLine(r);
        }
    }
Пример #8
0
 public static void query(SelectableSource source, Statement filter)
 {
     using (RdfWriter writer = new N3Writer(System.Console.Out))
         source.Select(filter, writer);
 }
Пример #9
0
    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);
    }
Пример #10
0
 public void Describe(SelectableSource source, TextWriter output)
 {
     using (RdfWriter w = new N3Writer(output))
         Describe(source, w);
 }
Пример #11
0
 public void Construct(SelectableSource source, TextWriter output)
 {
     using (RdfWriter w = new N3Writer(output))
         Construct(source, w);
 }
Пример #12
0
    public static void Main()
    {
        System.Net.ServicePointManager.Expect100Continue = false;         // don't send HTTP Expect: headers which confuse some servers

        string endpoint = "http://www.rdfabout.com/sparql";

        string ex1 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
                     + "SELECT ?name \n"
                     + "WHERE { [] foaf:name ?name . }\n"
                     + "LIMIT 10 \n";

        string ex2 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
                     + "ASK \n"
                     + "WHERE { [] foaf:name ?name . }\n";

        string ex3 = "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
                     + "CONSTRUCT { ?person foaf:name2 ?name } \n"
                     + "WHERE { ?person foaf:name ?name . }\n"
                     + "LIMIT 10 \n";

        SparqlHttpSource source = new SparqlHttpSource(endpoint);

        Console.WriteLine("RunSparqlQuery(ex1, Console.Out):");
        source.RunSparqlQuery(ex1, Console.Out);
        Console.WriteLine();

        Console.WriteLine("RunSparqlQuery(ex1, SparqlXmlQuerySink):");
        source.RunSparqlQuery(ex1, new SparqlXmlQuerySink(Console.Out));
        Console.WriteLine();
        Console.WriteLine();

        Console.WriteLine("RunSparqlQuery(ex2, bool):");
        bool result;

        source.RunSparqlQuery(ex2, out result);
        Console.WriteLine(result);
        Console.WriteLine();

        Console.WriteLine("RunSparqlQuery(ex3, N3Writer):");
        using (N3Writer writer = new N3Writer(Console.Out))
            source.RunSparqlQuery(ex3, writer);
        Console.WriteLine();

        Console.WriteLine("Select(subject,__,__)");
        using (N3Writer writer = new N3Writer(Console.Out))
            source.Select(new Statement("http://www.rdfabout.com/rdf/usgov/congress/people/M000303", null, null), writer);
        Console.WriteLine();

        Console.WriteLine("Query(...) A");
        Variable     a  = new Variable("a");
        QueryOptions qo = new QueryOptions();

        qo.Limit = 10;
        source.Query(new Statement[] {
            new Statement(a, "http://xmlns.com/foaf/0.1/name", (Literal)"John McCain"),
            new Statement(a, new Variable("b"), new Variable("c")),
        }, qo, new SparqlXmlQuerySink(Console.Out));
        Console.WriteLine();
        Console.WriteLine();

        Console.WriteLine("Query(...) B");
        QueryResultBuffer qb = new QueryResultBuffer();

        source.Query(new Statement[] {
            new Statement(a, "http://xmlns.com/foaf/0.1/name", (Literal)"John McCain"),
            new Statement(a, new Variable("b"), new Variable("c")),
        }, qo, qb);
        foreach (VariableBindings b in qb)
        {
            Console.WriteLine("a => " + b["a"]);
            Console.WriteLine("b => " + b["b"]);
            Console.WriteLine();
        }
        Console.WriteLine();
    }