项目作者: apache

项目描述 :
PredictionIO Ruby SDK
高级语言: Ruby
项目地址: git://github.com/apache/predictionio-sdk-ruby.git
创建时间: 2013-02-01T13:29:10Z
项目社区:https://github.com/apache/predictionio-sdk-ruby

开源协议:Apache License 2.0

下载


Apache PredictionIO Ruby SDK

Build Status
Gem Version

The Ruby SDK provides a convenient wrapper for PredictionIO Event Server API and
Engine API. It allows you to quickly record your users’ behavior and retrieve
personalized predictions for them.

Documentation

Full Ruby SDK documentation can be found here.

Please see the PredictionIO App Integration
Overview
to
understand how the SDK can be used to integrate PredictionIO Event Server and
Engine with your application.

Installation

Ruby 2+ required!

The module is published to RubyGems and
can be installed directly by:

  1. gem install predictionio

Or using Bundler with:

  1. gem 'predictionio', '0.12.1'

Sending Events to Event Server

Please refer to Event Server
documentation
for
event format and how the data can be collected from your app.

Instantiate Event Client and connect to PredictionIO Event Server

  1. require 'predictionio'
  2. # Define environment variables.
  3. ENV['PIO_THREADS'] = '50' # For async requests.
  4. ENV['PIO_EVENT_SERVER_URL'] = 'http://localhost:7070'
  5. ENV['PIO_ACCESS_KEY'] = 'YOUR_ACCESS_KEY' # Find your access key with: `$ pio app list`.
  6. # Create PredictionIO event client.
  7. client = PredictionIO::EventClient.new(ENV['PIO_ACCESS_KEY'], ENV['PIO_EVENT_SERVER_URL'], Integer(ENV['PIO_THREADS']))

Create a $set user event and send it to Event Server

  1. client.create_event(
  2. '$set',
  3. 'user',
  4. user_id
  5. )

Create a $set item event and send it to Event Server

  1. client.create_event(
  2. '$set',
  3. 'item',
  4. item_id,
  5. { 'properties' => { 'categories' => ['Category 1', 'Category 2'] } }
  6. )

Create a $set item event and send it to Event Server to specific channel

NOTE: channels are supported in PIO version >= 0.9.2 only. Channel must be created first.

  1. client.create_event(
  2. '$set',
  3. 'item',
  4. item_id,
  5. { 'properties' => { 'categories' => ['Category 1', 'Category 2'], 'channel' => 'test-channel'} }
  6. )

Create a user ‘rate’ item event and send it to Event Server

  1. client.create_event(
  2. 'rate',
  3. 'user',
  4. user_id, {
  5. 'targetEntityType' => 'item',
  6. 'targetEntityId' => item_id,
  7. 'properties' => { 'rating' => 10 }
  8. }
  9. )

Asynchronous request

To send an async request, simply use the acreate_event method instead of
create_event. Be aware that the asynchronous method does not throw errors.
It’s best to use the synchronous method when first getting started.

Query PredictionIO Engine

Connect to the Engine:

  1. # Define environmental variables.
  2. ENV['PIO_ENGINE_URL'] = 'http://localhost:8000'
  3. # Create PredictionIO engine client.
  4. client = PredictionIO::EngineClient.new(ENV['PIO_ENGINE_URL'])

Send a prediction query to the engine and get the predicted result:

  1. # Get 5 recommendations for items similar to 10, 20, 30.
  2. response = client.send_query(items: [10, 20, 30], num: 5)

Mailing List

Please use the Apache mailing lists. Subscription instructions are
here.

Issue Tracker

Use the Apache JIRA, and file any
issues under the Ruby SDK component.

Contributing

Please follow these
instructions.

License

Apache License 2.0.