File: loadfromweb.cs

package info (click to toggle)
semweb 1.05%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 3,988 kB
  • ctags: 2,832
  • sloc: cs: 14,483; makefile: 180; sh: 107; perl: 20; ansic: 7
file content (40 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// This example loads an RDF file from the web.
// It uses RdfReader.LoadFromUri, passing a URI,
// which downloads the corresponding URI and looks
// at its MIME type to determine what kind of
// RdfReader should be used to parse the file. A
// default URI (http://www.mozilla.org/news.rdf)
// can be used, or pass a URI on the command line
// to use a different data source.

using System;
using SemWeb;

public class LoadFromWeb {
	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());
	}
	
	class StatementPrinter : StatementSink {
		public bool Add(Statement assertion) {
			Console.WriteLine(assertion.ToString());
			return true;
		}
	}
}