File: containers.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 (35 lines) | stat: -rw-r--r-- 1,228 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
// This example deals with RDF containers.  You can use the rdfs:member
// property to match any rdf:_### (i.e. rdf:li) property.  Or,
// use SelectObjects on the Store, which will return the items
// in sorted order.

using System;
using SemWeb;

public class Containers {

	const string RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
	const string RDFS = "http://www.w3.org/2000/01/rdf-schema#";
	
	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);
	}
}