yshnb / refine-ruby

Ruby client library for controlling Google Refine

Home Page:http://code.google.com/p/google-refine/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

google-refine

is a Ruby Gem client library for Google Refine

If you want to port this to another language, check out the Refine API documentation.

Install

gem install google-refine

Example

Given that you have the following raw data:

  
    Date
    7 December 2001
    July 1 2002
    10/20/10
  

Google Refine lets you clean up the data and export your operation history as a JSON instruction set. Here is an example that extracts the year from the above dates:


  [
    {
      "op": "core/text-transform",
      "description": "Text transform on cells in column Date using expression grel:value.toDate()",
      "engineConfig": {
        "facets": [],
        "mode": "row-based"
      },
      "columnName": "Date",
      "expression": "grel:value.toDate()",
      "onError": "set-to-blank",
      "repeat": false,
      "repeatCount": 10
    },
    {
      "op": "core/text-transform",
      "description": "Text transform on cells in column Date using expression grel:value.datePart(\"year\")+1",
      "engineConfig": {
        "facets": [],
        "mode": "row-based"
      },
      "columnName": "Date",
      "expression": "grel:value.datePart(\"year\")",
      "onError": "set-to-blank",
      "repeat": false,
      "repeatCount": 10
    }
  ]

You can use this gem to apply the operation set to the raw data from ruby. You will need to have Google Refine running on your local computer, or specify an external address (see source):

  
    prj = Refine.new('date cleanup', 'dates.txt')
    prj.apply_operations('operations.json')
    puts prj.export_rows('csv')
    prj.delete_project
  

Which outputs:

  
    Date
    2001
    2002
    2010
  

Copyright

Copyright © 2011 David Huynh and Max Ogden. See LICENSE for details.

About

Ruby client library for controlling Google Refine

http://code.google.com/p/google-refine/

License:MIT License


Languages

Language:Ruby 100.0%