Class: Pho::FileManagement::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/pho/upload.rb

Class Method Summary collapse

Class Method Details

.prepare_and_store_upload(store, src_dir, collection_dir, triples = FileSplitter::DEFAULT_CHUNK_SIZE) ⇒ Object

Prepares a batch of files for uploading into the platform, then posts that collection to the designated store

Returns an RDFManager instance that can be inspected to check for successes



145
146
147
148
149
150
151
152
# File 'lib/pho/upload.rb', line 145

def Util.prepare_and_store_upload(store, src_dir, collection_dir, 
    triples=FileSplitter::DEFAULT_CHUNK_SIZE)
    
  prepare_platform_upload(store, src_dir, collection_dir)
  collection = Pho::FileManagement::RDFManager.new(store, collection_dir)
  collection.store()
  return collection
end

.prepare_platform_upload(store, src_dir, collection_dir, triples = FileSplitter::DEFAULT_CHUNK_SIZE) ⇒ Object

Take a directory of files, copy them to temporary directory, splitting where necessary, in preparation for uploading to a platform store.

Source directory is scanned for ntriple, turtle and RDF/XML files. All of these are automatically chunked into 10,000 triple chunks and re-serialized as ntriples

BNodes are automatically re-written to full uris.

store:: Pho::Store into which data will be posted. Used to normalizing bnodes
src_dir:: directory containing source data.


124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/pho/upload.rb', line 124

def Util.prepare_platform_upload(store, src_dir, collection_dir, 
    triples=FileSplitter::DEFAULT_CHUNK_SIZE)
    
    handler = BNodeRewritingHandler.new( store.build_uri("/items") )
    splitter = FileSplitter.new(collection_dir, triples, handler )
    
    formats = [ ["*.rdf", :rdfxml], ["*.nt", :ntriples], ["*.ttl", :turtle] ]
    formats.each do |format|
      
      files = Dir.glob( File.join(src_dir, format[0] ) )
      splitter.split_files(files, format[1] )
      
    end
    return true
    
end