4
class TestParser < Test::Unit::TestCase
9
@foaf = Namespace.new("http://xmlns.com/foaf/0.1/")
10
@faa = Namespace.new("http://http://www.faa.gov/ontology/people#")
11
@data_rdf_string =<<EOF
13
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
14
xmlns="http://www.faa.gov/ontology/people#"
15
xmlns:site="http://www.faa.gov/ontology/site#"
16
xmlns:foaf="http://xmlns.com/foaf/0.1/"
17
xml:base="http://www.faa.gov/ontology/people">
20
<foaf:name>Pat Richardson</foaf:name>
21
<foaf:title>NISC Program Manager</foaf:title>
22
<foaf:firstName>Pat</foaf:firstName>
23
<foaf:surname>Richardson</foaf:surname>
24
<foaf:mbox rdf:resource="mailto:pat.ctr.richardson@faa.gov" />
25
<foaf:phone>202-646-2352</foaf:phone>
26
<worksFor rdf:resource="http://www.faa.gov/people#NISC" />
30
<foaf:name>Jack Nager</foaf:name>
31
<foaf:title>Director of NAS Implementation Program</foaf:title>
32
<foaf:firstName>Jack</foaf:firstName>
33
<foaf:surname>Nager</foaf:surname>
34
<foaf:mbox rdf:resource="mailto:jack.nager@bogus.com" />
39
<foaf:name>Dominic Sisneros</foaf:name>
40
<foaf:title>Electronic Engineer</foaf:title>
41
<foaf:firstName>Dominic</foaf:firstName>
42
<foaf:surname>Sisneros</foaf:surname>
43
<foaf:mbox rdf:resource="mailto:dominic@bogus.com" />
50
@data_triples_string=<<TRIPLES
51
_:r1081452401r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
52
_:r1081452401r1 <http://xmlns.com/foaf/0.1/name> "Pat Richardson" .
53
_:r1081452401r1 <http://xmlns.com/foaf/0.1/title> "NISC Program Manager" .
54
_:r1081452401r1 <http://xmlns.com/foaf/0.1/firstName> "Pat" .
55
_:r1081452401r1 <http://xmlns.com/foaf/0.1/surname> "Richardson" .
56
_:r1081452401r1 <http://xmlns.com/foaf/0.1/mbox> <mailto:pat.ctr.richardson@bogus.com> .
57
_:r1081452401r1 <http://xmlns.com/foaf/0.1/phone> "202-646-2352" .
58
_:r1081452401r1 <http://www.faa.gov/ontology/people#worksFor> <http://www.faa.gov/people#NISC> .
59
_:r1081452401r2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
60
_:r1081452401r2 <http://xmlns.com/foaf/0.1/name> "Jack Nager" .
61
_:r1081452401r2 <http://xmlns.com/foaf/0.1/title> "Director of NAS Implementation Program" .
62
_:r1081452401r2 <http://xmlns.com/foaf/0.1/firstName> "Jack" .
63
_:r1081452401r2 <http://xmlns.com/foaf/0.1/surname> "Nager" .
64
_:r1081452401r2 <http://xmlns.com/foaf/0.1/mbox> <mailto:jack.nager@bogus.com> .
65
_:r1081452401r3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
66
_:r1081452401r3 <http://xmlns.com/foaf/0.1/name> "Dominic Sisneros" .
67
_:r1081452401r3 <http://xmlns.com/foaf/0.1/title> "Electronic Engineer" .
68
_:r1081452401r3 <http://xmlns.com/foaf/0.1/firstName> "Dominic" .
69
_:r1081452401r3 <http://xmlns.com/foaf/0.1/surname> "Sisneros" .
70
_:r1081452401r3 <http://xmlns.com/foaf/0.1/mbox> <mailto:dominic@bogus.com> .
77
foaf = Namespace.new("http://xmlns.com/foaf/0.1/")
78
faa = Namespace.new("http://http://www.faa.gov/ontology/people#")
80
parser.parse_into_model(model,"file:./ical.rdf")
81
#model.triples(){|s,p,o| puts "#{s}:#{p}:#{o}"}
87
parser.parse_as_stream("file:./ical.rdf"){|s| model.add_statement(s)}
90
def test_parser_with_contexts()
91
store = HashStore.new('bdb','thestore')
92
model = Model.new(store)
93
context = Node.new(Uri.new('http://www.faa.gov'))
95
parser.parse_into_model(model,"file:./ical.rdf",nil,context)
96
contexts = model.contexts
97
assert(1,contexts.size)
98
assert_equal(contexts[0],Node.new(Uri.new('http://www.faa.gov')))
101
def test_foaf_model(model)
102
jack = model.subject(@foaf['mbox'],Node.new(:uri_string=>'mailto:jack.nager@bogus.com'))
103
assert_equal('Jack',model.object(jack,@foaf['firstName']).to_s)
104
assert_equal('Nager',model.object(jack,@foaf['surname']).to_s)
105
assert_equal('Director of NAS Implementation Program', model.object(jack,@foaf['title']).to_s)
108
def test_parse_string_into_model
110
parser = Parser.new()
111
parser.parse_string_into_model(model,@data_rdf_string,'http://xml.com')
112
test_foaf_model(model)
115
def test_parse_string_into_model_from_triples
117
parser = Parser.ntriples()
118
parser.parse_string_into_model(model,@data_triples_string,'http://xml.com')
119
test_foaf_model(model)
122
def test_parse_string_as_stream
124
parser = Parser.new()
125
parser.parse_string_as_stream(@data_rdf_string,'http://xml.com'){|s| model.add_statement(s)}
126
test_foaf_model(model)
129
def smush_tester(model,dom)
130
assert_equal('Electronic Engineer',model.object(dom,@foaf['title']).to_s)
131
assert_equal('Sisneros',model.object(dom,@foaf['surname']).to_s)
134
def no_test_string_smush
136
dom = BNode.new('dom')
137
model.add(dom,@foaf['mbox'],Node.new(:uri_string=>'mailto:dominic@bogus.com'))
138
model.add(dom,@foaf['name'],'Dominic Sisneros')
139
#puts "Dom title before = #{model.object(dom,@foaf['title'])}"
140
assert_nil(model.object(dom,@foaf['title']))
141
parser = Parser.ntriples()
142
parser.add_ident(@foaf['mbox'])
143
parser.smush_string(@data_triples_string,model)
144
smush_tester(model,dom)
147
def test_file_smush()
148
#temp_model = Model.new()
149
#parser = Parser.new()
150
#parser.parse_string_into_model(temp_model,@data_rdf_string,"http://www.faa.gov")
151
#serializer = Serializer.new()
152
#serializer.to_file('triples.rdf',temp_model)
154
dom = BNode.new('dom')
155
model.add(dom,@foaf['mbox'],Node.new(:uri_string=>'mailto:dominic@bogus.com'))
156
model.add(dom,@foaf['name'],'Dominic Sisneros')
157
parser = Parser.new()
158
parser.add_ident(@foaf['mbox'])
159
parser.smush_file(model,'file:./triples.rdf')
160
smush_tester(model,dom)
161
model.statements{|s| puts s}
4
class TestParser < Test::Unit::TestCase
9
@foaf = Namespace.new("http://xmlns.com/foaf/0.1/")
10
@faa = Namespace.new("http://http://www.faa.gov/ontology/people#")
11
@data_rdf_string =<<EOF
13
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
14
xmlns="http://www.faa.gov/ontology/people#"
15
xmlns:site="http://www.faa.gov/ontology/site#"
16
xmlns:foaf="http://xmlns.com/foaf/0.1/"
17
xml:base="http://www.faa.gov/ontology/people">
20
<foaf:name>Pat Richardson</foaf:name>
21
<foaf:title>NISC Program Manager</foaf:title>
22
<foaf:firstName>Pat</foaf:firstName>
23
<foaf:surname>Richardson</foaf:surname>
24
<foaf:mbox rdf:resource="mailto:pat.ctr.richardson@faa.gov" />
25
<foaf:phone>202-646-2352</foaf:phone>
26
<worksFor rdf:resource="http://www.faa.gov/people#NISC" />
30
<foaf:name>Jack Nager</foaf:name>
31
<foaf:title>Director of NAS Implementation Program</foaf:title>
32
<foaf:firstName>Jack</foaf:firstName>
33
<foaf:surname>Nager</foaf:surname>
34
<foaf:mbox rdf:resource="mailto:jack.nager@bogus.com" />
39
<foaf:name>Dominic Sisneros</foaf:name>
40
<foaf:title>Electronic Engineer</foaf:title>
41
<foaf:firstName>Dominic</foaf:firstName>
42
<foaf:surname>Sisneros</foaf:surname>
43
<foaf:mbox rdf:resource="mailto:dominic@bogus.com" />
50
@data_triples_string=<<TRIPLES
51
_:r1081452401r1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
52
_:r1081452401r1 <http://xmlns.com/foaf/0.1/name> "Pat Richardson" .
53
_:r1081452401r1 <http://xmlns.com/foaf/0.1/title> "NISC Program Manager" .
54
_:r1081452401r1 <http://xmlns.com/foaf/0.1/firstName> "Pat" .
55
_:r1081452401r1 <http://xmlns.com/foaf/0.1/surname> "Richardson" .
56
_:r1081452401r1 <http://xmlns.com/foaf/0.1/mbox> <mailto:pat.ctr.richardson@bogus.com> .
57
_:r1081452401r1 <http://xmlns.com/foaf/0.1/phone> "202-646-2352" .
58
_:r1081452401r1 <http://www.faa.gov/ontology/people#worksFor> <http://www.faa.gov/people#NISC> .
59
_:r1081452401r2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
60
_:r1081452401r2 <http://xmlns.com/foaf/0.1/name> "Jack Nager" .
61
_:r1081452401r2 <http://xmlns.com/foaf/0.1/title> "Director of NAS Implementation Program" .
62
_:r1081452401r2 <http://xmlns.com/foaf/0.1/firstName> "Jack" .
63
_:r1081452401r2 <http://xmlns.com/foaf/0.1/surname> "Nager" .
64
_:r1081452401r2 <http://xmlns.com/foaf/0.1/mbox> <mailto:jack.nager@bogus.com> .
65
_:r1081452401r3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
66
_:r1081452401r3 <http://xmlns.com/foaf/0.1/name> "Dominic Sisneros" .
67
_:r1081452401r3 <http://xmlns.com/foaf/0.1/title> "Electronic Engineer" .
68
_:r1081452401r3 <http://xmlns.com/foaf/0.1/firstName> "Dominic" .
69
_:r1081452401r3 <http://xmlns.com/foaf/0.1/surname> "Sisneros" .
70
_:r1081452401r3 <http://xmlns.com/foaf/0.1/mbox> <mailto:dominic@bogus.com> .
77
foaf = Namespace.new("http://xmlns.com/foaf/0.1/")
78
faa = Namespace.new("http://http://www.faa.gov/ontology/people#")
80
parser.parse_into_model(model,"file:./ical.rdf")
81
#model.triples(){|s,p,o| puts "#{s}:#{p}:#{o}"}
87
parser.parse_as_stream("file:./ical.rdf"){|s| model.add_statement(s)}
90
def test_parser_with_contexts()
91
store = HashStore.new('bdb','thestore')
92
model = Model.new(store)
93
context = Node.new(Uri.new('http://www.faa.gov'))
95
parser.parse_into_model(model,"file:./ical.rdf",nil,context)
96
contexts = model.contexts
97
assert(1,contexts.size)
98
assert_equal(contexts[0],Node.new(Uri.new('http://www.faa.gov')))
101
def test_foaf_model(model)
102
jack = model.subject(@foaf['mbox'],Node.new(:uri_string=>'mailto:jack.nager@bogus.com'))
103
assert_equal('Jack',model.object(jack,@foaf['firstName']).to_s)
104
assert_equal('Nager',model.object(jack,@foaf['surname']).to_s)
105
assert_equal('Director of NAS Implementation Program', model.object(jack,@foaf['title']).to_s)
108
def test_parse_string_into_model
110
parser = Parser.new()
111
parser.parse_string_into_model(model,@data_rdf_string,'http://xml.com')
112
test_foaf_model(model)
115
def test_parse_string_into_model_from_triples
117
parser = Parser.ntriples()
118
parser.parse_string_into_model(model,@data_triples_string,'http://xml.com')
119
test_foaf_model(model)
122
def test_parse_string_as_stream
124
parser = Parser.new()
125
parser.parse_string_as_stream(@data_rdf_string,'http://xml.com'){|s| model.add_statement(s)}
126
test_foaf_model(model)
129
def smush_tester(model,dom)
130
assert_equal('Electronic Engineer',model.object(dom,@foaf['title']).to_s)
131
assert_equal('Sisneros',model.object(dom,@foaf['surname']).to_s)
134
def no_test_string_smush
136
dom = BNode.new('dom')
137
model.add(dom,@foaf['mbox'],Node.new(:uri_string=>'mailto:dominic@bogus.com'))
138
model.add(dom,@foaf['name'],'Dominic Sisneros')
139
#puts "Dom title before = #{model.object(dom,@foaf['title'])}"
140
assert_nil(model.object(dom,@foaf['title']))
141
parser = Parser.ntriples()
142
parser.add_ident(@foaf['mbox'])
143
parser.smush_string(@data_triples_string,model)
144
smush_tester(model,dom)
147
def test_file_smush()
148
#temp_model = Model.new()
149
#parser = Parser.new()
150
#parser.parse_string_into_model(temp_model,@data_rdf_string,"http://www.faa.gov")
151
#serializer = Serializer.new()
152
#serializer.to_file('triples.rdf',temp_model)
154
dom = BNode.new('dom')
155
model.add(dom,@foaf['mbox'],Node.new(:uri_string=>'mailto:dominic@bogus.com'))
156
model.add(dom,@foaf['name'],'Dominic Sisneros')
157
parser = Parser.new()
158
parser.add_ident(@foaf['mbox'])
159
parser.smush_file(model,'file:./triples.rdf')
160
smush_tester(model,dom)
161
model.statements{|s| puts s}