Infer 5 digit zip code triple from a 9 digit zip code

Is it possible to create new triple when such a triple gets added?

address has9Zip "60653-3669"

new triple:

address has5Zip "60653"

If so how do i do that?

A corresponding question:

  • Since I create a graph from CSV - can that be done at import time? That is can ttl mapping use a regex to create such a triple?


You can do it with a rule like

IF {
    ?address :has9Zip ?zip .
    BIND(strbefore(?zip, "-")
} THEN {
    ?address :has5Zip ?zip5 .

If you wanted to materialize it I believe you'd have to write a custom transaction listener. There should be an example in the stardog-examples repo somewhere.

I don't think you can do something that complex in the csv virtual graph mapping. You could import the csv into a relational database like Derby and do the transformation in the sql mapping.

Thanks Zachary,

Glad to see IF/ELSE is now supported. I will give it a try.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.