SemWeb Play

RDF is my preferred way of tracking my web usage, browsing habits, etc. About a year ago, I wrote an RDF database with a browser plugin and have been tracking my browsing this way ever since. This weekend, I finally decided to rewrite the database part from scratch, and gave it a better API. I am fairly happy with the result. Now I can do code like the following examples:


// traversing the graph
Context c = Context.Open();
Resource r = c.Resource(resourceUri);
Property p = r.Property(propertyUri);
Property[] pa = r.Properties();
p.Value = “foo”; // assign resource, string, or xml literals
c[resourceUri][predicateUri].Value = obj; // indexer support


// querying the graph
Resource[] ra = c.Resources(predicateUri, value); // including fulltext search


// support for built-in RDF stuff
if (p.Value is RdfCollection)
(RdfCollection)(p.Value).Append(”foo”);
r.RdfType = rdfsSchemaUri;


I also whipped up a treeview RDFDB browser in winforms to prove that the API is easy to use, and wrote code to import all of my bookmarks. (Less than ten of the lines in the code snippet below are concerned with talking to the RDFDB; the rest are just parsing out the bookmark, downloading, etc.):


static void Main(string[] args)
{
string baseDir = “c:\\documents and settings\\joshuaa\\favorites”;
string connectionString = “Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=favorites;Data Source=(local)”;
Guid contextId = new Guid(”0c1d3732-bdf9-42e0-bdd3-d72a265202a4″);

Context c = Context.Open(connectionString, contextId);
if (c == null) c = Context.Create(connectionString, contextId);


foreach (string file in Directory.GetFiles(baseDir, “*.url”))
{
DateTime createDate = File.GetCreationTime(file);


StreamReader sin = File.OpenText(file);
string line = sin.ReadLine();
string section = “”;
string url = “”;
while (line != null)
{
line = line.Trim();
if (line.StartsWith(”[”) && line.EndsWith(”]”)) section = line;
else if (section == “[InternetShortcut]”)
{
if (line.StartsWith(”URL=”))
{
url = line.Substring(4,line.Length - 4);
}
}
line = sin.ReadLine();
}
if (url != “”)
{
string dcTitle = “
http://purl.org/dc/elements/1.1/title“;
string dcCreator = “
http://purl.org/dc/elements/1.1/creator“;


Resource r = c[url];


r.RdfType = “http://purl.org/webstuff/bookmark“;


string title = file.Substring(0, file.Length - 4);
int spos = title.LastIndexOf(”\\”);
if (spos < title.Length && spos > -1)
{
title = title.Substring(spos + 1, title.Length - (spos + 1));
}
r[dcTitle].Value = title;

string docBody = “”;
XmlDocument doc = null;
try
{
doc = new XmlDocument();
WebRequest req = WebRequest.Create(r.Uri);
StreamReader sr = new StreamReader(req.GetResponse().GetResponseStream());
SgmlReader reader = new SgmlReader();
reader.InputStream = sr;
docBody = sr.ReadToEnd();
doc.LoadXml(docBody);
}
catch (Exception e)
{
//Console.WriteLine(”Unable to load {0}: {1}”, r.Uri.AbsoluteUri, e.Message);
}
if (doc != null)
{
try
{
r[”
http://purl.org/webstuff/bookmark#body”].Value = doc;
}
catch (Exception ie)
{
}
r[”
http://purl.org.webstuff/bookmark#text”].Value = doc.InnerText;
ArrayList links = new ArrayList();
XmlNodeList nodes = doc.SelectNodes(”
//a/@href“);
foreach (XmlNode node in nodes)
{
Uri u = new Uri(r.Uri, node.InnerText);
links.Add(u);
}
r[”
http://purl.org.webstuff/bookmark#links”].Value = r.Context.CreateCollection(links);
}
else
{
if (docBody != “”)
r[”
http://purl.org.webstuff/bookmark#text”].Value = docBody;
}
}
}


}


WordPress database error: [Can't open file: 'wp_comments.MYI'. (errno: 145)]
SELECT * FROM wp_comments WHERE comment_post_ID = '391' AND comment_approved = '1' ORDER BY comment_date

Leave a Reply