Map a full IRI to a resource in SMS

Is there a way to map a full IRI contained in a column to a resource. I can map it to a literal but I can't map it to a resource.

My relational database looks like this

 geonameid |                 alternatename                 
-----------+-----------------------------------------------
   3038816 | https://en.wikipedia.org/wiki/Xixerella

and I can map to a literal like this

<{geonameid}/>
    gn:wikipediaArticle "{alternatename}";
    sm:map [
        sm:query """
            SELECT geonameid, alternatename FROM alternatename WHERE isolanguage = 'link'
        """;
    ]
.

but what I'd like to do is this

<{geonameid}/>
    gn:wikipediaArticle <{alternatename}>;
    sm:map [
        sm:query """
            SELECT geonameid, alternatename FROM alternatename WHERE isolanguage = 'link'
        """;
    ]
.

but that just puts a colon the front.

:https://en.wikipedia.org/wiki/Xixerella

I've also tried it without the angle backets

<{geonameid}/>
    gn:wikipediaArticle {alternatename};
    sm:map [
        sm:query """
            SELECT geonameid, alternatename FROM alternatename WHERE isolanguage = 'link'
        """;
    ]
.

but that gives me the following error when trying to add the virtual graph

Expected :, found '_' [L36]

I suppose I could strip the http:// off in SQL and add a prefix

prefix h: http://

and I think it should work but it's not the nicest looking thing and I'd have to have two mappings. One for http and another for https assuming it's just these two in there.

1 Like

Do you consider this related to Creating virtual graph when CSV contains legitimate URIs ? You actually provided one response to that.

In my case, I was trying to materialize URIs from CSV, and I think the conclusion was that it was easier to do from relational!

I think it's a little bit different but thanks for the link to the previous issue. It might have something to do with the fact that I have a BASE defined in my mapping.

...nope. I eliminated the BASE and I still have the colon out front.

It looks like the difference is you were getting urn: and url encoding and I'm just getting : with urlencoding

Can you export the mapping as R2RML and see what you get?

The mapping with the angle brackets

<http://sws.geonames.org/isthisworking/{geonameid}/>
  gn:wikipediaArticle <{\"alternatename\"}> ;
    sm:map [
        sm:query """
            SELECT geonameid, alternatename FROM alternatename WHERE isolanguage = 'link'
        """
    ];
.

produces this in r2rml

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix gn: <http://www.geonames.org/ontology#> .
@prefix wgs84_pos: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix sm: <tag:stardog:api:mapping:> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<tag:stardog:api:mapping:generated:mapping-561233221> a rr:TriplesMap ;
    rr:logicalTable [
        rr:sqlQuery """SELECT \"geonameid\", \"alternatename\"
FROM \"public\".\"alternatename\"
WHERE \"isolanguage\" = 'link' AND \"geonameid\" IS NOT NULL AND \"alternatename\" IS NOT NULL"""
    ] ;
    rr:predicateObjectMap [
        rr:predicateMap [
            rr:constant gn:wikipediaArticle
        ] ;
            rr:objectMap [
                rr:template "{\"alternatename\"}" ;
                    rr:termType rr:IRI
            ]
    ] ;
    rr:subjectMap [
        rr:termType rr:IRI ;
            rr:template "http://sws.geonames.org/{\"geonameid\"}{http://sws.geonames.org/}"
    ] .

It looks like the subject template is super odd because I needed to have a trailing slash. Not because I wanted it but because I'm trying to reproduce what geonamed produces in their rdf dumps but oddly it looks like it works when I query it.

That would work as a rr:column instead of template.

ha, I was just about to write that I gave that a try and it works. The odd subject template doesn't load but when I replaced the second template with a slash it works. Looks like a mis translation from SMS to R2RML.

Is there any way to do that in SMS? I'd really rather not use R2RML. SMS is much nicer.

The only hack workaround I can think of is to put http: in the template and do a substring starting at position 5 in your IRIs. We're adding an IRI() cast support to SMS2 and soon the STRDT and STRLANG functions you mentioned so we should have full parity at that point.

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