Scripts


2
Jul 13

A python script to show line endings in use

I get fed up with trying to quickly check line endings in files – especially when I am working with a file format that absolutely requires DOS line endings \r\n.

#!/usr/bin/python

import sys
import os

print 'Number of files given as args: ', len(sys.argv)

padding = 20

for file in sys.argv:
    if os.path.isfile(file):
        if "\r\n" in open(file,"rb").read():
            print str(file).ljust(padding, " ")," : DOS line endings found"
            continue
        if "\n" in open(file,"rb").read():
            print  str(file).ljust(padding, " "), " : UNIX line endings found"
            continue
        if "\r" in open(file,"rb").read():
            print str(file).ljust(padding, " ")," : MAC line endings found"

28
Jun 11

Fix a single space in a URI

Looking for a regex to fix a file with a space appearing in random places in the URI:

sed -e 's/\(<[^ >]*\) \([^ ]*> [<.]\)/\1_\2/' < file.nt > newfile.nt

An improvement would be to change that to include more than one space… So here is my test command where I look for a token in the output to see what is matching:

sed -e 's/\(<[^ >]*\) \{1,\}\([^ ]\{0,\}> [<.]\)/\1FOUND\2/' < file.nt | grep FOUND


6
May 11

Installing SwiftOWLIM on MacOSX

I’m sure there are other guides out there, but his is how I did it, and works for me.

Install tomcat

Use macports to install tomcat6

sudo port install tomcat6

This puts tomcat in /opt/local/share/java/tomcat6/

The tomcatctl script can be used to start and stop tomcat.

sudo tomcatctl start
sudo tomcatctl stop
sudo tomcatctl restart

We’ll also be editing tomcatctl to add some specifics for our sesame install.

Install Sesame

  1. Download the sesame tar and unwrap it somewhere convenient.
  2. Drop the .war files from the war/ directory into the tomcat6/webapps/ directory.
  3. Restart tomcat
  4. go to http://localhost:8080/openrdf-sesame
  5. You’ll likely get an error beacuse sesame is tryin to write some directories and log files to a protected area of the system. Therefore you can do this:
    cd ~
    mkdir Aduna
    chmod 777 Aduna
  6. Then add this Java opt to your tomcatctl script. You may also want to change the maximum memory tomcat can use.
    JAVA_OPTS='-Dinfo.aduna.platform.appdata.basedir=/Users/myid/Aduna/'
    JAVA_OPTS="$JAVA_OPTS -Xmx1024m"

Install SwiftOWLIM

  1. Download the SwiftOWLIM distribution.
  2. Follow the instructions in the SwiftOWLIM documentation for a step by step vanilla install.
    (I also copyed {swiftowlim_dir}/lubm/ontology/owl.rdfs to /Users/myid/Aduna/ontology/ but not sure I needed to.)

All Done: hopefully…. now to load some data…

Load Data

Now, I’m sure there are better ways… but…

This script (run using sudo) finds all the files in a given directory that are .nt (ntriples) files.

#!/bin/bash
# script to load data to a local swiftowlim instance.

LOG=load_mydata_swiftowlim.log

for file in `find $1 -name "*.nt"`
do
    ( time  ./loadFileSwiftOwlim.sc $file ) 2>&1 | tee -a $LOG
done

Which calls this expect script to use the sesame console to load the files into the repository.

#!/usr/bin/expect
# script to load data to a local swiftowlim instance.

puts "\n#### Sending $argv"
spawn /opt/local/share/openrdf-sesame-2.3.3/bin/console.sh 

expect "> "
send "connect http://localhost:8080/openrdf-sesame.\r"

expect "> "
send "open mystore.\r"

expect "mystore> "
send "load $argv.\r"

expect "mystore> "
puts "\nLoaded $argv"

15
Feb 10

Taking the plunge

Ever been really indecisive?
Yes?
No?

[gview file=”http://timhodson.com/wp-content/uploads/2010/02/taking-the-plunge.pdf” ]

Creative Commons License
Taking the plunge by Tim Hodson is licensed under a Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales License.
Based on a work at timhodson.com.


15
Feb 10

Shepherd cries wolf

Shepherd cries wolf was written for a crib service at St Paul’s in Hereford.  The madder and the more like compo (last of the summer wine) the shepherd appears, the better. 🙂

[gview file=http://timhodson.com/wp-content/uploads/2010/02/shepherdcrieswolf.pdf]

Released under the following license:
Creative Commons License
Shepherd Cries Wolf by Tim Hodson is licensed under a Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales License.
Based on a work at timhodson.com.


13
Feb 10

Clive’s Funny Valentine

Written for a children’s talk at Lakeside Community Church Perton, this sketch was written with a view to being a screen play.

Hence the video.

Clive is waiting for a valentine day card from someone. anyone…

[gview file=http://timhodson.com/wp-content/uploads/2010/02/The-Apostle-Clive-on-Valentines-day.pdf]

Creative Commons License
Clive’s Funny Valentine by Tim Hodson is licensed under a Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales License.
Based on a work at timhodson.com.


16
Oct 09

The Inner Voice of Hubert Latham

This is one of my favourite pieces. It was composed for a Theatre Skills workshop at Hereford Courtyard Theatre.  It was inspired by 5 words that popped into my head as I cycled the pitch dark lanes of Herefordshire one evening.

“The birds, they mock me!” – I wanted to get home quicker than I could pedal…

I combined that with an early pioneer of powered flight who ditched in the English Channel and was found on his broken plane, calmly smoking a cigarette.

[gview file=”http://timhodson.com/wp-content/uploads/2009/10/the-inner-voice-of-hubert-latham-v2.pdf”]

Creative Commons License
The Inner Voice of Hubert Latham by Tim Hodson is licensed under a Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales License.
Based on a work at timhodson.com.


10
Oct 09

The Security Guard and the Upper Room

A security Guard has previously been detailed to watch a tomb. But the tomb has been vacated right under his eyes. He has come to the upper room to see if the apostle Clive knows anything about it. The Apostle Clive is a bit suspicious.

[gview file=”http://timhodson.com/wp-content/uploads/2009/10/The-security-Guard-and-the-upper-room.pdf”]

Creative Commons License
The Security Guard and the Upper Room by Tim Hodson is licensed under a Creative Commons Attribution-Non-Commercial-No Derivative Works 2.0 UK: England & Wales License.
Based on a work at timhodson.com.

« Page 1 »