Pass prefix definitions from data and query parsing to results serialization.
Gregory Todd Williams
8 years ago
8 | 8 | use Attean; |
9 | 9 | use Attean::RDF; |
10 | 10 | use Attean::SimpleQueryEvaluator; |
11 | use AtteanX::RDFQueryTranslator; | |
12 | 11 | use RDF::Query; |
13 | 12 | use Data::Dumper; |
14 | 13 | use Getopt::Long; |
58 | 57 | my $model = Attean::MutableQuadModel->new( store => $store ); |
59 | 58 | my $graph = Attean::IRI->new('http://example.org/graph'); |
60 | 59 | |
60 | my $map = URI::NamespaceMap->new(); | |
61 | 61 | while (my $data = shift(@ARGV)) { |
62 | 62 | my $base = Attean::IRI->new('file://' . File::Spec->rel2abs($data)); |
63 | 63 | open(my $fh, '<:encoding(UTF-8)', $data); |
64 | 64 | warn "Parsing data from $data...\n" if ($verbose); |
65 | 65 | my $pclass = Attean->get_parser( filename => $data ) // 'AtteanX::Parser::Turtle'; |
66 | my $parser = $pclass->new(base => $base); | |
66 | my $parser = $pclass->new(base => $base, namespaces => $map); | |
67 | 67 | my $iter = $parser->parse_iter_from_io($fh); |
68 | 68 | my $quads = $iter->as_quads($graph); |
69 | 69 | $model->add_iter($quads); |
78 | 78 | |
79 | 79 | warn "Parsing query...\n" if ($verbose); |
80 | 80 | my $base = Attean::IRI->new('file://' . File::Spec->rel2abs($qfile)); |
81 | my $s = AtteanX::Parser::SPARQL->new(base => $base); | |
81 | my $s = AtteanX::Parser::SPARQL->new(base => $base, namespaces => $map); | |
82 | 82 | open(my $fh, '<:utf8', $qfile) or die $!; |
83 | 83 | my $algebra; |
84 | 84 | eval { |
113 | 113 | my $count = 1; |
114 | 114 | my $class = Attean->get_serializer($out_format); |
115 | 115 | if ($out_format and $class) { |
116 | my $s = $class->new(); | |
116 | my $s = $class->new(namespaces => $map); | |
117 | 117 | $s->serialize_iter_to_io(\*STDOUT, $iter); |
118 | 118 | } else { |
119 | 119 | while (my $r = $iter->next) { |