Skip to content

When it comes to Semantic Triples, LISP is your friend

July 6, 2011

I was reading this book and I got to the bit on Variable Binding. It just occurred to me that as I read, the language used here is Python.

I got to this bit
\textsf{("San\_Francisco\_California", "inside", "California")}

Well what is that? It is a triple and it is a is list! Immediately I recalled an example found in David Touretzky’s book.

Actually it is in an exercise found in Section 7.29. Here is where LISP is so natural once I believe we get into its mind set.

In LISP you can form your triples as a list and load them into a symbol using \texttt{setf}. For example for this case we can do something like \texttt {(setf knowledgebase '((San-Francisco-California inside California)}
\texttt{(San-Francisco-California mayor Gavin-Newsome)))}

Then using Touretzky’s \texttt{match-element, match-triple } and \texttt{fetch} functions we can issue the following function execution in LISP that matches what the Semantic Web book is trying to do. Hence we can say
\texttt{(fetch '(? inside California))}.

To the LISP expert (which I am not), this insight is no brainer since they are accustomed to this sort of thing as second nature.

However, my point is that this is a far far elegant solution than what the Semantic Web book is trying to do using Python, p40-p42. In COMMON LISP, you won’t have to spend that much code trying to implement a query language. Those functions in Touretzky consumed only 11 LISP lines.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: