Skip to content
This repository

d2rq:condition not being applied at all !! #172

Open
domguard opened this Issue June 19, 2012 · 3 comments

2 participants

Dominique Guardiola Richard Cyganiak
Dominique Guardiola

This is a cleaner version of the bug described in issue #144 that we're seeing everywhere
It's also a part of the bug described in the issue #171

I'm just trying to add a property given a dr2q:condition, out of the classic "is not null" condition
If you try the above example, you'll see that resource 2 gets the property even if does not satisfies the condition

You can verify this via SNORQL or via the linked data interface,

Am I missing something here about d2rq:condition usage, or is it a bug ?

Here is some simple data :

CREATE TABLE "data" (
    "id" int2 NOT NULL,
    "category" varchar(20) NOT NULL,
    "value" varchar(20) NOT NULL

)
INSERT INTO "data" VALUES ('1', '04 78 56 89 56', 'tel');
INSERT INTO "data" VALUES ('2', 'bob@test.com', 'email');

Then mapping used (just change your db credentials) :

@prefix map: <file:/d2r/mapping.ttl#> .
@prefix db: <> .
@prefix vocab: <http://localhost:2020/vocab/resource/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
@prefix jdbc: <http://d2rq.org/terms/jdbc/> .
@prefix d2r: <http://sites.wiwiss.fu-berlin.de/suhl/bizer/d2r-server/config.rdf#> .
@prefix ess:  <http://ns.economie-solidaire.fr/ess#> .
@prefix v: <http://www.w3.org/2006/vcard/ns#> .

<> a d2r:Server;
    rdfs:label "Test";
    d2r:port 2020;
    d2r:baseURI <http://localhost:2020/>;
    d2r:autoReloadMapping true;
    d2r:limitPerClassMap false;   # to display everything within the interfac, default is 50
    .

map:database a d2rq:Database;
    d2rq:jdbcDriver "org.postgresql.Driver";
    d2rq:jdbcDSN "jdbc:postgresql://localhost:5432/d2r_test";
    d2rq:username "postgres";
    d2rq:password "xxxxx";
    .

# A contact class is created if value is not empty
map:contact a d2rq:ClassMap;
    d2rq:dataStorage map:database;
    d2rq:uriPattern "contact/@@data.id@@/";
    d2rq:class ess:Contact;
    d2rq:condition "data.value <> ''"
    .
map:contact_value a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:contact;
    d2rq:property rdf:value;
    d2rq:column "data.value";
    .   

# Another RDF type is added upon a condition based on the 'category' db field    
map:tel_type a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:contact;
    d2rq:property rdf:type;
    d2rq:constantValue v:Tel;
    d2rq:condition "data.category = 'tel'";
    .

The fact that the conditional property is rdf:type is not important, it happens with any property

Trying to add aliases in the propertyBridge declaration like in :

map:tel_type a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:contact;
    d2rq:property rdf:type;
    d2rq:constantValue v:Tel;
    d2rq:alias "data AS data_alias";
    d2rq:condition "data_alias.category = 'tel'";
    .

...does not solve the problem.
Rather it adds another errors, the repetition of the rdf:type triples in the XML (not turtle) dump and SPARQL store (but this can be discussed later)

Thanks for your help...

Dominique Guardiola

In other contexts, d2rq:condition works as expected.
For example, we use the same pattern (an additional) class but with an additional d2rq:join statement, it works :

map:exchange_method_gift a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:exchange;
    d2rq:property rdf:type;
    d2rq:constantValue ess:Gift;
    d2rq:alias "coop_local_exchange_methods AS exchange_method_Gift";
    d2rq:condition "exchange_method_Gift.exchangemethod_id = 2";
    d2rq:join "coop_local_exchange.id = exchange_method_Gift.exchange_id";
    .
Richard Cyganiak
Owner
cygri commented June 20, 2012

Thanks for the detailed test case, I will try to work out what's going on.

Dominique Guardiola

Trying to understand the SQL output,
I just removed the first d2rq:condition, the one in the classMap about the blank value to not pollute the query

SELECT 
    ("data"."id" = 2 AND ("data"."category" = 'tel')) AS expre9788344, 
    "data"."value", 
    "data"."id" = 2 AS expr32 
FROM "data" 
WHERE (
    "data"."id" = 2 OR 
    ("data"."id" = 2 AND "data"."value" IS NOT NULL) OR 
    ("data"."id" = 2 AND ("data"."category" = 'tel'))
)

lauching this in PGSQL console, the resulting row shows :

which means that the first expression - that looks as the implementation of the d2rq:condition I'm trying to isolate - was evaluated as "False", which is correct as this row does not have a "tel" category
But the "v:Tel" type is still appended to this resource, so the bug may lie after in the code

I can't interpret the WHERE part :

  • the second line talks about a NOT NULL value, but as I said I had removed this condition (double-checked, strange...)
  • why all these "OR" ? I don't know how D2R treats this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.