5 namespace Beagle
.Util
{
6 public class MetadataStore
: MemoryStore
8 public static NamespaceManager Namespaces
;
9 private static MetadataStore descriptions
;
11 static MetadataStore ()
13 Namespaces
= new NamespaceManager ();
15 Namespaces
.AddNamespace ("http://ns.adobe.com/photoshop/1.0/", "photoshop");
16 Namespaces
.AddNamespace ("http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/", "Iptc4xmpCore");
17 Namespaces
.AddNamespace ("http://purl.org/dc/elements/1.1/", "dc");
18 Namespaces
.AddNamespace ("http://ns.adobe.com/xap/1.0/", "xmp");
19 Namespaces
.AddNamespace ("http://ns.adobe.com/xmp/Identifier/qual/1.0", "xmpidq");
20 Namespaces
.AddNamespace ("http://ns.adobe.com/xap/1.0/rights/", "xmpRights");
21 Namespaces
.AddNamespace ("http://ns.adobe.com/xap/1.0/bj/", "xmpBJ");
22 Namespaces
.AddNamespace ("http://ns.adobe.com/xap/1.0/mm/", "xmpMM");
23 Namespaces
.AddNamespace ("http://ns.adobe.com/exif/1.0/", "exif");
24 Namespaces
.AddNamespace ("http://ns.adobe.com/tiff/1.0/", "tiff");
25 Namespaces
.AddNamespace ("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
26 Namespaces
.AddNamespace ("http://www.w3.org/2000/01/rdf-schema#", "rdfs");
29 public static MetadataStore Descriptions
{
31 if (descriptions
== null) {
32 descriptions
= new MetadataStore ();
33 System
.IO
.Stream stream
= System
.Reflection
.Assembly
.GetCallingAssembly ().GetManifestResourceStream ("dces.rdf");
35 descriptions
.Import (new RdfXmlReader (stream
));
37 System
.Console
.WriteLine ("Can't find resource");
47 foreach (SemWeb
.Statement stmt
in this) {
48 System
.Console
.WriteLine(stmt
);
52 XPathSemWebNavigator navi = new XPathSemWebNavigator (this, Namespaces);
54 navi.MoveToFirstChild ();
55 navi.MoveToFirstChild ();
59 /* Use the statement writer to filter the messages */
61 foreach (string nspace in Namespaces.GetNamespaces ()) {
62 this.Select (new StatementWriter (nspace));
67 public static void AddLiteral (StatementSink sink
, string predicate
, string type
, Literal
value)
69 Entity empty
= new Entity (null);
70 Statement top
= new Statement ("", (Entity
)MetadataStore
.Namespaces
.Resolve (predicate
), empty
);
71 Statement desc
= new Statement (empty
,
72 (Entity
)MetadataStore
.Namespaces
.Resolve ("rdf:type"),
73 (Entity
)MetadataStore
.Namespaces
.Resolve (type
));
75 Statement literal
= new Statement (empty
,
76 (Entity
)MetadataStore
.Namespaces
.Resolve ("rdf:li"),
82 public static void AddLiteral (StatementSink sink
, string predicate
, string value)
84 Statement stmt
= new Statement ((Entity
)"",
85 (Entity
)MetadataStore
.Namespaces
.Resolve (predicate
),
90 public static void Add (StatementSink sink
, string predicate
, string type
, string [] values
)
92 Add (sink
, new Entity (""), predicate
, type
, values
);
95 public static void Add (StatementSink sink
, Entity subject
, string predicate
, string type
, string [] values
)
98 System
.Console
.WriteLine ("{0} has no values; skipping", predicate
);
102 Entity empty
= new Entity (null);
103 Statement top
= new Statement (subject
, (Entity
)MetadataStore
.Namespaces
.Resolve (predicate
), empty
);
104 Statement desc
= new Statement (empty
,
105 (Entity
)MetadataStore
.Namespaces
.Resolve ("rdf:type"),
106 (Entity
)MetadataStore
.Namespaces
.Resolve (type
));
108 foreach (string value in values
) {
109 Statement literal
= new Statement (empty
,
110 (Entity
)MetadataStore
.Namespaces
.Resolve ("rdf:li"),
111 new Literal (value, null, null));
117 private class StatementWriter
: StatementSink
120 public StatementWriter (string name
)
125 public bool Add (Statement stmt
)
127 string predicate
= stmt
.Predicate
.ToString ();
129 if (predicate
.StartsWith (name
))
130 System
.Console
.WriteLine ("----------- {0}", stmt
);
136 private class SelectFirst
: StatementSink
138 public Statement Statement
;
140 public bool Add (Statement stmt
)
142 this.Statement
= stmt
;
147 public void DumpNode (XPathSemWebNavigator navi
, int depth
)
150 System
.Console
.WriteLine ("node [{0}] {1} {2}", depth
, navi
.Name
, navi
.Value
);
151 } while (navi
.MoveToNext ());