def __init__(self,source, defaultStatements=(), context='', **kw): stmts, format, fsize, mtime = loadFileStore(source, context) if stmts is None: stmts = defaultStatements #try to save in source format if format == 'ntriples': self.format = 'nt' self.path = source elif format == 'rdfxml': self.format = 'xml' self.path = source else: #unsupported format, save as ntriples (to new file) self.format = 'nt' base, ext = os.path.splitext(path) self.path = base + '.nt' import rdflib RDFLibStore.__init__(self, rdflib.ConjunctiveGraph()) self.addStatements( stmts )
from vesper.data.store import basic import sys if len(args) == 2: source = sys.argv[1] dest = sys.argv[2] else: print 'usage: copystore.py [source] [dest]' sys.exit(-1) stmts, format, fsize, mtime = basic.loadFileStore(source) store = basic.MemStore(stmts) format = basic.guessFileType(dest) if not format: print 'error: unknown format for', dest sys.exit(-1) outputfile = open(dest, 'wt') try: stmts = store.getStatements() basic.serializeRDF_Stream(stmts, outputfile, format) finally: outputfile.close()