Skip to content

Commit

Permalink
Cleaning up example 8
Browse files Browse the repository at this point in the history
  • Loading branch information
gigasquid committed Jul 7, 2011
1 parent 9b4f1ce commit 0f75df0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 6 additions & 0 deletions example_1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
java_import 'com.hp.hpl.jena.rdf.model.ModelFactory'

#Tutorial 1 Creating a Simple Model

#creating the model
model = ModelFactory.create_default_model

#creating the resource
person_uri = "http://somewhere/JohnSmith"
full_name = "John Smith"
john_smith = model.create_resource(person_uri)

#adding property to resource
john_smith.add_property(VCARD::FN, full_name)
model.write(java.lang.System::out)

Expand Down
20 changes: 9 additions & 11 deletions example_8.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
require 'javalib/jena-2.6.4.jar'
require 'javalib/arq-2.8.7.jar'
require 'javalib/icu4j-3.4.4.jar'
require 'javalib/iri-0.8.jar'
require 'javalib/log4j-1.2.13.jar'
require 'javalib/lucene-core-2.3.1.jar'
require 'javalib/slf4j-api-1.5.8.jar'
require 'javalib/slf4j-log4j12-1.5.8.jar'
require 'javalib/stax-api-1.0.1.jar'
require 'javalib/wstx-asl-3.2.9.jar'
require 'javalib/xercesImpl-2.7.1.jar'
require 'java'

Expand All @@ -17,28 +13,30 @@
java_import 'com.hp.hpl.jena.vocabulary.VCARD'
java_import 'java.io.InputStream'

#Tutorial 8 - demonstrate Selector methods

#Creating a model
m = ModelFactory.create_default_model
model = ModelFactory.create_default_model

#Finding the input file using the Jena File Manager
input_file = FileManager.get.open "sample_input.rdf"

#read the RDF/XML file
m.read(input_file, nil)
model.read(input_file, nil)

#select all the resources with a VCARD.FN property
iter = m.list_resources_with_property VCARD::FN
iter = model.list_resources_with_property VCARD::FN
puts "The database contains vcards for:"
while iter.has_next
puts iter.next_resource.get_required_property(VCARD::FN).get_string
puts iter.next_resource.get_required_property(VCARD::FN).string
end

#select all the resources with a VCARD.FN property whose value ends
#with Smith

class MySelector < SimpleSelector
def selects(statement)
if statement.get_string.include?("Smith")
if statement.string.include?("Smith")
return true
else
return false
Expand All @@ -49,10 +47,10 @@ def selects(statement)

selector = MySelector.new(nil, VCARD::FN, nil)

iter = m.list_statements(selector)
iter = model.list_statements(selector)
puts "When using a selector for Smith we get:"
while iter.has_next
puts iter.next_statement.get_string
puts iter.next_statement.string
end


Expand Down

0 comments on commit 0f75df0

Please sign in to comment.