Search code examples
linked-datad2rq

Cannot create blank nodes from D2RQ mapping


I have one table (FCT_POPULATION) with the following structure, representing a quantity of a range over the years for a single city. So, in the same year, I have two quantities, varying according to a range (ids 1 or 2):

CITY_ID | YEAR | RANGE_ID | QTY
-------------------------------
1100015 | 2021 | 1        | 134
1100015 | 2021 | 2        | 221
1100015 | 2022 | 1        | 158
1100015 | 2022 | 2        | 243

Since they are multiple measurements of the same city over the years, I would like to create an RDF structure like this, with a list of blank nodes representing the tuple (year, range, quantity) for each city:

<http://localhost:2020/resource/populacao/1100015/2021> a db:Population ;
      db:indicator
              [ :year 2021, :range 1, :quantity 134] ;
      db:indicator
              [ :year 2021, :range 2, :quantity 221] .

My mapping file is like this:

# Table FCT_POPULATION
map:Population a d2rq:ClassMap;
    d2rq:dataStorage map:database;
    d2rq:uriPattern "population/@@FCT_POPULATION.CITY_ID@@/@@FCT_POPULATION.YEAR@@";
    d2rq:class :Population;

map:BN_Range_Year_QTY a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:Population;
    d2rq:property :indicator;
    d2rq:refersToClassMap map:Range_Year_QTY;
    .

map:Range_Year_QTY a d2rq:ClassMap;
    d2rq:dataStorage map:database; #database connection is ok.
    d2rq:bNodeIdColumns "FCT_POPULATION.YEAR,FCT_POPULATION.RANGE_ID,FCT_POPULATION.QTY";
    .
map:quantity a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:Range_Year_QTY ;
    d2rq:property :quantity;  
    d2rq:column "FCT_POPULATION.QTY";
    .
map:ano a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:Range_Year_QTY ;
    d2rq:property :year;
    d2rq:column "FCT_POPULATION.YEAR";
.
map:faixa a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:Range_Year_QTY ;
    d2rq:property :range;
    d2rq:column "FCT_POPULATION.RANGE_ID";
.

It parses ok, but when I try to resolve a specific URI using "http://localhost:2020/data/population/1100015/2014" the following is returned with "blank" blank nodes:

<http://localhost:2020/resource/populacao/1100015/2014>
      a       db:Population ;
      db:indicator
              [] ;
      db:indicator
              [] ;

Any suggestions?

I am using d2rq v0.8.1 and PostgreSQL 14.2(x64) Windows 8.1, command line: d2r-server mapping.ttl


Solution

  • resolving an URI in d2rq is based on sparql describe. you can see result entering in the form which is availabe by url http://localhost:2020/snorql/

    DESCRIBE <http://localhost:2020/resource/populacao/1100015/2014>
    

    and there is no values you need in the results too. that's why blank nodes aren't available through http resolving

    but your mapping is right and you can see it for example if try to dump you data using

    dump-rdf  -f ttl  -o data.ttl mapping.ttl
    

    all your data is in place so you can query them as you need