2009-08-25T10:07:04
Dave Pawson.
link
Home
rdf
For years now I've relied on cwm from Sean Palmer and TimBL. It's showing its age! I'm currently on FC11 which (as of today) runs Python 2.6. Now, when I run cwm I'm getting the message that the md5sum import is deprecated, I should be using hashlib. OK, I changed all occurrences of that import, and the warning has gone away. Since Sean has declared his loss of interest in semweb, I'm not expecting him to fix it and I guess Tims far too busy. So I started looking for an alternative.
Jena came to
mind so I installed it. Nothing obvious in the
documentation but some googling found the class
jena.rdfcopy which seems to do the trick. The
usual classpath hacks and I came up with a script to do
either way copying depending on the input file
extension. Requires zsh
shell, i.e. it's Linux based. That's for the
nameonly function. Otherwise OK in bash
Have fun
A response notes: Jena lists possibly useful command line wrappers... but fails to say what each might do? Come on Jena, you can do better than this!
#!/bin/zsh
cp=/apps/jena26/lib/slf4j-api-1.5.6.jar:/apps/jena26/lib/xercesImpl.jar:/apps/jena26/lib/iri.jar:\
/apps/jena26/lib/slf4j-log4j12-1.5.6.jar:/apps/jena26/lib/lucene-core-2.3.1.jar:\
/apps/jena26/lib/log4j-1.2.12.jar:/apps/jena26/lib/icu4j_3_4.jar:/apps/jena26/lib/jena.jar
#Name only, also remove paths. p296
nameonly() {
echo ${${1##*/}%.*}
}
#return the extension, less the name
function extx()
{
local bn=`basename $1`
local nm=`nameonly $1`
local ext=${bn##$nm\.}
echo "$ext"
}
if [ $# -lt 1 ]
then
echo "Usage. $0 inputFileName.n3|rdf"
echo "\tConverts from n3->rdf or rdf->n3"
echo "\tdepending on extension of input file."
exit 2
fi
if [ ! -f $1 ]
then
echo "$0, parameter must be regular file"
echo "\t$1 is not a regular file"
exit 2
fi
ext=`extx $1`
name=`nameonly $1`
echo "\t Filename $name, extension $ext"
if [ $ext = "n3" ]
then
java -cp $cp jena.rdfcopy ${name}.n3 N3 RDF/XML >${name}.rdf
echo "See file ${name}.rdf"
exit 0
fi
if [ $ext = "rdf" ]
then
java -cp $cp jena.rdfcopy ${name}.rdf RDF/XML N3 >${name}.n3
echo "See file ${name}.n3"
exit 0
fi
echo "Unable to process $1"
echo "\t Filename $name, extension $ext"
# fyi
# n2 to rdf
#java -cp $cp jena.rdfcopy test.n3 N3 RDF/XML
# rdf to n3
#java -cp $cp jena.rdfcopy test.rdf RDF/XML N3
When I asked, via twitter, where the other command line apps were for Jena, @uche pointed me to FuXi. I baulked a little at the name... but tried to install it anyway.
The Python easy_install (great app) gave me
FuXi-1.0-rc.dev-r277.macosx-10.5-i386.tar.gz which said
to me it was built for a Mac? I then hunted down FuXi-1.0_rc.dev_r277-py2.5.egg the .egg file, which installed easily... yet gave me
warning FuXi/Rete/Network.py:16: DeprecationWarning: the sets module is deprecated
That warning! I think FuXi was developed under Python 2.5? Still trying to resolve that!Anyway, warning aside, Fuxi does the job too.
Takes a bit of working out, but
$Fuxi --output=pretty-xml --input-format=n3 --closure $1
I.e. It can do the conversion... just need to RTFM a little. Call
up Fuxi (just don't say it out loud, you'll get strange
looks!) with no parameters for a full help screen.
Enjoy.
Keywords: rdf
Comments (View)Return to main index