You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Anthony Ramalho <an...@yahoo.com> on 2013/07/23 15:57:59 UTC
Doubt about SPARQL
Hi all,
I'd like to know if somebody knows a way of hiding the prefix from results in SPARQL queries.
If yes, is it possible showing some kind of example?
Thanks for your support,
Anthony Diniz
Re: Doubt about SPARQL
Posted by Andy Seaborne <an...@apache.org>.
See the SPARQL spec for the exact syntax for REPLACE:
REPLACE(str(?YourVariable), '^.*(/|#)', '')
AS assigns a variable so it is setting ?localName. You can not also use
it in the pattern (variables are set once per solution).
You will need to change ?YourVariable.
And "?Desvio rdfs:label ?localName."
Andy
On 23/07/13 18:48, Anthony Ramalho wrote:
> Hi Andy,
>
> I tried this (based on what you suggested):
>
> PREFIX hazop:<http://www.owl-ontologies.com/Ontology1372961464.owl#>
> PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
> SELECT ?No ?Desvio (REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
> WHERE { ?No hazop:hasDeviation ?Desvio.
> ?Desvio rdfs:label ?localName.}
>
> It didn't work and I got this error message:
>
> Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Lexical error at line 1, column 147. Encountered: "(" (40), after : "REPLACE"
> at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:96)
> at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40)
> at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132)
> at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69)
> at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
> at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
> at testesontologia.TestesOntologiaHazop.main(TestesOntologiaHazop.java:91)
>
> Thank you for your help,
>
> Anthony Diniz
>
>
> ________________________________
> From: Andy Seaborne <an...@apache.org>
> To: users@jena.apache.org
> Sent: Tuesday, July 23, 2013 2:03 PM
> Subject: Re: Doubt about SPARQL
>
>
> On 23/07/13 17:53, Anthony Diniz wrote:
>> Thank you, Joshua.
>> My case is the 3rd one. Can you give me an example? I have foo:someIndividual, but I would like just "someIndividual", without having to process the answer as string with Java.
>>
>> Thank you again,
>>
>> Anthony
>
>
> REPLACE(str(?YourVariable), '^.*(/|#)')
>
> will calculate the local part for your example.
>
> SELECT ... ?localName {
> ...
> BIND(REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
> ....
> }
>
>
> or
> SELECT ... (REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
> WHERE
> { ... }
>
>
>>
>> Enviado via iPhone
>>
>> Em 2013-07-23, às 12:24, Joshua TAYLOR <jo...@gmail.com> escreveu:
>>
>>> On Tue, Jul 23, 2013 at 9:57 AM, Anthony Ramalho
>>> <an...@yahoo.com> wrote:
>>>> I'd like to know if somebody knows a way of hiding the prefix from results in SPARQL queries.
>>>> If yes, is it possible showing some kind of example?
>>>
>>> What do you mean by "hiding the prefix"?
>
> And how are you processing the results? Using ResultSetFormatter?
>
>>>
>>>
>>> 1) Are you currently getting results like: foo:someIndividual but you
>>> want <http://foo.com/.../someIndividual>, i.e., you want to to show
>>> the full IRI, and not use a prefix?
>>>
>>> 2) Are you currently getting results like
>>> <http://foo.com/.../someIndividual> and you want to hide the prefix
>>> (of the IRI) "http://foo.com/.../" and show foo:someIndividual
>>> instead?
>>>
>>> 3) Are you currently getting results like
>>> <http://foo.com/.../someIndividual> or foo:someIndividual, and you
>>> want to just have someIndividual instead?
>>>
>>> All three are possible, but they require different approaches.
>>>
>>> //JT
>>> --
>>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Doubt about SPARQL
Posted by Anthony Ramalho <an...@yahoo.com>.
Hi Andy,
I tried this (based on what you suggested):
PREFIX hazop:<http://www.owl-ontologies.com/Ontology1372961464.owl#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT ?No ?Desvio (REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
WHERE { ?No hazop:hasDeviation ?Desvio.
?Desvio rdfs:label ?localName.}
It didn't work and I got this error message:
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Lexical error at line 1, column 147. Encountered: "(" (40), after : "REPLACE"
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:96)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse(ParserSPARQL11.java:40)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:132)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:69)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:28)
at testesontologia.TestesOntologiaHazop.main(TestesOntologiaHazop.java:91)
Thank you for your help,
Anthony Diniz
________________________________
From: Andy Seaborne <an...@apache.org>
To: users@jena.apache.org
Sent: Tuesday, July 23, 2013 2:03 PM
Subject: Re: Doubt about SPARQL
On 23/07/13 17:53, Anthony Diniz wrote:
> Thank you, Joshua.
> My case is the 3rd one. Can you give me an example? I have foo:someIndividual, but I would like just "someIndividual", without having to process the answer as string with Java.
>
> Thank you again,
>
> Anthony
REPLACE(str(?YourVariable), '^.*(/|#)')
will calculate the local part for your example.
SELECT ... ?localName {
...
BIND(REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
....
}
or
SELECT ... (REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
WHERE
{ ... }
>
> Enviado via iPhone
>
> Em 2013-07-23, às 12:24, Joshua TAYLOR <jo...@gmail.com> escreveu:
>
>> On Tue, Jul 23, 2013 at 9:57 AM, Anthony Ramalho
>> <an...@yahoo.com> wrote:
>>> I'd like to know if somebody knows a way of hiding the prefix from results in SPARQL queries.
>>> If yes, is it possible showing some kind of example?
>>
>> What do you mean by "hiding the prefix"?
And how are you processing the results? Using ResultSetFormatter?
>>
>>
>> 1) Are you currently getting results like: foo:someIndividual but you
>> want <http://foo.com/.../someIndividual>, i.e., you want to to show
>> the full IRI, and not use a prefix?
>>
>> 2) Are you currently getting results like
>> <http://foo.com/.../someIndividual> and you want to hide the prefix
>> (of the IRI) "http://foo.com/.../" and show foo:someIndividual
>> instead?
>>
>> 3) Are you currently getting results like
>> <http://foo.com/.../someIndividual> or foo:someIndividual, and you
>> want to just have someIndividual instead?
>>
>> All three are possible, but they require different approaches.
>>
>> //JT
>> --
>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Doubt about SPARQL
Posted by Andy Seaborne <an...@apache.org>.
On 23/07/13 17:53, Anthony Diniz wrote:
> Thank you, Joshua.
> My case is the 3rd one. Can you give me an example? I have foo:someIndividual, but I would like just "someIndividual", without having to process the answer as string with Java.
>
> Thank you again,
>
> Anthony
REPLACE(str(?YourVariable), '^.*(/|#)')
will calculate the local part for your example.
SELECT ... ?localName {
...
BIND(REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
....
}
or
SELECT ... (REPLACE(str(?YourVariable), '^.*(/|#)') AS ?localName)
WHERE
{ ... }
>
> Enviado via iPhone
>
> Em 2013-07-23, às 12:24, Joshua TAYLOR <jo...@gmail.com> escreveu:
>
>> On Tue, Jul 23, 2013 at 9:57 AM, Anthony Ramalho
>> <an...@yahoo.com> wrote:
>>> I'd like to know if somebody knows a way of hiding the prefix from results in SPARQL queries.
>>> If yes, is it possible showing some kind of example?
>>
>> What do you mean by "hiding the prefix"?
And how are you processing the results? Using ResultSetFormatter?
>>
>>
>> 1) Are you currently getting results like: foo:someIndividual but you
>> want <http://foo.com/.../someIndividual>, i.e., you want to to show
>> the full IRI, and not use a prefix?
>>
>> 2) Are you currently getting results like
>> <http://foo.com/.../someIndividual> and you want to hide the prefix
>> (of the IRI) "http://foo.com/.../" and show foo:someIndividual
>> instead?
>>
>> 3) Are you currently getting results like
>> <http://foo.com/.../someIndividual> or foo:someIndividual, and you
>> want to just have someIndividual instead?
>>
>> All three are possible, but they require different approaches.
>>
>> //JT
>> --
>> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Doubt about SPARQL
Posted by Anthony Diniz <an...@yahoo.com>.
Thank you, Joshua.
My case is the 3rd one. Can you give me an example? I have foo:someIndividual, but I would like just "someIndividual", without having to process the answer as string with Java.
Thank you again,
Anthony
Enviado via iPhone
Em 2013-07-23, às 12:24, Joshua TAYLOR <jo...@gmail.com> escreveu:
> On Tue, Jul 23, 2013 at 9:57 AM, Anthony Ramalho
> <an...@yahoo.com> wrote:
>> I'd like to know if somebody knows a way of hiding the prefix from results in SPARQL queries.
>> If yes, is it possible showing some kind of example?
>
> What do you mean by "hiding the prefix"?
>
>
> 1) Are you currently getting results like: foo:someIndividual but you
> want <http://foo.com/.../someIndividual>, i.e., you want to to show
> the full IRI, and not use a prefix?
>
> 2) Are you currently getting results like
> <http://foo.com/.../someIndividual> and you want to hide the prefix
> (of the IRI) "http://foo.com/.../" and show foo:someIndividual
> instead?
>
> 3) Are you currently getting results like
> <http://foo.com/.../someIndividual> or foo:someIndividual, and you
> want to just have someIndividual instead?
>
> All three are possible, but they require different approaches.
>
> //JT
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Doubt about SPARQL
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Tue, Jul 23, 2013 at 9:57 AM, Anthony Ramalho
<an...@yahoo.com> wrote:
> I'd like to know if somebody knows a way of hiding the prefix from results in SPARQL queries.
> If yes, is it possible showing some kind of example?
What do you mean by "hiding the prefix"?
1) Are you currently getting results like: foo:someIndividual but you
want <http://foo.com/.../someIndividual>, i.e., you want to to show
the full IRI, and not use a prefix?
2) Are you currently getting results like
<http://foo.com/.../someIndividual> and you want to hide the prefix
(of the IRI) "http://foo.com/.../" and show foo:someIndividual
instead?
3) Are you currently getting results like
<http://foo.com/.../someIndividual> or foo:someIndividual, and you
want to just have someIndividual instead?
All three are possible, but they require different approaches.
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/