generate an urn/iri/uri dynamically

倾然丶 夕夏残阳落幕 提交于 2019-12-12 16:16:17

问题


I need to generate dynamically the name of a graph depending on the time. I've tough that some think like

select ?g where { 
    bind(concat("<urn:myNewGraph_",str(now()),">") as ?g)
}

would have done the trick, but with Stardog I get a null result.

If instead I run this

select ?g where { 
    bind(concat("urn:myNewGraph_",str(now())) as ?g)
}

i get urn:myNewGraph_2015-05-28T09:37:11.823Z

Any Ideas?

moreover I'm not sure that even if i can get somehow a string like <urn:myNewGraph_2015-05-28T09:37:11.823Z> would have worked as a valid argument for a graph name as can be seen from this not-working test:

INSERT {graph ?g {<urn:s> <urn:p> <urn:o>}
where { 
    ?g="<rn:myNewGraph_2015-05-28T09:37:11.823Z>"
}

is there a proper way to generate an urn/iri/uri dynamically?


回答1:


Your original query looks correct, and produces a valid result when I execute it using a different SPARQL engine (Sesame), so I guess that you might want to report this to the Stardog developers as a possible bug.

However, to be able to use the value thus obtained it needs to be an actual URI (or IRI) - whereas what you're producing is a literal string.

You need to change two things: first of all, get rid of the enclosing < and > (these brackets are not actually part of the IRI) - so actually your second query is better. Second, use the IRI function to convert your string value to an IRI:

INSERT {GRAPH ?g {<urn:s> <urn:p> <urn:o>} }
WHERE { 
     BIND( IRI(CONCAT("urn:myNewGraph_",STR(NOW()))) as ?g)
}

Not sure it's necessary in your case, but in general you may need to use the ENCODE_FOR_URI function in there somewhere, to make sure that any special characters in your string are properly encoded/escaped before turning it into an IRI.



来源:https://stackoverflow.com/questions/30503255/generate-an-urn-iri-uri-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!