public void Import(StatementSource source) { bool newDistinct = checkForDuplicates || ((StatementCount == 0) && source.Distinct); source.Select(this); distinct = newDistinct; }
/// <summary> /// Takes the contents of a SemWeb Statement Source and inputs it into a dotNetRDF Graph /// </summary> /// <param name="source">Statement Source</param> /// <param name="g">Graph</param> public static void FromSemWeb(StatementSource source, IGraph g) { SemWebMapping mapping = new SemWebMapping(g); Triple t; MemoryStore mem = new MemoryStore(); source.Select(mem); foreach (Statement stmt in mem) { t = FromSemWeb(stmt, mapping); g.Assert(t); } }
public void LoadSchema(StatementSource source) { if (source is SelectableSource) { ((SelectableSource)source).Select( new SelectFilter( null, new Entity[] { subClassOf, subPropertyOf, domain, range }, null, null), Schema); } else { source.Select(Schema); } }
public bool Import(Photo photo, string path, string orig_path) { XmpFile xmp; string source_sidecar = String.Format("{0}{1}{2}.xmp", Path.GetDirectoryName(orig_path), Path.DirectorySeparatorChar, Path.GetFileName(orig_path)); string dest_sidecar = String.Format("{0}{1}{2}.xmp", Path.GetDirectoryName(path), Path.DirectorySeparatorChar, Path.GetFileName(path)); if (File.Exists(source_sidecar)) { xmp = new XmpFile(File.OpenRead(source_sidecar)); } else if (File.Exists(dest_sidecar)) { xmp = new XmpFile(File.OpenRead(dest_sidecar)); } else { xmp = new XmpFile(); } using (ImageFile img = ImageFile.Create(path)) { StatementSource source = img as StatementSource; if (source != null) { try { source.Select(xmp); } catch { } } } ProcessStore(xmp.Store, photo); #if enable_debug xmp.Save(Console.OpenStandardOutput()); #endif return(true); }
public void Import(StatementSource source) { if (source == null) { throw new ArgumentNullException(); } Init(); connection.BeginTransaction(); Importer imp = new Importer(this); try { source.Select(imp); } finally { imp.RunAddBuffer(); connection.EndTransaction(); } }
public void Import(StatementSource source) { if (source == null) throw new ArgumentNullException(); if (isImporting) throw new InvalidOperationException("Store is already importing."); Init(); RunAddBuffer(); cachedNextId = -1; NextId(); // get this before starting transaction because it relies on indexes which may be disabled addStatementBuffer = new StatementList(); BeginTransaction(); try { isImporting = true; source.Select(this); } finally { RunAddBuffer(); EndTransaction(); addStatementBuffer = null; isImporting = false; entityCache.Clear(); literalCache.Clear(); } }
public static void Build(StatementSource graph, out bool[,] connectivity, Hashtable indexes) { connectivity = new bool[indexes.Count, indexes.Count]; graph.Select(new Sink(connectivity, indexes)); }
void WriterRunner() { sourceData.Select(this); finished = true; hasData.Set(); // anything written but not flagged }
public virtual void Write(StatementSource source) { source.Select(this); }
private void Update() { Gtk.HTMLStream stream = this.Begin(null, "text/html; charset=utf-8", Gtk.HTMLBeginFlags.Scroll); string bg = Color(this.Style.Background(Gtk.StateType.Active)); string fg = Color(this.Style.Foreground(Gtk.StateType.Active)); string ig = Color(this.Style.Base(Gtk.StateType.Active)); stream.Write("<table width=100% cellpadding=5 cellspacing=0>"); bool empty = true; bool missing = false; System.Exception error = null; if (exif_info != null) { foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); if (entries.Length > 0) { empty = false; break; } } if (exif_info.Data.Length > 0) { stream.Write(String.Format("<tr><td colspan=2 align=\"center\" bgcolor=\"{0}\">" + "<img center src=\"exif:thumbnail\"></td></tr>", ig)); } int i = 0; foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); i++; if (entries.Length < 1) { continue; } stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Exif.ExifUtil.GetIfdNameExtended((Exif.Ifd)i - 1) + "</th><tr>"); foreach (Exif.ExifEntry entry in entries) { stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); if (entry.Title != null) { stream.Write(entry.Title); } else { stream.Write("<Unknown Tag ID=" + entry.Tag.ToString() + ">"); } stream.Write("</font></small></td><td>"); string s = entry.Value; if (s != null && s != String.Empty) { stream.Write(s); } stream.Write("</td><tr>"); } } } if (photo != null) { MetadataStore store = new MetadataStore(); try { using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) { if (img is SemWeb.StatementSource) { StatementSource source = (StatementSource)img; source.Select(store); } } } catch (System.IO.FileNotFoundException) { missing = true; } catch (System.Exception e) { // Sometimes we don't get the right exception, check for the file if (!System.IO.File.Exists(photo.DefaultVersionUri.LocalPath)) { missing = true; } else { // if the file is there but we still got an exception display it. error = e; } } if (store.StatementCount > 0) { #if false using (System.IO.Stream xmpstream = System.IO.File.OpenWrite("tmp.xmp")) { xmpstream.Length = 0; FSpot.Xmp.XmpFile file; file = new FSpot.Xmp.XmpFile(); store.Select(file); file.Save(xmpstream); } #endif empty = false; stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Extended Metadata") + "</th></tr>"); foreach (Statement stmt in store) { // Skip anonymous subjects because they are // probably part of a collection if (stmt.Subject.Uri == null && store.SelectSubjects(null, stmt.Subject).Length > 0) { continue; } string title; string value; Description.GetDescription(store, stmt, out title, out value); stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); stream.Write(title); stream.Write("</font></small></td><td width=100%>"); if (value != null) { value = Escape(value); } else { MemoryStore substore = store.Select(new Statement((Entity)stmt.Object, null, null, null)).Load(); WriteCollection(substore, stream); } if (value != null && value != String.Empty) { stream.Write(value); } stream.Write("</td></tr>"); } } if (Core.Database != null && photo is Photo) { stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Exported Locations") + "</th></tr>"); Photo p = photo as Photo; foreach (ExportItem export in Core.Database.Exports.GetByImageId(p.Id, p.DefaultVersionId)) { string url = GetExportUrl(export); string label = GetExportLabel(export); if (url == null || label == null) { continue; } stream.Write("<tr colspan=2><td width=100%>"); stream.Write(String.Format("<a href=\"{0}\">{1}</a>", url, label)); stream.Write("</font></small></td></tr>"); } } } if (empty) { string msg; if (photo == null) { // FIXME we should pass the full selection to the info display and let it // handle multiple items however it wants. msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No active photo")); } else if (missing) { string text = String.Format(Catalog.GetString("The photo \"{0}\" does not exist"), photo.DefaultVersionUri); msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, text); } else { msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No metadata available")); if (error != null) { String.Format("<pre>{0}</pre>", error); } } stream.Write(msg); } stream.Write("</table>"); End(stream, Gtk.HTMLStreamStatus.Ok); }
/// <summary> /// Adds the contents of the given Statement Source to the Store /// </summary> /// <param name="source">Statement Source</param> public void Import(StatementSource source) { source.Select(this); }
private bool Update() { TreeIter iter; ListStore model; string name; bool empty = true; bool missing = false; System.Exception error = null; up_to_date = true; int i = 0; int index_of_expander = 0; // Write Exif-Data if (exif_info != null) { foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); i++; if (entries.Length < 1) { continue; } empty = false; name = Exif.ExifUtil.GetIfdNameExtended((Exif.Ifd)i - 1); if (index_of_expander >= exif_vbox.Children.Length) { model = AddExpander(name, index_of_expander); } else { Expander expander = (Expander)exif_vbox.Children[index_of_expander]; if (expander.Label == name) { model = (ListStore)((TreeView)expander.Child).Model; } else { model = AddExpander(name, index_of_expander); } } model.GetIterFirst(out iter); foreach (Exif.ExifEntry entry in entries) { string s; if (entry.Title != null) { s = String.Format("{0}\n\t<small>{1}</small>", entry.Title, entry.Value); } else { s = String.Format("Unknown Tag ID={0}\n\t<small>{1}</small>", entry.Tag.ToString(), entry.Value); } if (model.IterIsValid(iter)) { model.SetValue(iter, 0, s); model.IterNext(ref iter); } else { model.AppendValues(s); } } // remove rows, that are not used while (model.IterIsValid(iter)) { model.Remove(ref iter); } index_of_expander++; } } // Write Extended Metadata if (photo != null) { MetadataStore store = new MetadataStore(); try { using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) { if (img is SemWeb.StatementSource) { StatementSource source = (StatementSource)img; source.Select(store); } } } catch (System.IO.FileNotFoundException) { missing = true; } catch (System.Exception e) { // Sometimes we don't get the right exception, check for the file if (!System.IO.File.Exists(photo.DefaultVersionUri.LocalPath)) { missing = true; } else { // if the file is there but we still got an exception display it. error = e; } } model = extended_metadata; model.GetIterFirst(out iter); if (store.StatementCount > 0) { empty = false; foreach (Statement stmt in store) { // Skip anonymous subjects because they are // probably part of a collection if (stmt.Subject.Uri == null && store.SelectSubjects(null, stmt.Subject).Length > 0) { continue; } string title; string value; string s; Description.GetDescription(store, stmt, out title, out value); if (value == null) { MemoryStore substore = store.Select(new Statement((Entity)stmt.Object, null, null, null)).Load(); StringBuilder collection = new StringBuilder(); collection.Append(title); WriteCollection(substore, collection); if (model.IterIsValid(iter)) { model.SetValue(iter, 0, collection.ToString()); model.IterNext(ref iter); } else { model.AppendValues(collection.ToString()); } } else { s = String.Format("{0}\n\t<small>{1}</small>", title, value); if (model.IterIsValid(iter)) { model.SetValue(iter, 0, s); model.IterNext(ref iter); } else { model.AppendValues(s); } } } } else { // clear Extended Metadata String s = String.Format("<small>{0}</small>", Catalog.GetString("No Extended Metadata Available")); if (model.IterIsValid(iter)) { model.SetValue(iter, 0, s); model.IterNext(ref iter); } else { model.AppendValues(s); } } // remove rows, that are not used while (model.IterIsValid(iter)) { model.Remove(ref iter); } } if (empty) { string msg; if (photo == null) { msg = Catalog.GetString("No active photo"); } else if (missing) { msg = String.Format(Catalog.GetString("The photo \"{0}\" does not exist"), photo.DefaultVersionUri); } else { msg = Catalog.GetString("No metadata available"); if (error != null) { msg = String.Format("<i>{0}</i>", error); } } exif_message.Markup = "<span weight=\"bold\">" + msg + "</span>"; if (display == State.exif) { // Child is a Viewport, (AddWithViewport in ctor) ((Viewport)Child).Remove(main_vbox); ((Viewport)Child).Add(exif_message); display = State.message; exif_message.Show(); } } else { // remove Expanders, that are not used while (index_of_expander < exif_vbox.Children.Length) { exif_vbox.Remove(exif_vbox.Children[index_of_expander]); } if (display == State.message) { // Child is a Viewport, (AddWithViewport in ctor) ((Viewport)Child).Remove(exif_message); ((Viewport)Child).Add(main_vbox); display = State.exif; main_vbox.ShowAll(); } } return(false); }
public override void Select(StatementSink storage) { foreach (string infile in files) { if (!quiet) { Console.Error.Write(infile + " "); } try { DateTime start = DateTime.Now; StatementFilterSink filter = new StatementFilterSink(storage); if (format == null || format != "spec") { string fmt = format; if (fmt == null) { // Use file extension to override default parser type. if (infile.StartsWith("http:")) { fmt = "url"; } else if (infile.EndsWith(".nt") || infile.EndsWith(".n3") || infile.EndsWith(".ttl")) { fmt = "n3"; } else if (infile.EndsWith(".xml") || infile.EndsWith(".rdf")) { fmt = "xml"; } else { Console.Error.WriteLine("Unrecognized file extension in " + infile + ": Trying RDF/XML."); fmt = "xml"; } } using (RdfReader parser = RdfReader.Create(fmt, infile)) { if (baseuri != null) { parser.BaseUri = baseuri; } if (meta != null) { parser.Meta = meta; } if (storage is RdfWriter) { ((RdfWriter)storage).Namespaces.AddFrom(parser.Namespaces); } try { parser.Select(filter); } finally { if (parser.Warnings.Count > 0) { Console.Error.WriteLine("\nThere were warnings parsing this file:"); } foreach (string warning in parser.Warnings) { Console.Error.WriteLine("> " + warning); } } } } else { StatementSource src = Store.Create(infile); src.Select(filter); if (src is IDisposable) { ((IDisposable)src).Dispose(); } } totalStatementsRead += filter.StatementCount; TimeSpan time = DateTime.Now - start; if (!quiet) { Console.Error.WriteLine(" {0}m{1}s, {2} statements, {3} st/sec", (int)time.TotalMinutes, (int)time.Seconds, filter.StatementCount, time.TotalSeconds == 0 ? "?" : ((int)(filter.StatementCount / time.TotalSeconds)).ToString()); } } catch (ParserException e) { Console.Error.WriteLine(" " + e.Message); } catch (Exception e) { Console.Error.WriteLine("\n" + e + "\n"); } } }
/// <summary> /// Imports the contents of a Source into the underlying Graph /// </summary> /// <param name="source"></param> public void Import(StatementSource source) { source.Select(this); }
public void Import(StatementSource source) { if (source == null) throw new ArgumentNullException(); Init(); connection.BeginTransaction(); Importer imp = new Importer(this); try { source.Select(imp); } finally { imp.RunAddBuffer(); connection.EndTransaction(); } }