Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 48 lines (32 sloc) 1.25 kB
dd663b0 @gigasquid example 6
gigasquid authored
1 require 'javalib/jena-2.6.4.jar'
2 require 'javalib/icu4j-3.4.4.jar'
3 require 'javalib/iri-0.8.jar'
4 require 'javalib/log4j-1.2.13.jar'
5 require 'javalib/slf4j-api-1.5.8.jar'
6 require 'javalib/slf4j-log4j12-1.5.8.jar'
7 require 'javalib/xercesImpl-2.7.1.jar'
8 require 'java'
9
10 java_import 'com.hp.hpl.jena.rdf.model.ModelFactory'
11 java_import 'com.hp.hpl.jena.util.FileManager'
12 java_import 'com.hp.hpl.jena.vocabulary.VCARD'
13 java_import 'java.io.InputStream'
14
476a5ad @gigasquid Cleaning up example 6
gigasquid authored
15 #Tutorial navigating a model
dd663b0 @gigasquid example 6
gigasquid authored
16
476a5ad @gigasquid Cleaning up example 6
gigasquid authored
17 john_smith_uri = "http://somewhere/JohnSmith/"
dd663b0 @gigasquid example 6
gigasquid authored
18 #Creating a model
476a5ad @gigasquid Cleaning up example 6
gigasquid authored
19 model = ModelFactory.create_default_model
dd663b0 @gigasquid example 6
gigasquid authored
20
21 #Finding the input file using the Jena File Manager
22 input_file = FileManager.get.open "sample_input.rdf"
23
24 #read the RDF/XML file
476a5ad @gigasquid Cleaning up example 6
gigasquid authored
25 model.read(input_file, nil)
dd663b0 @gigasquid example 6
gigasquid authored
26
27 #Retreive the john_smith vcard from the model and properties
476a5ad @gigasquid Cleaning up example 6
gigasquid authored
28 vcard = model.get_resource(john_smith_uri)
dd663b0 @gigasquid example 6
gigasquid authored
29 name = vcard.get_required_property(VCARD::N).get_object
30 full_name = vcard.get_required_property(VCARD::FN).get_string;
31
32 #Add nicknames to the vcard
33 vcard.add_property(VCARD::NICKNAME, "Smithy")
34 vcard.add_property(VCARD::NICKNAME, "Adman")
35
36 puts "The Nicknames of #{full_name} are"
37 iter = vcard.list_properties VCARD::NICKNAME
38 while iter.has_next
39 puts iter.next_statement.get_object.to_s
40 end
41
42
43
44
45
46
47
Something went wrong with that request. Please try again.