List Info

Thread: How to use two adapters?




How to use two adapters?
user name
2007-07-19 11:21:56
Hello,

I am using a redland adapter to store my app's own data,
but I'll also need to be able to query an external SPARQL
store.

Is it possible? If so, how?

Thanks in advance,

-- 
Simon Rozet, http://atonie.org/sr/
_______________________________________________
ActiveRDF mailing list
ActiveRDFlists.deri.org
http
://lists.deri.org/mailman/listinfo/activerdf

Re: How to use two adapters?
user name
2007-07-20 04:31:48
Good luck. I noticed that Rails crashes randomly if I mix two adapters, but then again I might have configured it improperly. When it worked, it did what it should but I got a headache figuring out that the problems arose from using two adapters.

I solved the problem by using a daemon on the server which I connect by DRb. This way it is also possible to run Rails on CRuby and use JRuby adapters.

If you need more help I can show you our code.

Cheers,
Mikael


Re: How to use two adapters?
user name
2007-07-21 02:53:26
We run into problems when we first introduced large ontologies into Rails. We used Joseki + activerdf_sparql adapter, and the "construct classes" instruction took about 30 seconds to execute. This, of course, is unacceptable on www services.

The solution to this is to use a remote DRb server which we instantiate on either environment.rb, or as is our current implementation, in a specific model in Rails:

class ActiveRubinstein

    # require 'drb/drb'
    DRB_SRV = '192.168.0.7'
    DRB_PORT = '2001'
   ; JDRB_SRV = '192.168.0.7'
    JDRB_PORT = '2002'

 ;   ## cRubinstein and jRubinstein are the DRb backends that handle the RDF queries
  ;  RUBINSTEIN = DRbObject.new_with_uri( ['druby',';//' + DRB_SRV, DRB_PORT].join(':') )
    JRUBINSTEIN = DRbObject.new_with_uri( ['druby',';//' + JDRB_SRV, JDRB_PORT].join(':') )
   ;
    DRb.start_service


  # Pass an unadultered query to Rubinstein daemon
  # Parameters:
  #  1  Query
  def query( query, &block )
    return RUBINSTEIN.query( query )
  end

  # Shortcut to a common Query
  # uses given symbols for the 'select' clause
  # Parameters:
  #  1 subject   (symbol or RDFS::Resource)
 ; #  2 predicate (symbol or RDFS::Resource)
 ; #  3 object    (symbol or RDFS::Resource)
  def find( s, p, o )
    begin

      x1 = nil
   ;   x2 = nil
   ;   x3 = nil

 ;     if s.class == Symbol
        x1 = s
      end
   ;   if p.class == Symbol
        x2 = p
      end
      if o.class == Symbol
        x3 = o
      end

 ;     return RUBINSTEIN.query( Query.new.select(x1,x2,x3).where(s, p, o) )
    rescue
      return Array.new
  ;  end
  end

end

This model is inherited to other models:

class Analyzer < ActiveRubinstein
end

or can be directly called from controllers:

ActiveRubinstein.new.query( Query.new.select(:any).where(subject, RDFS::label, :any ) )
ActiveRubinstein.new.find( subject, RDFS::label, :any )

The query method in the Rubinstein daemon:

class Zuma

&nbsp; # Receives and executes an unadultered query through the DRb bridge
&nbsp; # Parameters:
  #  1  Query
&nbsp; def query( query, &block )

 &nbsp;  log ( query.to_s )
 &nbsp;  return query.execute

  end
end

Startup of the DRb daemon:

#####################################################
## DAEMONS
#####################################################
&nbsp; require 'drb/drb'
&nbsp; require 'thread'
&nbsp; require 'gen&#39;

#################################
## The CRuby server daemon
#################################
def cruby_daemon

  DRb.start_service(&quot;druby://#{DRB_SERVER}:#{DRB_PORT}", Zuma.new)

  # join the DRb thread
&nbsp; DRb.thread.join
end

Since we are developing methods to run queries from Jena/Lucene, we also use JRuby, and this solution makes it possible to run Rails with native CRuby.

Sorry for the long post but I hope this helps other people.
Improvements may be suggested!!

Cheers,
Mikael

2007/7/20, Simon Rozet < simon.rozetgmail.com"> simon.rozetgmail.com>:
2007/7/20, Mikael Lammentausta < mikael.lammentaustagmail.com"> mikael.lammentaustagmail.com>:
> Good luck. I noticed that Rails crashes randomly if I mix two adapters, but
> then again I might have configured it improperly. When it worked, it did
> what it should but I got a headache figuring out that the problems arose
&gt; from using two adapters.
>
> I solved the problem by using a daemon on the server which I connect by DRb.
> This way it is also possible to run Rails on CRuby and use JRuby adapters.
>
> If you need more help I can show you our code.

Yes, that'd be great, thanks. Even if it sounds a bit complicated. A
daemon on the server huum isn't it a bit slow?

Thanks for your answer!


--
Simon Rozet, http://atonie.org/sr/

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )