1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
use Test::More;
use Test::Exception;
use strict;
use warnings;
no warnings 'redefine';
use RDF::Trine qw(iri);
my $data = <<'END';
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/StatesOfGermany> .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "\u30D9\u30EB\u30EA\u30F3"@ja .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "\u67CF\u6797"@zh .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlino"@it .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlin"@de .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlim"@pt .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlin"@fr .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlin"@en .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berl\u00EDn"@es .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlin"@pl .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlin"@sv .
<http://dbpedia.org/resource/Berlin> <http://www.w3.org/2000/01/rdf-schema#label> "Berlijn"@nl .
END
my $parser = RDF::Trine::Parser->new('ntriples');
my $store = RDF::Trine::Store::Memory->new();
my $model = RDF::Trine::Model->new($store);
$parser->parse_into_model("http://dbpedia.org/resource/Berlin", $data, $model);
is($model->size, 12, 'expected model size');
{
my $lstore = RDF::Trine::Store::LanguagePreference->new( $store, {} );
my $lmodel = RDF::Trine::Model->new($lstore);
is($lmodel->size, 2, 'expected language model size');
my $iter = $lstore->get_statements(undef, iri('http://www.w3.org/2000/01/rdf-schema#label'), undef);
my $count = 0;
while (my $st = $iter->next) {
my $o = $st->object;
is($o->literal_value_language, 'en', 'Accept-Language: ');
$count++;
}
is($count, 1, 'expected count');
}
{
my $lstore = RDF::Trine::Store::LanguagePreference->new( $store, { 'en' => 1.0 } );
my $lmodel = RDF::Trine::Model->new($lstore);
my $iter = $lstore->get_statements(undef, iri('http://www.w3.org/2000/01/rdf-schema#label'), undef);
my $count = 0;
while (my $st = $iter->next) {
my $o = $st->object;
is($o->literal_value_language, 'en', 'Accept-Language: en;q=1.0');
$count++;
}
is($count, 1, 'expected count');
}
{
my $lstore = RDF::Trine::Store::LanguagePreference->new( $store, { 'en' => 0.9, 'ja' => 1.0 } );
my $lmodel = RDF::Trine::Model->new($lstore);
my $iter = $lstore->get_statements(undef, iri('http://www.w3.org/2000/01/rdf-schema#label'), undef);
my $count = 0;
while (my $st = $iter->next) {
my $o = $st->object;
is($o->literal_value_language, 'ja', 'Accept-Language: en;q=0.9, ja;q=1.0');
$count++;
}
is($count, 1, 'expected count');
}
done_testing();
|