Class: ActiveRubic::Base

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

Overview

Methods

find()

accepts two type of queries

  • an RDFS::Resource object, with options that specify the requested value

  • action; a Ruby Symbol

actions are defined in storage-specific objects:

  • ActiveRubinstein::Base,

  • ActiveRubinstein::SparqlFormulator

  • ActiveRubinstein::JenaQuery

  • ActiveRubinstein::LuceneSearcher

  • ActiveRubinstein::JosekiQuery

search()

string query from Lucene indices

sparql()

accepts a Ruby Query and executes it to storages that accept SPARQL

EXAMPLES:

  • ActiveRubic::Base.find( subject, :label, :from => :jena )

  • this is the function called by RDFS::Resource.label

  • ActiveRubic::Base.sparql( Query.new.distinct( :gp ).where( :gp, GEO::point, KUOPIO::kuopion_museo ) )

  • this is the function called by RDFS::Resource.geopoint

Constant Summary collapse

@@rails_db =
RailsDB.new( 'precursor' )

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

:nodoc:



33
34
# File 'lib/active_rubic/base.rb', line 33

def initialize # :nodoc:
end

Class Method Details

.check_connection(options = {}) ⇒ Object

checks if the servers are alive, tries to re-initialize ActiveRubinstein once.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_rubic/base.rb', line 50

def check_connection( options={} )
  begin
    ActiveRubinstein::Base.new() if options[ :reinit_rubinstein ]
    ActiveRubinstein::JenaQuery.server.ping
  rescue
    # try to re-initialize once
    unless options[ :reinit_rubinstein ]
      check_connection( :reinit_rubinstein => true )
    else
      raise ConnectionNotEstablishedError, $!
    end
  end
end

.find(*args) ⇒ Object

The main method for queries.

options:

  • :data_stores = Array

  • :suffice_to = Array of data_stores that are trusted to return sufficient results. By default all data stores are untrusted to be complete, and the results of each are combined. The results of servers given in the Array.

  • :combine = Array of data stores that are queried and the results combined. If the trusted server returns results, trust that the contents is sufficient.

EXAMPLES:

  • triple-based: find( RDFS::label, :subject => KUOPIO::kuopion_museo )

  • abstract: find( :images_of, :subject => KUOPIO::puijon_torni )



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/active_rubic/base.rb', line 88

def find(*args)
  options = extract_options_from_args!(args)
#         validate_find_options(options)
#         set_readonly_option!(options)
  @@log.rubic " * Find: #{args}, #{options}"

  case args.first
    ###########################################
#           when :first then find_initial(options)

    ###########################################
    when :all   then 
      return serial_query_handler( :all, options )

    ###########################################
#          else              find_from_resources(args, options)
    else
      return serial_query_handler( args.first, options )
  end
end

.search(keywords, options = {}) ⇒ Object

Counterpart to find(). Instead of resource-based queries, this method takes in strings and returns resources from Lucene indices.

The indices are defined in Rubinstein/config/lucene_indices.rb

Parameters:

  • 1 keywords (String)

  • 2 options (Hash;

    :index => :images,
    :limit => @@search_limit,
    :score_limit => 0.0,
    :original_keywords => search_string,
    :from => :lucene | :geolucene
    


138
139
140
141
142
143
# File 'lib/active_rubic/base.rb', line 138

def search( keywords, options={} )
  @@log.rubic " * Search: #{keywords}, #{options}"

  options.update :lucene_branch => :standard
  return ActiveRubinstein::LuceneSearcher.search( keywords, options )
end

.set_query_options(options = {}) ⇒ Object

Sets the Rubinstein query parameters.

Parameters:

  • 1, lang (Hash; :lang => ‘en’)



68
69
70
71
72
73
74
75
76
# File 'lib/active_rubic/base.rb', line 68

def set_query_options( options={} )
  lang = options[ :lang ]

  # set the language by which Rubinstein queries.
  if lang
    @@log.rubic "Using language #{lang} (#{lang.class})" 
    ActiveRubinstein::Base.set_language( lang )
  end
end

.sparql(query, *args, &block) ⇒ Object Also known as: find_by_sparql, query

Executes a SPARQL query on the backends that support this. calls serial_query_handler, which calls the query validator.

EXAMPLES:

  • sparql( Query.new.distinct( :s ).where( :s, KUOPIO::isDesignedBy, TOIMIJAT::j_v_stromberg ) )



113
114
115
116
117
118
119
120
121
122
# File 'lib/active_rubic/base.rb', line 113

def sparql( query, *args, &block )
  unless query.is_a? Query
    @@log.error "The first parameter must be a Query"
  else
    options = extract_options_from_args!(args)
    @@log.rubic " * Received SPARQL; options: #{options}"
    @@log.query " * Sparql: #{query.to_sp}"
    return serial_query_handler( query, options )
  end
end