Skip to content

Instantly share code, notes, and snippets.

@njh
Created April 30, 2010 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njh/385526 to your computer and use it in GitHub Desktop.
Save njh/385526 to your computer and use it in GitHub Desktop.
Ruby code to build a fake FOAF social network of 20 people and insert it into RedStore
require 'rubygems'
require 'rdf'
require 'rdf/redstore'
require 'spira'
require 'faker'
class Person
include Spira::Resource
type RDF::FOAF.Person
base_uri "http://example.org/example/people"
property :name, :predicate => RDF::FOAF.name, :type => String
property :homepage, :predicate => RDF::FOAF.homepage, :type => RDF::URI
property :phone, :predicate => RDF::FOAF.phone, :type => RDF::URI
property :gender, :predicate => RDF::FOAF.gender, :type => String
property :description, :predicate => RDF::DC.description, :type => String
has_many :knows, :predicate => RDF::FOAF.knows, :type => Person
end
repo = RDF::RedStore::Repository.new('http://localhost:8080/')
Spira.add_repository(:default, repo)
repo.clear!
COUNT = 20
(0..COUNT).each do |n|
person = Person.new(n)
person.name = Faker::Name.name
person.gender = ['male','female'].rand
person.homepage = RDF::URI.parse("http://#{Faker::Internet.domain_name}/#{Faker::Internet.user_name(person.name)}/")
person.phone = RDF::URI.parse("tel:#{Faker.numerify(Faker::PhoneNumber::Formats.first)}")
person.description = Faker::Lorem.paragraph
(0..(rand(5))).each do
person.knows << Person.new(rand(COUNT+1))
end
person.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment