I actively use the Subversion version management system for all my projects. I use it while writing papers (in LaTeX), e.g. to merge different versions (of co-authors) with a main file, I use it for my Java projects, but I use it for my OWL ontologies as well.
A couple of weeks ago I found out that the TortoiseSVN Subversion client GUI for Windows is able to use Microsoft Word for performing diffs and merges on Word documents. While composing today’s post on the OWL Tools of Denny Vrandecic, something went ‘click’: why not use his diff and merge algorithms for resolving conflincts between different versions of an ontology stored using Subversion?
The SVN book says the following:
Subversion uses its internal diff engine, which produces unified diff format, by default. If you want diff output in a different format, specify an external diff program using --diff-cmd and pass any flags you’d like to it using the --extensions switch. For example, to see local differences in file foo.c in context output format while ignoring whitespace changes, you might run svn diff --diff-cmd /usr/bin/diff --extensions '-bc' foo.c.
Rewriting this to OWL Tool format results in something like:
svn diff --diff-cmd '../owltools/owl diff' lricore.owl
However, subversion calls the diff program as if it were GNU diff, and Denny’s diff does not understand the standard GNU diff commandline options. We therefore need to write a diff wrapper (see the manual):
#!/bin/sh
# Configure your favorite OWL Tools diff program here.
# That's Denny's! (his 'owl' script assumes that kaon2.jar and
# owltools.jar are in the path)
DIFF="owl diff "
# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}
# Call the diff command.
$DIFF $LEFT $RIGHT
# Return an errorcode of 0 if no differences were detected,
# 1 if some were.
# Any other errorcode will be treated as fatal.
Caveat: So far so good… were it not for the last two lines. The OWL tools diff always returns 1: if differences are found, it generates an owl file containing the differences, and if no differences are found, it generates an owl file with headers, but no triples.
Ah well… this works fine for me. I’ll use the standard diff for checking whether anything has changed, and the OWL Tools diff to see what has changed. If the above script is saved as ‘owldiff’, we can now use it to find the differences between my working copy of LRI-Core and the one stored in my subversion repository:
svn diff --diff-cmd owldiff lricore.owl
Remember this is just as powerful as svn diff itself: we can also use it to compare different revisions. And when a difference is found, we can use Denny’s merge, or the Prompt Tab of Protege-OWL to merge the differences into an ontology of our choice! (you can tell I’m happy now)
You can download the script (and a batch file for Win32) here: owldiff.zip