'Process results of twitter search with KeyGraph.'

@staticmethod
def process_keygraph(search_id):

    import subprocess
    import os
    import tempfile
    db = current.db
    s3db = current.s3db
    curpath = os.getcwd()
    preprocess = S3Msg.preprocess_tweet
    def generateFiles():
        dirpath = tempfile.mkdtemp()
        os.chdir(dirpath)
        rtable = s3db.msg_twitter_search_results
        tweets = db((rtable.deleted == False)).select(rtable.body)
        tweetno = 1
        for tweet in tweets:
            filename = ('%s.txt' % tweetno)
            f = open(filename, 'w')
            f.write(preprocess(tweet.body))
            tweetno += 1
        return dirpath
    tpath = generateFiles()
    jarpath = os.path.join(curpath, 'static', 'KeyGraph', 'keygraph.jar')
    resultpath = os.path.join(curpath, 'static', 'KeyGraph', 'results', ('%s.txt' % search_id))
    return subprocess.call(['java', '-jar', jarpath, tpath, resultpath])
