Class: Juxta

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

Overview

This class provides the Ruby interface to the JuxtaWS REST web service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, username = nil, password = nil) ⇒ Connection

Initialize a Juxta interface with optional authentication.

Parameters:

  • URL (String)

    of the JuxtaWS server to connect to.

  • username (String) (defaults to: nil)

    if server require authentication.

  • password (String) (defaults to: nil)

    if server require authentication.



23
24
25
26
# File 'lib/juxta.rb', line 23

def initialize( url, username=nil, password=nil )
  @logging = false
  @connection = Connection.new( url, username, password ) 
end

Instance Attribute Details

#connectionObject (readonly)

The connection object for this Juxta instance.



15
16
17
# File 'lib/juxta.rb', line 15

def connection
  @connection
end

#loggingObject

Set to true to enable logging.



12
13
14
# File 'lib/juxta.rb', line 12

def logging
  @logging
end

Instance Method Details

#async_collate_set(set_id) ⇒ String

Collate the specified comparison set. Returns immediately, use get_status(task_id) to check the status of collation.

Parameters:

  • set_id (String, Integer)

    Identifier of the comparison set.

Returns:

  • (String)

    An identifier for the server task.



408
409
410
411
# File 'lib/juxta.rb', line 408

def async_collate_set( set_id )
   log_message( "Collating witness set #{set_id}..." ) unless @logging == false
   @connection.post( "set/#{set_id}/collate", nil)
end

#async_get_as_html(asset_id) ⇒ String

Retrieve the HTML for a given asset. Returns immediately, use get_status(task_id) to check status.

Parameters:

  • asset_id (String, Integer)

    Identifier of a given asset.

Returns:

  • (String)

    Task_id for the checking status or nil if the asset can not be retrieved.



458
459
460
461
462
463
464
465
# File 'lib/juxta.rb', line 458

def async_get_as_html( asset_id )
  log_message( "Getting html #{asset_id}..." ) unless @logging == false
  resp = @connection.get_html( asset_id )
  if resp.include?('RENDERING') == true
    return resp.split( ' ' )[ 1 ]
  end
  return nil
end

#async_get_as_json(asset_id) ⇒ String

Retrieve the JSON for a given asset. Returns immediately, use get_status(task_id) to check status.

Parameters:

  • asset_id (String, Integer)

    Identifier of a given asset.

Returns:

  • (String)

    Task_id for the checking status or nil if the asset can not be retrieved.



535
536
537
538
539
540
541
542
# File 'lib/juxta.rb', line 535

def async_get_as_json( asset_id )
  log_message( "Getting json #{asset_id}..." ) unless @logging == false
  resp = @connection.get( asset_id )
  if resp['status'] == 'RENDERING'
    return resp['taskId']
  end
  return nil
end

#async_tokenize_set(set_id) ⇒ String

Tokenize the specified comparison set. Returns immediately, use get_status(task_id) to check the status of tokenization. Tokens are accessible as annotations of type ‘token’.

Parameters:

  • set_id (String, Integer)

    Identifier of the comparison set.

Returns:

  • (String)

    An identifier for the server task.



378
379
380
381
# File 'lib/juxta.rb', line 378

def async_tokenize_set( set_id )
   log_message( "Tokenizing witness set #{set_id}..." ) unless @logging == false
   @connection.post( "set/#{set_id}/tokenize", nil)
end

#collate_set(set_id) ⇒ Object

Collate the specified comparison set and wait for the response from server.

Parameters:

  • set_id (String, Integer)

    Identifier of the target comparison set.

Returns:

  • (Object)

    True if successful, false otherwise.



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/juxta.rb', line 417

def collate_set( set_id )
  task_id = async_collate_set( set_id )
  while true do
    sleep(2.0)
    resp = get_status( task_id )
    case resp
      when 'COMPLETE'
        return true

      when 'FAILED'
        error_message( "failed to tokenize set: #{set_id}")
        return false
    end
  end
end

#create_alignments(set_id, json) ⇒ String

Create new alignments, which are associations of annotations in a comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • json (Array)

    An array of hashes defining alignments. See JuxtaWS API docs for hash format.

Returns:

  • (String)

    A JSON array of alignment identifiers created.



212
213
214
215
216
217
# File 'lib/juxta.rb', line 212

def create_alignments( set_id, json )
   asset_id = "set/#{set_id}/alignment"
   log_message( "Posting alignments to #{asset_id}..." ) unless @logging == false   
   resp = @connection.post(asset_id, json)
   return resp
end

#create_annotations(set_id, witness_id, json) ⇒ String

Create new annotations, on a given witness in a comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • witness_id (String, Integer)

    Identifier of a witness.

  • json (Array)

    An array of hashes defining annotations. See JuxtaWS API docs for hash format.

Returns:

  • (String)

    A JSON array of annotation identifiers created.



177
178
179
180
181
182
# File 'lib/juxta.rb', line 177

def create_annotations( set_id, witness_id, json )
   asset_id = "set/#{set_id}/witness/#{witness_id}/annotation"
   log_message( "Posting annotations to #{asset_id}..." ) unless @logging == false   
   resp = @connection.post(asset_id, json)
   return resp
end

#create_sources(source_array) ⇒ Array

Command the server to create source files from the provided array of hashes.

Parameters:

  • source_array (Array)

    Array of hashes describing the sources to be created. See JuxtaWS API for format.

Returns:

  • (Array)

    Identifiers of the sources if successful, otherwise nil.



318
319
320
321
322
# File 'lib/juxta.rb', line 318

def create_sources( source_array )
  log_message( "Creating sources from JSON data..." ) unless @logging == false
  resp = @connection.post( "source", source_array )
  JSON.parse(resp) 
end

#create_witness_set(file_list) ⇒ Array, String

Create an uncollated comparison set from an array of local files.

Parameters:

  • file_list (Array)

    An array of paths to local files to upload.

Returns:

  • (Array)

    Array of resultant source identifiers.

  • (Array)

    Array of resultant witness identifiers.

  • (String)

    The identifier for the resultant comparison set.



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
# File 'lib/juxta.rb', line 589

def create_witness_set( file_list )

  src_ids = []
  wit_ids = []

  file_list.each do |file|

    # create source
    src_id = upload_source( file )
    src_ids.push( src_id )

    # xform to witness
    wit_id = transform_source( src_id )
    wit_ids.push( wit_id )

  end

  # create set from witnesses
  set_id = make_set( wit_ids )

  return src_ids, wit_ids, set_id
end

#create_workspace(workspace_id) ⇒ String

Create a new workspace.

Parameters:

  • Name (String)

    of the workspace to create. Must be unique to this server.

Returns:

  • (String)

    If successful, the created workspace’s id.



65
66
67
68
69
70
# File 'lib/juxta.rb', line 65

def create_workspace( workspace_id )
  log_message( "Creating workspace #{workspace_id} ..." ) unless @logging == false
  json = { "name" => workspace_id, "description" => "the description for #{workspace_id}" }
  workspace_id = @connection.post( "workspace", json, false )
  return workspace_id
end

#create_xslt(name, xslt) ⇒ String

Create a new XSLT on the server.

Parameters:

  • name (String)

    A display name for this XSLT.

  • xslt (String)

    XML string for the XSLT.

Returns:

  • (String)

    An identifier for the newly created XSLT.



149
150
151
# File 'lib/juxta.rb', line 149

def create_xslt( name, xslt )
  @connection.post("xslt", {:name=>name, :xslt=>xslt } )
end

#delete_alignment(set_id, alignment_id) ⇒ Object

Delete the specified alignment from a given comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of the comparison set.

  • alignment_id (String, Integer)

    Identifier of a given alignment.

Returns:

  • (Object)

    True if successful, false otherwise.



287
288
289
# File 'lib/juxta.rb', line 287

def delete_alignment( set_id, alignment_id )
  return delete_asset( "set/#{set_id}/alignment/#{alignment_id}" )
end

#delete_annotation(set_id, witness_id, annotation_id) ⇒ Object

Delete the specified annotation from a given comparison set witness.

Parameters:

  • set_id (String, Integer)

    Identifier of the comparison set.

  • witness_id (String, Integer)

    Identifier of the witness.

  • annotation_id (String, Integer)

    Identifier of the annotation.

Returns:

  • (Object)

    True if successful, false otherwise.



278
279
280
# File 'lib/juxta.rb', line 278

def delete_annotation( set_id, witness_id, annotation_id )
  return delete_asset( "set/#{set_id}/witness/#{witness_id}/annotation/#{annotation_id}" )
end

#delete_set(set_id) ⇒ Object

Delete the specified comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of the comparison set.

Returns:

  • (Object)

    True if successful, false otherwise.



268
269
270
# File 'lib/juxta.rb', line 268

def delete_set( set_id )
  return delete_asset( "set/#{set_id}" )
end

#delete_source(source_id) ⇒ Object

Delete the specified source.

Parameters:

  • source_id (String, Integer)

    Identifier of the source.

Returns:

  • (Object)

    True if successful, false otherwise.



252
253
254
# File 'lib/juxta.rb', line 252

def delete_source( source_id )
  return delete_asset( "source/#{source_id}" )
end

#delete_witness(witness_id) ⇒ Object

Delete the specified witness.

Parameters:

  • witness_id (String, Integer)

    Identifier of the witness.

Returns:

  • (Object)

    True if successful, false otherwise.



244
245
246
# File 'lib/juxta.rb', line 244

def delete_witness( witness_id )
   return delete_asset( "witness/#{witness_id}" )
end

#delete_workspace(workspace_id) ⇒ Object

Delete a new workspace and everything in it.

Parameters:

  • Name (String)

    of the workspace to delete.

Returns:

  • (Object)

    True if successful, false otherwise.



76
77
78
79
80
81
82
83
84
# File 'lib/juxta.rb', line 76

def delete_workspace( workspace_id )
  log_message( "Deleting workspace #{workspace_id} ..." ) unless @logging == false
  resp = @connection.delete( "workspace/#{workspace_id}", false )
  if resp['status'] == 'FAILED'
     error_message( "failed to delete asset: #{asset_id}")
     return false
  end
  return true
end

#delete_xslt(xslt_id) ⇒ Object

Delete the specified XSLT.

Parameters:

  • xslt_id (String, Integer)

    Identifier of the XSLT.

Returns:

  • (Object)

    True if successful, false otherwise.



260
261
262
# File 'lib/juxta.rb', line 260

def delete_xslt( xslt_id )
  return delete_asset( "xslt/#{xslt_id}" )
end

#export(set_id, base_id) ⇒ Object

TEI Parallel segmentation export



577
578
579
580
581
# File 'lib/juxta.rb', line 577

def export( set_id, base_id )
  log_message( "Exporting set #{set_id}..." ) unless @logging == false
  resp = @connection.get_xml( "set/#{set_id}/export?mode=teips&base=#{base_id}&sync" )
  return resp
end

#get_alignment(set_id, alignment_id) ⇒ Hash

Get full information about a given alignment.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • alignment_id (String, Integer)

    Identifier of an alignment.

Returns:

  • (Hash)

    A hash with complete information about the alignment, including text fragments.



234
235
236
237
238
# File 'lib/juxta.rb', line 234

def get_alignment( set_id, alignment_id )
  asset_id = "set/#{set_id}/alignment/#{alignment_id}"
  log_message( "Getting alignment #{asser_id}..." ) unless @logging == false
  @connection.get( "#{asset_id}" )
end

#get_annotation(set_id, witness_id, annotation_id) ⇒ Hash

Retrieve information about a specific annotation.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • witness_id (String, Integer)

    Identifier of a witness.

  • annotation_id (String, Integer)

    Identifier of the specified annotation.

Returns:

  • (Hash)

    A hash containing the annotation data.



202
203
204
205
# File 'lib/juxta.rb', line 202

def get_annotation( set_id, witness_id, annotation_id )
  log_message( "Getting annotation #{annotation_id}..." ) unless @logging == false
  @connection.get( "set/#{set_id}/witness/#{witness_id}/annotation/#{annotation_id}?content=YES" )
end

#get_as_html(asset_id) ⇒ Object

Retrieve the HTML for a given asset, waiting for server to prepare asset if necessary.

Parameters:

  • asset_id (String, Integer)

    Identifier of a given asset.

Returns:

  • (Object)

    HTML for the asset or false if the asset could not be retrieved.



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/juxta.rb', line 511

def get_as_html( asset_id )
   task_id = async_get_as_html( asset_id )
   if task_id.nil? == false
      while true do
         sleep(2.0)
         resp = get_status( task_id )
         case resp
         when 'COMPLETE'
            return @connection.get_html( asset_id )

         when 'FAILED'
            error_message( "failed to get html asset: #{asset_id}")
            return false
         end
      end
   end
   return resp
end

#get_as_json(asset_id) ⇒ Object

Retrieve the JSON for a given asset, waiting for server to prepare asset if necessary.

Parameters:

  • asset_id (String, Integer)

    Identifier of a given asset.

Returns:

  • (Object)

    JSON for the asset or false if the asset could not be retrieved.



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
# File 'lib/juxta.rb', line 548

def get_as_json( asset_id )
   task_id = async_get_as_json( asset_id )
   if task_id.nil? == false
      while true do
         sleep(2.0)
         resp = get_status( task_id )
         case resp
         when 'COMPLETE'
            return @connection.get( asset_id )

         when 'FAILED'
            error_message( "failed to get json asset: #{asset_id}")
            return false
         end
      end
   end
   return false
end

#get_heatmap_asset_id(set_id, base_id) ⇒ String

Creates an asset identifier for the heatmap of a given base text in a comparison set. Use get_as_html or get_as_json to retrieve the asset.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • base_id (String, Integer)

    Identifier of a base text.

Returns:

  • (String)

    Asset identifier for the heatmap visualization of the given base text.



473
474
475
# File 'lib/juxta.rb', line 473

def get_heatmap_asset_id( set_id, base_id )
  "set/#{set_id}/view?mode=heatmap&base=#{base_id}"    
end

#get_heatmap_url(set_id, base_id) ⇒ String

Creates a URL for the heatmap of a given base text in a comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • base_id (String, Integer)

    Identifier of a base text.

Returns:

  • (String)

    URL to the heatmap visualization of the given base text.



493
494
495
# File 'lib/juxta.rb', line 493

def get_heatmap_url( set_id, base_id )
  @connection.make_full_url( get_heatmap_asset_id(set_id,base_id) )    
end

#get_set(set_id) ⇒ Hash

Get full information about a given comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

Returns:

  • (Hash)

    A hash with complete information about the comparison set, including a list of witnesses.



166
167
168
169
# File 'lib/juxta.rb', line 166

def get_set( set_id )
  log_message( "Getting set #{set_id}..." ) unless @logging == false
  @connection.get( "set/#{set_id}" )
end

#get_side_by_side_asset_id(set_id, witness_a, witness_b) ⇒ String

Creates an asset identifier for a side-by-side comparison of two witnesses in a comparison set. Use get_as_html or get_as_json to retrieve the asset.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • witness_a (String, Integer)

    Identifier of the first witness.

  • witness_b (String, Integer)

    Identifier of the second witness.

Returns:

  • (String)

    Asset identifier for the side-by-side visualization.



484
485
486
# File 'lib/juxta.rb', line 484

def get_side_by_side_asset_id( set_id, witness_a, witness_b )
  "set/#{set_id}/view?mode=sidebyside&docs=#{witness_a},#{witness_b}" 
end

#get_side_by_side_url(set_id, witness_a, witness_b) ⇒ String

Creates a URL for a side-by-side comparison of two witnesses in a comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • witness_a (String, Integer)

    Identifier of the first witness.

  • witness_b (String, Integer)

    Identifier of the second witness.

Returns:

  • (String)

    URL to the side-by-side visualization.



503
504
505
# File 'lib/juxta.rb', line 503

def get_side_by_side_url( set_id, witness_a, witness_b )
  @connection.make_full_url( get_side_by_side_asset_id(set_id, witness_a, witness_b) )    
end

#get_source(source_id) ⇒ Hash

Get full information about a given source.

Parameters:

  • source_id (String, Integer)

    Identifier of the source to retrieve.

Returns:

  • (Hash)

    A hash with complete information about the source, including full text.



107
108
109
110
# File 'lib/juxta.rb', line 107

def get_source( source_id )
  log_message( "Getting source #{source_id}..." ) unless @logging == false
  @connection.get( "source/#{source_id}" )
end

#get_status(task_id) ⇒ String

Retrieve the status of a server side task.

Parameters:

  • task_id (String, Integer)

    An identifier for a server side task.

Returns:

  • (String)

    A status code. Possible codes are: PENDING, PROCESSING, COMPLETE, CANCEL_REQUESTED, CANCELLED, FAILED.



447
448
449
450
451
# File 'lib/juxta.rb', line 447

def get_status( task_id )
  log_message( "Getting status for #{task_id}..." ) unless @logging == false
  resp = @connection.get("task/#{task_id}/status")
  return resp['status']
end

#get_witness(witness_id) ⇒ Hash

Get full information about a given witness.

Parameters:

  • witness_id (String, Integer)

    Identifier of the witness to retrieve.

Returns:

  • (Hash)

    A hash with complete information about the witness, including full text.



98
99
100
101
# File 'lib/juxta.rb', line 98

def get_witness( witness_id )
  log_message( "Getting witness #{witness_id}..." ) unless @logging == false
  @connection.get( "witness/#{witness_id}" )
end

#get_witness_fragment(witness_id, start_point, end_point) ⇒ String

Retrieve a text fragment from a given witness.

Parameters:

  • witness_id (String, Integer)

    Identifier of the witness.

  • start_point (String, Integer)

    Starting offset of the fragment.

  • end_point (String, Integer)

    Ending offset of the fragment.

Returns:

  • (String)

    A string containing the text fragment, if found.



118
119
120
121
# File 'lib/juxta.rb', line 118

def get_witness_fragment( witness_id, start_point, end_point )
  log_message( "Getting witness #{witness_id}..." ) unless @logging == false
  @connection.get_html( "witness/#{witness_id}.txt?range=#{start_point},#{end_point}" )
end

#get_xslt(asset_id) ⇒ String

Get the specified XSLT resource from server.

Parameters:

  • asset_id (String, Integer)

    The identifier of the specified XSLT.

Returns:

  • (String)

    XML for the specified XSLT.



571
572
573
574
# File 'lib/juxta.rb', line 571

def get_xslt( asset_id )
  log_message( "Getting xslt #{asset_id}..." ) unless @logging == false
  @connection.get_html( "xslt/#{asset_id}" )
end

#list_alignments(set_id) ⇒ Array

List the alignments for a given comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

Returns:

  • (Array)

    An array of hashes containing alignment data.



223
224
225
226
227
# File 'lib/juxta.rb', line 223

def list_alignments( set_id )
  asset_id = "set/#{set_id}"
  log_message( "Listing alignments for #{asset_id}..." ) unless @logging == false
  @connection.get( "#{asset_id}/alignment" )
end

#list_annotations(set_id, witness_id) ⇒ Array

List the annotations applied to a given witness in a comparison set.

Parameters:

  • set_id (String, Integer)

    Identifier of a comparison set.

  • witness_id (String, Integer)

    Identifier of a witness.

Returns:

  • (Array)

    An array of hashes containing annotation data.



189
190
191
192
193
194
# File 'lib/juxta.rb', line 189

def list_annotations( set_id, witness_id )
  asset_id = "set/#{set_id}/witness/#{witness_id}"
  log_message( "Listing annotations for #{asset_id}..." ) unless @logging == false
  annotation_list = @connection.get( "#{asset_id}/annotation" )
  return annotation_list
end

#list_setsArray

List the comparison sets in this workspace.

Returns:

  • (Array)

    An array of hashes with summary information about each comparison set.



355
356
357
358
359
# File 'lib/juxta.rb', line 355

def list_sets
  log_message( "Listing sets..." ) unless @logging == false
  set_list = @connection.get( "set" )
  return set_list
end

#list_sourcesArray

List the sources in this workspace.

Returns:

  • (Array)

    An array of hashes with summary information about each source.



138
139
140
141
142
# File 'lib/juxta.rb', line 138

def list_sources
  log_message( "Listing sources..." ) unless @logging == false
  source_list = @connection.get( "source" )
  return source_list
end

#list_witnessesArray

List the witnesses in this workspace. Witnesses are the transformed version of the sources.

Returns:

  • (Array)

    An array of hashes with summary information about each witness.



89
90
91
92
# File 'lib/juxta.rb', line 89

def list_witnesses
  log_message( "Listing witnesses..." ) unless @logging == false
  @connection.get( "witness" )
end

#list_workspacesArray

Lists the workspaces available on this server.

Returns:

  • (Array)

    List of workspace names.



55
56
57
58
59
# File 'lib/juxta.rb', line 55

def list_workspaces
  log_message( "Listing workspaces..." ) unless @logging == false
  ws_list = @connection.get( "workspace", false )
  return ws_list
end

#list_xsltArray

List the XSL stylesheets in this workspace.

Returns:

  • (Array)

    An array of hashes with summary information about each XSLT.



156
157
158
159
160
# File 'lib/juxta.rb', line 156

def list_xslt
  log_message( "Listing xslt..." ) unless @logging == false
  xslt_list = @connection.get( "xslt" )
  return xslt_list
end

#make_set(witness_ids) ⇒ String

Group the specified witnesses into a new comparison set.

Parameters:

  • witness_ids (Array)

    An array of witness identifiers.

Returns:

  • (String)

    Identifier of the resultant comparison set.



365
366
367
368
369
370
# File 'lib/juxta.rb', line 365

def make_set( witness_ids )
  log_message( "Creating witness set ..." ) unless @logging == false
  set = { 'name' => make_guid(), 'witnesses' => witness_ids }
  set_id = @connection.post( "set", set )
  return set_id
end

#obtain_source_from_url(url) ⇒ String

Command the server to obtain an XML source file from the specified URL.

Parameters:

  • url (String)

    URL of the XML source file to grab.

Returns:

  • (String)

    Identifier of the obtained source if successful, otherwise nil.



328
329
330
331
332
333
334
335
336
337
338
# File 'lib/juxta.rb', line 328

def obtain_source_from_url( url )
  id = make_guid()
  log_message( "Downloading #{url} as #{id} ..." ) unless @logging == false
  resp = @connection.post( "source", [{name: id, type: 'url', contentType: 'xml', data: url}] )
  parsed = JSON.parse(resp) 
  if parsed.length > 0
    parsed[0]
  else
    nil
  end
end

#rename_witness(witness_id, new_name) ⇒ Hash

Change the name of the witness.

Parameters:

  • witness_id (String, Integer)

    Identifier of the witness.

  • new_name (String, Integer)

    The new name for the witness.

Returns:

  • (Hash)


128
129
130
131
132
133
# File 'lib/juxta.rb', line 128

def rename_witness( witness_id, new_name )
  log_message( "Renaming witness #{witness_id} to #{new_name}..." ) unless @logging == false
  json = { 'name' => new_name }
  resp = @connection.put( "witness/#{witness_id}", json )
  return resp
end

#search(query) ⇒ Array

Search the current workspace for the specified phrase. Server must have search indexing enabled.

Parameters:

  • query (String)

    The phrase to search for within the workspace.

Returns:

  • (Array)

    An array of objects that detail the search results.



437
438
439
440
441
# File 'lib/juxta.rb', line 437

def search( query )
  log_message( "Searching for #{query}..." ) unless @logging == false
  resp = @connection.get("search?q=#{query}")
  return resp
end

#select_workspace(workspace_name) ⇒ Object

Select a workspace to operate in.

Parameters:

  • workspace_name (String)

    this is the name of the workspace.

Returns:

  • (Object)

    true if selection suceeded, false otherwise.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/juxta.rb', line 38

def select_workspace(workspace_name)
  workspaces = list_workspaces()
  workspace_names = workspaces.map { |workspace|
    workspace["name"]
  }
  
  if workspace_names.include? workspace_name
    @connection.workspace = workspace_name
    return true
  else
    return false
  end    
end

#tokenize_set(set_id) ⇒ Object

Tokenize the specified comparison set. Tokens are accessible as annotations of type ‘token’.

Parameters:

  • set_id (String, Integer)

    Identifier of the comparison set.

Returns:

  • (Object)

    True if successful, false otherwise.



387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/juxta.rb', line 387

def tokenize_set( set_id )
  task_id = async_tokenize_set( set_id )
  while true do
    sleep(2.0)
    resp = get_status( task_id )
    case resp
      when 'COMPLETE'
        return true

      when 'FAILED'
         error_message( "failed to tokenize set: #{set_id}")
         return false
    end
  end
end

#transform_source(source_id) ⇒ String

Transform the specified source into a witness using the associated XSLT.

Parameters:

  • source_id (String, Integer)

    Identifier of the source.

Returns:

  • (String)

    Identifier of the resultant witness.



344
345
346
347
348
349
350
# File 'lib/juxta.rb', line 344

def transform_source( source_id )

  log_message( "Transforming #{source_id} ..." ) unless @logging == false
  json = { 'source' => source_id, 'finalName' => make_guid() }
  wit_id = @connection.post( "transform", json )
  return wit_id
end

#upload_source(file_name) ⇒ String

Upload a file from local disk to the server.

Parameters:

  • file_name (String)

    Local path to the file to upload.

Returns:

  • (String)

    Identifier of uploaded source if successful, otherwise nil.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/juxta.rb', line 295

def upload_source( file_name )

   id = make_guid()
   log_message( "Uploading #{file_name} as #{id} ..." ) unless @logging == false
   src_id = @connection.upload_file( id, "text/xml", open( file_name ))

   srcs = @connection.get("source")
   srcs.each do |src|
     if src['id'] == src_id
       log_message( "successfully uploaded file: #{file_name} (#{src['name']})" ) unless @logging == false
       return src_id
     end

   end

   error_message( "failed to upload file: #{file_name}")
   return nil
end

#workspaceString

The name of the currently selected workspace. Default is “public”.

Returns:

  • (String)

    The name of the current workspace.



30
31
32
# File 'lib/juxta.rb', line 30

def workspace()
  @connection.workspace
end