Using IF in where part

27 vues
Accéder directement au premier message non lu

Sahar Vahdati

non lue,
29 oct. 2015, 08:25:4029/10/2015
à ta...@googlegroups.com
Hi all,

I am using Tarql and in my CSV files there are cases that I need IF
statement.
For example, I have a cell with two possible values and I want to say
BIND it to vocab1:term1 if the value is value1 and if the value is
value 2 BILD it to vocab2:term2.

Saying:
IF(?case= "value1",
BIND(vocab1:term1 AS ?case),
BIND(vocab2:term2 AS ?case).

I receive error for IF. Encountered "if" "IF" .....

Cheers,

Sahar Vahdati

Richard Cyganiak

non lue,
29 oct. 2015, 09:57:5629/10/2015
à Sahar Vahdati,ta...@googlegroups.com
Do it like this:

BIND (IF(condition, thenValue, elseValue) AS ?targetVariable)

In SPARQL, IF(…) is a function that returns a value, not a statement like in most programming languages. So you can only use IF(…) in places where a value is allowed. For example, in FILTER (…), in the SELECT clause at the top of the query, and—as we’re doing here—in BIND (…).

Best,
Richard
> --
> You received this message because you are subscribed to the Google Groups "Tarql" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tarql+un...@googlegroups.com.
> To post to this group, send an email to ta...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/tarql/56321042.8040200%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

Sahar Vahdati

non lue,
29 oct. 2015, 10:15:4029/10/2015
à Richard Cyganiak,ta...@googlegroups.com
Hi Richard, hi all,

It worked perfectly fine!
Thanks a lot.

one comment to the example1 that you have in http://tarql.github.io/examples/.
this does not work because in the example wring variable name is used, you can see it in the result RDF:
BIND (xsd:integer(?numEmps) AS ?numEmployees)


Let me ask another question that I am struggling with that problem also.
I could not manage to show the URLs with <>  but as string inside "" .
I am doing the mapping in the same way that is done in the example and I wonder why it does not work for me.
 this is what I have in the construct part : ex:webSiteUrl ?Websiteurl;

and the result triple is: <subject><predicate>"http://www.example.org"

Many thanks and regards,

Sahar

Richard Cyganiak

non lue,
29 oct. 2015, 10:37:5129/10/2015
à Sahar Vahdati,ta...@googlegroups.com
To make a URI from a literal, use BIND and the URI function in the WHERE part of the query. For example:

BIND (URI(?someStringVariable) AS ?someURIVariable)

And then use ?someURIVariable in the CONSTRUCT section.

URI is a function that turns a string value into a URI value.

Best,
Richard


Sahar Vahdati

non lue,
29 oct. 2015, 10:47:3029/10/2015
à Richard Cyganiak,ta...@googlegroups.com
Excellent clarification.

Thanks again.

Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message