Raramorph is a Ruby 1.9 gem for an intelligent port of Aramorph based on Buckwalter Arabic Morphological Analyzer Version 1.0 , Released By eSpace Technologies.

The first Release of Raramorph full morphological analyzer tools , provided with an executable or a library can be included in the code , with basic developer tools , to be extended in the next version.

Due to algorithmic and data structures optimization in Raramorph , we enhanced the performance of the library reaching an average of 4 – 5 seconds in loading the dictionaries  which was the main bottleneck in the java raramorph reaching to 10-11 seconds and average of 2-3 seconds in parsing meduim sized files and printing the output file.

Installing Raramorph :

gem install raramorph  ( note that raramorph requires Ruby1.9 )

Usage :

for exectuable :

raramorph input_file_name output_file_name  -v -a
  -v verbose mode ( optional )
  -a arabic output ( optional )

In Coding

require ‘raramorph’

For analyzing a file

Raramorph.execute(input_filename, output_filename ,verbose = false, not_arabic = true)

You can use functions like analyze_token , tokenize , segement_word all as static methods in Raramorph class , In the next Release developer tools will be more stable including more features for analysis and finding the morphological solutions , which can be used in searching and mining engines.

Also Raramorph -ferret adapter is to be released soon , for helping in the morphological analysis in search engines.

Raramorph Source Code is avaliable at :

http://github.com/espace/raramorph/tree/master

Raramorph Documentation is availabe here.

If you are one of the Ruby On Rails developers , and  trying to make a complex has_many relation , you have one option .. the :finder_sql and :count_sql options.

these options allows you to write a custom query for your relation maintaining the remaining association options.

So if you were quering using the instance variables of the object like this ,

:finder_sql => “select * from attendance_items a where a.employee_id = #{id}”

This will give you wrong results , even more if your query was like this

:finder_sql => “select * from attendance_items a, where a.email = #{email}”

where email is an attribute in Employee… you will get a syntax error !!!

Cause : writing variables in the query between double quotes , makes the variable to be expanded once it was parsed , so in the first case the returned  id will be the object id in the memory not the active record id and in the second case , it will find that no attribute is name email as the object was not loaded.

Solution : Simply replace the double quotes with single quotes , this cause rails to skip expanding the variables.

:finder_sql => ‘select * from attendance_items a ‘+
‘where a.employee_id = #{self.hr_id}’

For an application that requires communication and interactive communication between the users , chatting is one of the most suitable to make you achieve this aspect . A lot of chatting programs are availiable , alot of chatting sites are availiable , but if you want to make a browser based chatting through your application , this might seem to be a little bit complicated.

The main problem is that , Our traditional browsers pulls the page from the server using requests and the server replies with a response , this model is not applicable to use in a browser based chatting application , as what is supposed to happen when client X send the data to client Y ? Client  X sends the data to the server then the server pushs this data to client Y , In our traditional model the server can’t send the data to the browser without a request from the client , this puts to us limited choices to implement this  , as periodically asking the server for new data which is not efficent and highly costing.

So what is the solution … ? PUSH SERVERS TECHNOLOGY

Push technology, or server push, describes a style of Internet-based communication where the request for a given transaction originates with the publisher or central server. It is contrasted with pull technology, where the request for the transmission of information originates with the receiver or client. A lot of Push Servers have been introduced ..  I looked at most of them the most exceptional one , was the   Flash Media Server But its not free for more than 10 connected users , and simply you can look at its price to know why its not feasible to be used by startups 🙂 …

So as working with Ruby On Rails , I searched for a neat Ruby On Rails solution , this was the result …  Juggernaut Push Server Plugin . This was an excellent solution for me… However let’s take a look at Juggernaut.

Juggernaut is a push server written in Ruby , that can make your application interactively communicate with the server. Juggernaut uses flash objects , javascripts , rails code .

How does Juggernaut work ?

Juggernaut uses a flash object in the browser with a server socket , which makes juggernaut work on almost 90 % of the current browsers , as it only requires flash 8.

Juggernaut Consists of three main parts

  1. in-browser/client side elements
  2. a stand alone push server and
  3. Rails elements to tie everything together.

So this is a simple chat scenario….

  • Browser connects to rails server , recieves the required javascripts , SWFs files   ( Element 1 )
  • The browser creates a flashXML socket with the push server ( used for listening )  ( Element 1 )
  • The Client sends the data using AJAX method to a controller.  ( Element 3 )
  • Rails send the data to the push server using the Juggernaut plugin methods  ( Element 3 )
  • Juggernaut push server broadcasts the data to the channels  ( Element 2 )
  • Clients receive the new data using the flashXML socket and updates the dom elements with Javascript ( Element 1)

Juggernaut has different modes of operation , the data can be sent to a certain channel ( no. of users ) Or to a specific user .

Advantages of Juggernaut

  • Allows a real time connection with a client – Rails can literally push javascript in real time to the client which is then evaluated.
  • Using flash sockets allows us to use different port other than the rails application port , which helps us not to overload the application server with requests which may lead to crash the application , thats why we need a stand alone application server
  • Push server – written in Ruby using EventMachine. EventMachine has a non-blocking IO so scales very well
  • Integrated, as a plugin, into Rails.
  • Subscribers can subscribe to multiple channels, and broadcasters can broadcast to multiple channels.
  • Broadcasts can be made to channels, or to a specific client.
  • Connect/Disconnect triggers.
  • Authentication support.
  • Uses Flash 8 – installed on more than 95% of computers.
  • Supports all the major browsers (uses ExternalInterface): Firefox 1+, IE 6+ and Safari 2+

My friends and I made juggernaut plugin to add a secured chatting sessions to juggernaut using RSA or DES encryption algorithms , I’ll write  a blog post about it soon.

So How can I use juggernaut..

This is a very good tutorial about installing and using Juggernaut in your application , it is quite straight forward in linux , but it has some problems in installation with windows and it solved here

Hope this was helpful

Radiant is a cool tool for managing the contents of a website , however many times you will feel that you need to need to customize things in Radiant , but its hard to do because of the radiant structure  which makes the radiant code not visible directly to you , lack of documentation in creating extensions , but we can overcome by a simple way , which is trying to control the Radiant Page without editing the main Radiant gem Code through some Radiant and Rails Facilities.

I was working in a project where I needed to edit the ( pre-created add page ) view for the admin , to add in certain cases some buttons , links , page parts with new actions to be added . The solution is quite simple…

It is assumed that you have a fair knowledge with Radiant extensions to complete through the steps.

Steps :

1 – Appending code to a written action in the radiant controllers

  • In the activate method in the x_extension.rb file in your extension folder , Open the controller you want to add the functions in , use the rails call back functions ( after_filter , before_filter ) to append the code to the required action

Admin::PageController.class_eval do

after_filter :this_is_a_function  , :only => [:new , :edit ,:update]

private
def
this_is_a_function

# do your code
end

end

2- After adding the back end code we need to put the display to this code in the Radiant page  , we can use the radiant ( admin.page.edit , admin.tabs )  to append objects to specific regions in the page , this is the attributes the admin.page.edit object has , these attributes defines certain regions in the page , where Radiant uses these regions to divide the page . You are able to edit in any of these regions , under any conditions without affecting the existing Radiant gem

@regions={:form=>[“edit_title”, “edit_extended_metadata”, “edit_page_parts”],     :form_bottom=>[“edit_buttons”], :parts_bottom=>[“edit_layout_and_type”, “edit_timestamp”],  :main=>[“edit_header”, “edit_form”, “edit_popups”]}>
(  admin.page.edit ) attributes

Example :

Add a button to the bottom of the form in case the page is having a certain page  type (  Archive , normal , not found …) , Add a select list for the user to choose an element  in the bottom part of the page

  • Just add the following lines  in your activate method in the x_extension.rb file

admin.page.edit.form_bottom << “add_button”

admin.page.edit.parts_bottom << “select”

In these two lines , we tell the radiant to add  partials in the named regions ( form_bottom  , parts_bottom )  to be render , as the regions are arrays of partials and the radiant renders the partials in the regions.

  • The only remaining thing is to create the partials

A.  create folder called admin and inside it add the page ( As we write the partials in the admin namespace )

B.  Add the html code you want in the partials you want , you can add conditions inside the partials to make it rendered in some specific page claasses

3. You can add specific page parts to a certain class of pages by the same way of adding actions to controller , you can use the after_save call back and add some code to add a page parts to the page as follows :

Admin::Page.class_eval do

after_save :add_parts

def_add_parts

if this.class_name == “X”

this.parts << PagePart.new(:name=> “x” , :filter_id => “y” , :page_id=>this.id  )

end

end

end

This will add a part for the class of pages you choose ..

Hope this will be helpful

Facing problems while configuring anything in linux is a normal thing .. may be its boring and tiring .. but its really interesting when you solve them..

As a linux  starter i face some problems while configuring ruby on rails environment for linux .. Here they are

Note : Sure before any thing you need to get ruby and rails installed

  • sudo apt-get install ruby
  • sudo apt-get install rubygems
  • gem install rails –include-dependencies

1.Problem :Any Gem that lets you choose between mswin32 and ruby ( and of course you choose ruby ) is installed

  • Solution : Simply this happens because these gems require compilation so just give them the tool
    • sudo apt-get install g++ ( Now you are done and can work )

2.  Problem : While Installing A gem it tells you this: Could not create Makefile due to        some necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

  • Solution : This Happens because the ruby1.8-dev required library is not installed so simply
    • sudo apt-get install ruby1.8-dev Done

3. Problem : Always installing rmagick gem is a problem but i think its solution in linux is more simple than windows

  • Solution : 3 Steps ( Download imagicmagick , The Lib Magick library , Then the Gem )

    • sudo apt-get install imagemagick
    • sudo apt-get install libmagick9-dev
    • gem install rmagick

4. Problem : The great Problem of the file ( /tmp/mysql.sock ) which makes you not able to use rake db:migrate or any other access to the mysql databases

  • Solution : This Problem arises as the mysql.sock file location and a name has changed during newer versions to be installed in this silly location ( /var/run/mysqld/mysqld.sock) . Really Boring… So now we have to make a symbolic link and also change the name so do this
    • ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock

These Problems were very annoying and tiring for me and i hope it helps