2 using System
.Collections
;
6 public class ParserException
: ApplicationException
{
7 public ParserException (string message
) : base (message
) {}
8 public ParserException (string message
, Exception cause
) : base (message
, cause
) {}
11 public abstract class RdfReader
: StatementSource
, IDisposable
{
12 Entity meta
= Statement
.DefaultMeta
;
13 string baseuri
= null;
14 ArrayList warnings
= new ArrayList();
15 ArrayList variables
= new ArrayList();
16 bool reuseentities
= false;
17 bool dupcheck
= false;
28 public string BaseUri
{
37 public bool ReuseEntities
{
42 reuseentities
= value;
46 public bool DuplicateCheck
{
55 public ICollection Variables { get { return ArrayList.ReadOnly(variables); }
}
57 protected void AddVariable(Entity variable
) {
58 variables
.Add(variable
);
61 public abstract void Select(StatementSink sink
);
63 public virtual void Dispose() {
66 public static RdfReader
Create(string type
, string source
) {
70 return new RdfXmlReader(source
);
73 return new N3Reader(source
);
75 throw new ArgumentException("Unknown parser type: " + type
);
79 internal static TextReader
GetReader(string file
) {
80 if (file
== "-") return Console
.In
;
81 return new StreamReader(file
);
84 protected void OnWarning(string message
) {
85 warnings
.Add(message
);
88 internal string GetAbsoluteUri(string baseuri
, string uri
) {
89 if (baseuri
== null) return uri
;
90 if (uri
.IndexOf(':') != -1) return uri
;
92 UriBuilder b
= new UriBuilder(baseuri
);
93 b
.Fragment
= null; // per W3 RDF/XML test suite
94 return new Uri(b
.Uri
, uri
, true).ToString();
95 } catch (UriFormatException e
) {
100 internal StatementSink
GetDupCheckSink(StatementSink sink
) {
101 if (!dupcheck
) return sink
;
102 if (!(sink
is Store
)) return sink
;
103 return new DupCheckSink((Store
)sink
);
106 private class DupCheckSink
: StatementSink
{
108 public DupCheckSink(Store store
) { this.store = store; }
109 public bool Add(Statement s
) {
110 if (store
.Contains(s
)) return true;
117 internal class MultiRdfReader
: RdfReader
{
118 private ArrayList parsers
= new ArrayList();
120 public ArrayList Parsers { get { return parsers; }
}
122 public override void Select(StatementSink storage
) {
123 foreach (RdfReader p
in Parsers
)