private static object Create(string spec, bool output) { string[] multispecs = spec.Split('\n', '|'); if (multispecs.Length > 1) { SemWeb.Stores.MultiStore multistore = new SemWeb.Stores.MultiStore(); foreach (string mspec in multispecs) { object mstore = Create(mspec.Trim(), output); if (mstore is SelectableSource) { multistore.Add((SelectableSource)mstore); } else if (mstore is StatementSource) { MemoryStore m = new MemoryStore((StatementSource)mstore); multistore.Add(m); } } return multistore; } string type = spec; int c = spec.IndexOf(':'); if (c != -1) { type = spec.Substring(0, c); spec = spec.Substring(c+1); } else { spec = ""; } Type ttype; switch (type) { case "mem": return new MemoryStore(); case "xml": if (spec == "") throw new ArgumentException("Use: xml:filename"); if (output) { return new RdfXmlWriter(spec); } else { return new RdfXmlReader(spec); } case "n3": case "ntriples": case "nt": case "turtle": if (spec == "") throw new ArgumentException("Use: format:filename"); if (output) { N3Writer ret = new N3Writer(spec); // turtle is default format switch (type) { case "nt": case "ntriples": ret.Format = N3Writer.Formats.NTriples; break; } return ret; } else { return new N3Reader(spec); } /*case "file": if (spec == "") throw new ArgumentException("Use: format:filename"); if (output) throw new ArgumentException("The FileStore does not support writing."); return new SemWeb.Stores.FileStore(spec);*/ case "sqlite": case "mysql": case "postgresql": if (spec == "") throw new ArgumentException("Use: sqlite|mysql|postgresql:table:connection-string"); c = spec.IndexOf(':'); if (c == -1) throw new ArgumentException("Invalid format for SQL spec parameter (table:constring)."); string table = spec.Substring(0, c); spec = spec.Substring(c+1); string classtype = null; if (type == "sqlite") { classtype = "SemWeb.Stores.SqliteStore, SemWeb.SqliteStore"; spec = spec.Replace(";", ","); } else if (type == "mysql") { classtype = "SemWeb.Stores.MySQLStore, SemWeb.MySQLStore"; } else if (type == "postgresql") { classtype = "SemWeb.Stores.PostgreSQLStore, SemWeb.PostgreSQLStore"; } ttype = Type.GetType(classtype); if (ttype == null) throw new NotSupportedException("The storage type in <" + classtype + "> could not be found."); return Activator.CreateInstance(ttype, new object[] { spec, table }); /*case "bdb": return new SemWeb.Stores.BDBStore(spec);*/ case "sparql-http": return new SemWeb.Remote.SparqlHttpSource(spec); case "class": ttype = Type.GetType(spec); if (ttype == null) throw new NotSupportedException("The class <" + spec + "> could not be found."); return Activator.CreateInstance(ttype); default: throw new ArgumentException("Unknown parser type: " + type); } }
private static object Create(string spec, bool output) { string[] multispecs = spec.Split('\n', '|'); if (multispecs.Length > 1) { SemWeb.Stores.MultiStore multistore = new SemWeb.Stores.MultiStore(); foreach (string mspec in multispecs) { object mstore = Create(mspec.Trim(), output); if (mstore is SelectableSource) { multistore.Add((SelectableSource)mstore); } else if (mstore is StatementSource) { MemoryStore m = new MemoryStore((StatementSource)mstore); multistore.Add(m); } } return(multistore); } string type = spec; int c = spec.IndexOf(':'); if (c != -1) { type = spec.Substring(0, c); spec = spec.Substring(c + 1); } else { spec = ""; } Type ttype; switch (type) { case "mem": return(new MemoryStore()); case "xml": if (spec == "") { throw new ArgumentException("Use: xml:filename"); } if (output) { return(new RdfXmlWriter(spec)); } else { return(new RdfXmlReader(spec)); } case "n3": case "ntriples": case "nt": case "turtle": if (spec == "") { throw new ArgumentException("Use: format:filename"); } if (output) { N3Writer ret = new N3Writer(spec); // turtle is default format switch (type) { case "nt": case "ntriples": ret.Format = N3Writer.Formats.NTriples; break; } return(ret); } else { return(new N3Reader(spec)); } /*case "file": * if (spec == "") throw new ArgumentException("Use: format:filename"); * if (output) throw new ArgumentException("The FileStore does not support writing."); * return new SemWeb.Stores.FileStore(spec);*/ case "sqlite": case "mysql": case "postgresql": if (spec == "") { throw new ArgumentException("Use: sqlite|mysql|postgresql:table:connection-string"); } c = spec.IndexOf(':'); if (c == -1) { throw new ArgumentException("Invalid format for SQL spec parameter (table:constring)."); } string table = spec.Substring(0, c); spec = spec.Substring(c + 1); string classtype = null; if (type == "sqlite") { classtype = "SemWeb.Stores.SqliteStore, SemWeb.SqliteStore"; spec = spec.Replace(";", ","); } else if (type == "mysql") { classtype = "SemWeb.Stores.MySQLStore, SemWeb.MySQLStore"; } else if (type == "postgresql") { classtype = "SemWeb.Stores.PostgreSQLStore, SemWeb.PostgreSQLStore"; } ttype = Type.GetType(classtype); if (ttype == null) { throw new NotSupportedException("The storage type in <" + classtype + "> could not be found."); } return(Activator.CreateInstance(ttype, new object[] { spec, table })); /*case "bdb": * return new SemWeb.Stores.BDBStore(spec);*/ case "sparql-http": return(new SemWeb.Remote.SparqlHttpSource(spec)); case "class": ttype = Type.GetType(spec); if (ttype == null) { throw new NotSupportedException("The class <" + spec + "> could not be found."); } return(Activator.CreateInstance(ttype)); default: throw new ArgumentException("Unknown parser type: " + type); } }
public KnowledgeModel() { stores = new SemWeb.Stores.MultiStore(); mainstore = stores; }