| 1 |
require 'test/unit' |
| 2 |
require 'rdf/redland' |
| 3 |
|
| 4 |
class TestParser < Test::Unit::TestCase |
| 5 |
include Redland |
| 6 |
|
| 7 |
def setup |
| 8 |
world = $world |
| 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 |
| 12 |
<?xml version="1.0"?> |
| 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"> |
| 18 |
|
| 19 |
<foaf:Person> |
| 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:[email protected]" /> |
| 25 |
<foaf:phone>202-646-2352</foaf:phone> |
| 26 |
<worksFor rdf:resource="http://www.faa.gov/people#NISC" /> |
| 27 |
</foaf:Person> |
| 28 |
|
| 29 |
<foaf:Person> |
| 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:[email protected]" /> |
| 35 |
|
| 36 |
</foaf:Person> |
| 37 |
|
| 38 |
<foaf:Person> |
| 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:[email protected]" /> |
| 44 |
</foaf:Person> |
| 45 |
|
| 46 |
</rdf:RDF> |
| 47 |
|
| 48 |
EOF |
| 49 |
|
| 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:[email protected]> . |
| 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:[email protected]> . |
| 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:[email protected]> . |
| 71 |
TRIPLES |
| 72 |
|
| 73 |
end |
| 74 |
|
| 75 |
def test_parse |
| 76 |
model = Model.new() |
| 77 |
foaf = Namespace.new("http://xmlns.com/foaf/0.1/") |
| 78 |
faa = Namespace.new("http://http://www.faa.gov/ontology/people#") |
| 79 |
parser = Parser.new() |
| 80 |
parser.parse_into_model(model,"file:./ical.rdf") |
| 81 |
|
| 82 |
end |
| 83 |
|
| 84 |
def test_stream |
| 85 |
parser = Parser.new() |
| 86 |
model = Model.new() |
| 87 |
parser.parse_as_stream("file:./ical.rdf"){|s| model.add_statement(s)} |
| 88 |
end |
| 89 |
|
| 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')) |
| 94 |
parser = Parser.new() |
| 95 |
parser.parse_into_model(model,"file:./ical.rdf",nil,context) |
| 96 |
contexts = model.contexts |
| 97 |
assert_equal(1,contexts.size) |
| 98 |
assert_equal(contexts[0],Node.new(Uri.new('http://www.faa.gov'))) |
| 99 |
end |
| 100 |
|
| 101 |
def check_foaf_model(model) |
| 102 |
jack = model.subject(@foaf['mbox'],Node.new(:uri_string=>'mailto:[email protected]')) |
| 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) |
| 106 |
end |
| 107 |
|
| 108 |
def test_parse_string_into_model |
| 109 |
model = Model.new() |
| 110 |
parser = Parser.new() |
| 111 |
parser.parse_string_into_model(model,@data_rdf_string,'http://xml.com') |
| 112 |
check_foaf_model(model) |
| 113 |
end |
| 114 |
|
| 115 |
def test_parse_string_into_model_from_triples |
| 116 |
model = Model.new() |
| 117 |
parser = Parser.ntriples() |
| 118 |
parser.parse_string_into_model(model,@data_triples_string,'http://xml.com') |
| 119 |
check_foaf_model(model) |
| 120 |
end |
| 121 |
|
| 122 |
def test_parse_string_as_stream |
| 123 |
model = Model.new() |
| 124 |
parser = Parser.new() |
| 125 |
parser.parse_string_as_stream(@data_rdf_string,'http://xml.com'){|s| model.add_statement(s)} |
| 126 |
check_foaf_model(model) |
| 127 |
end |
| 128 |
|
| 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) |
| 132 |
end |
| 133 |
|
| 134 |
def no_test_string_smush |
| 135 |
model = Model.new() |
| 136 |
dom = BNode.new('dom') |
| 137 |
model.add(dom,@foaf['mbox'],Node.new(:uri_string=>'mailto:[email protected]')) |
| 138 |
model.add(dom,@foaf['name'],'Dominic Sisneros') |
| 139 |
|
| 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) |
| 145 |
end |
| 146 |
|
| 147 |
def test_file_smush() |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
model = Model.new() |
| 154 |
dom = BNode.new('dom') |
| 155 |
model.add(dom,@foaf['mbox'],Node.new(:uri_string=>'mailto:[email protected]')) |
| 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 |
|
| 162 |
end |
| 163 |
end |