You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by 이명진 <xm...@gmail.com> on 2014/11/06 08:13:22 UTC

Problem SPARQL query encoding

Hello. My name is Myunjin Lee.

I am testing simple SPARQL query from Korean DBpedia SPARQL
endpoint(http://ko.dbpedia.org/sparql) using Jena.

For that, I implemented simple test code, but I had URI encoding problem of
SPARQL query that has Korean character.

 

My simple query is:

 

        String allSameAsQuery = ""

                       + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"

                       + "SELECT *\n" + "WHERE {\n"

                       + "  <http://ko.dbpedia.org/resource/문절망둑>
owl:sameAs ?x .\n" + "}";

 

And then, to process query, I construct Query object.

 

Query query = QueryFactory.create(allSameAsQuery);

System.out.println(query.toString());

 

Problem is that the query string is encoded when I make a Query object.
Print out result is:

 

PREFIX  owl:  <http://www.w3.org/2002/07/owl#>

 

SELECT  *

WHERE

  { <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
owl:sameAs ?x }

 

So that, I cannot get any owl:sameAs resource.

 

How can I figure out the encoding problem? Or is there any method for my
problem?

Thank for your help.

 

Sincerely yours,

Dr. Myungjin Lee


RE: Problem SPARQL query encoding

Posted by 이명진 <xm...@gmail.com>.
Thank you for your response, Rob Vesse.

I found what my error was caused.

Thanks once again.


-----Original Message-----
From: Rob Vesse [mailto:rvesse@dotnetrdf.org] 
Sent: Thursday, November 06, 2014 8:01 PM
To: users@jena.apache.org
Subject: Re: Problem SPARQL query encoding

How are you compiling and running the code?

If you are using Maven be aware that the compiler plugin defaults to compiling with the platform specific character set and not UTF-8 unless explicitly configured e.g.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<version>3.2</version>
	<configuration>
		<source>1.7</source>
		<target>1.7</target>
		<encoding>UTF-8</encoding>
	</configuration>
</plugin>

Add the above to the <build>/<plugins> section of your POM or edit the existing definition as appropriate.

Note that if this is the case you should be seeing a Warning from Maven about platform specific encoding when you build from the command line.  If you are using a Maven project within Eclipse via m2e then this warning might not be visible anywhere obvious

Rob



On 06/11/2014 10:27, "이명진" <xm...@gmail.com> wrote:

>Thank you for your response, Andy Seaborne.
>
>What happened?
>Did my test code work well?
>But it does not still work in my computer.
>
>My code was developed in Eclipse.
>I checked my Eclipse environment, but my Eclipse project was set UTF-8.
>
>
>-----Original Message-----
>From: Andy Seaborne [mailto:andy@apache.org]
>Sent: Thursday, November 06, 2014 7:16 PM
>To: users@jena.apache.org
>Subject: Re: Problem SPARQL query encoding
>
>Hi there,
>
>I tried you test code from your second message here and it worked for 
>me, getting 9 results.
>
>Your first email was in
>
>Content-Type: text/plain; charset="ks_c_5601-1987"
>
>and displayed correctly so it is wrong for unicode.  I switched to 
>unicode display and it was wrong.
>
>Your second email was
>
>Content-Type: text/plain; charset="UTF-8"
>
>SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.
>
>
>Just to confuse things, when I cut&paste into Eclipse from your 
>charset="ks_c_5601-1987" email, it does get converted to unicode.
>
>My guess is that the environment you wrote the example in is set to be 
>a charset other than unicode.
>
>What environment are you writing your code in?
>
>	Andy
>
>
>On 06/11/14 09:40, Miguel Bento Alves wrote:
>> Hi,
>>
>> you only can get the variables that are in Select clause. Try this 
>>and will work:
>>
>> ….
>> String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT ?x\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + 
>> "}"; ….
>>
>> "SELECT ?x” instead of "SELECT *”
>>
>> Miguel
>>
>>
>>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>>
>>> Thank you for your response.
>>>
>>> My question is that my test code does not work if SPARQL query has 
>>>Korean characters because query string is encoded.
>>> My test code is:
>>>
>>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>>> 		String allSameAsQuery = ""
>>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>> 			+ "SELECT *\n" + "WHERE {\n"
>>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>>> 		Query query = QueryFactory.create(allSameAsQuery);
>>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, 
>>>query);
>>> 		ResultSet results = httpQuery.execSelect();
>>> 		while (results.hasNext()) {
>>> 			QuerySolution solution = results.next();
>>> 			String species = solution.getResource("?x").getURI();
>>> 			System.out.println(species);
>>> 		}
>>>
>>> If you input SPARQL query like below on 
>>>http://ko.dbpedia.org/sparql, you can get 9 resources.
>>>
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>
>>> SELECT  *
>>> WHERE
>>>   { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>>
>>> This query is the same as SPARQL query in my test code.
>>> Thank you.
>>>
>>> Sincerely yours,
>>> Dr. Myungjin Lee
>>>
>>>
>>> -----Original Message-----
>>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>>> Sent: Thursday, November 06, 2014 5:24 PM
>>> To: users@jena.apache.org
>>> Subject: Re: Problem SPARQL query encoding
>>>
>>> Hi Myunjin,
>>>
>>> what you did is not enough. You need to create a QueryExecution and 
>>>create a ResultSet to have a cursor pointing to the results.
>>> See the example below.
>>>
>>> Miguel
>>>
>>>
>>> 	String service = "http://dbpedia.org/sparql";
>>>         String query = "select distinct ?Concept where {[] a 
>>>?Concept} LIMIT 100";
>>>         QueryExecution qe
>>>                 = QueryExecutionFactory.sparqlService(service,
>>> query);
>>>
>>>         ResultSet rs = qe.execSelect();
>>>
>>>         while(rs.hasNext()) {
>>>             QuerySolution qs = rs.next();
>>>             System.out.println("Concept -> 
>>>"+qs.get("Concept").toString());
>>>         }
>>>
>>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>>
>>>> Hello. My name is Myunjin Lee.
>>>>
>>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>>
>>>> For that, I implemented simple test code, but I had URI encoding 
>>>> problem of SPARQL query that has Korean character.
>>>>
>>>>
>>>>
>>>> My simple query is:
>>>>
>>>>
>>>>
>>>>        String allSameAsQuery = ""Myunjin
>>>>
>>>>                       + "PREFIX owl:
>>>><http://www.w3.org/2002/07/owl#>\n"
>>>>
>>>>                       + "SELECT *\n" + "WHERE {\n"
>>>>
>>>>                       + "  <http://ko.dbpedia.org/resource/문절망둑>
>>>> owl:sameAs ?x .\n" + "}";
>>>>
>>>>
>>>>
>>>> And then, to process query, I construct Query object.
>>>>
>>>>
>>>>
>>>> Query query = QueryFactory.create(allSameAsQuery);
>>>>
>>>> System.out.println(query.toString());
>>>>
>>>>
>>>>
>>>> Problem is that the query string is encoded when I make a Query 
>>>>object.
>>>> Print out result is:
>>>>
>>>>
>>>>
>>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>>
>>>>
>>>>
>>>> SELECT  *
>>>>
>>>> WHERE
>>>>
>>>> {
>>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%9
>>>> 1
>>>> >
>>>> owl:sameAs ?x }
>>>>
>>>>
>>>>
>>>> So that, I cannot get any owl:sameAs resource.
>>>>
>>>>
>>>>
>>>> How can I figure out the encoding problem? Or is there any method 
>>>> for my problem?
>>>>
>>>> Thank for your help.
>>>>
>>>>
>>>>
>>>> Sincerely yours,
>>>>
>>>> Dr. Myungjin Lee
>>>>
>>>
>>>
>>
>
>






Re: Problem SPARQL query encoding

Posted by Rob Vesse <rv...@dotnetrdf.org>.
How are you compiling and running the code?

If you are using Maven be aware that the compiler plugin defaults to
compiling with the platform specific character set and not UTF-8 unless
explicitly configured e.g.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<version>3.2</version>
	<configuration>
		<source>1.7</source>
		<target>1.7</target>
		<encoding>UTF-8</encoding>
	</configuration>
</plugin>

Add the above to the <build>/<plugins> section of your POM or edit the
existing definition as appropriate.

Note that if this is the case you should be seeing a Warning from Maven
about platform specific encoding when you build from the command line.  If
you are using a Maven project within Eclipse via m2e then this warning
might not be visible anywhere obvious

Rob



On 06/11/2014 10:27, "이명진" <xm...@gmail.com> wrote:

>Thank you for your response, Andy Seaborne.
>
>What happened?
>Did my test code work well?
>But it does not still work in my computer.
>
>My code was developed in Eclipse.
>I checked my Eclipse environment, but my Eclipse project was set UTF-8.
>
>
>-----Original Message-----
>From: Andy Seaborne [mailto:andy@apache.org]
>Sent: Thursday, November 06, 2014 7:16 PM
>To: users@jena.apache.org
>Subject: Re: Problem SPARQL query encoding
>
>Hi there,
>
>I tried you test code from your second message here and it worked for me,
>getting 9 results.
>
>Your first email was in
>
>Content-Type: text/plain; charset="ks_c_5601-1987"
>
>and displayed correctly so it is wrong for unicode.  I switched to
>unicode display and it was wrong.
>
>Your second email was
>
>Content-Type: text/plain; charset="UTF-8"
>
>SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.
>
>
>Just to confuse things, when I cut&paste into Eclipse from your
>charset="ks_c_5601-1987" email, it does get converted to unicode.
>
>My guess is that the environment you wrote the example in is set to be a
>charset other than unicode.
>
>What environment are you writing your code in?
>
>	Andy
>
>
>On 06/11/14 09:40, Miguel Bento Alves wrote:
>> Hi,
>>
>> you only can get the variables that are in Select clause. Try this and
>>will work:
>>
>> ….
>> String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT ?x\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" +
>> "}"; ….
>>
>> "SELECT ?x” instead of "SELECT *”
>>
>> Miguel
>>
>>
>>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>>
>>> Thank you for your response.
>>>
>>> My question is that my test code does not work if SPARQL query has
>>>Korean characters because query string is encoded.
>>> My test code is:
>>>
>>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>>> 		String allSameAsQuery = ""
>>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>> 			+ "SELECT *\n" + "WHERE {\n"
>>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>>> 		Query query = QueryFactory.create(allSameAsQuery);
>>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint,
>>>query);
>>> 		ResultSet results = httpQuery.execSelect();
>>> 		while (results.hasNext()) {
>>> 			QuerySolution solution = results.next();
>>> 			String species = solution.getResource("?x").getURI();
>>> 			System.out.println(species);
>>> 		}
>>>
>>> If you input SPARQL query like below on http://ko.dbpedia.org/sparql,
>>>you can get 9 resources.
>>>
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>
>>> SELECT  *
>>> WHERE
>>>   { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>>
>>> This query is the same as SPARQL query in my test code.
>>> Thank you.
>>>
>>> Sincerely yours,
>>> Dr. Myungjin Lee
>>>
>>>
>>> -----Original Message-----
>>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>>> Sent: Thursday, November 06, 2014 5:24 PM
>>> To: users@jena.apache.org
>>> Subject: Re: Problem SPARQL query encoding
>>>
>>> Hi Myunjin,
>>>
>>> what you did is not enough. You need to create a QueryExecution and
>>>create a ResultSet to have a cursor pointing to the results.
>>> See the example below.
>>>
>>> Miguel
>>>
>>>
>>> 	String service = "http://dbpedia.org/sparql";
>>>         String query = "select distinct ?Concept where {[] a ?Concept}
>>>LIMIT 100";
>>>         QueryExecution qe
>>>                 = QueryExecutionFactory.sparqlService(service,
>>> query);
>>>
>>>         ResultSet rs = qe.execSelect();
>>>
>>>         while(rs.hasNext()) {
>>>             QuerySolution qs = rs.next();
>>>             System.out.println("Concept ->
>>>"+qs.get("Concept").toString());
>>>         }
>>>
>>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>>
>>>> Hello. My name is Myunjin Lee.
>>>>
>>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>>
>>>> For that, I implemented simple test code, but I had URI encoding
>>>> problem of SPARQL query that has Korean character.
>>>>
>>>>
>>>>
>>>> My simple query is:
>>>>
>>>>
>>>>
>>>>        String allSameAsQuery = ""Myunjin
>>>>
>>>>                       + "PREFIX owl:
>>>><http://www.w3.org/2002/07/owl#>\n"
>>>>
>>>>                       + "SELECT *\n" + "WHERE {\n"
>>>>
>>>>                       + "  <http://ko.dbpedia.org/resource/문절망둑>
>>>> owl:sameAs ?x .\n" + "}";
>>>>
>>>>
>>>>
>>>> And then, to process query, I construct Query object.
>>>>
>>>>
>>>>
>>>> Query query = QueryFactory.create(allSameAsQuery);
>>>>
>>>> System.out.println(query.toString());
>>>>
>>>>
>>>>
>>>> Problem is that the query string is encoded when I make a Query
>>>>object.
>>>> Print out result is:
>>>>
>>>>
>>>>
>>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>>
>>>>
>>>>
>>>> SELECT  *
>>>>
>>>> WHERE
>>>>
>>>> {
>>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91
>>>> >
>>>> owl:sameAs ?x }
>>>>
>>>>
>>>>
>>>> So that, I cannot get any owl:sameAs resource.
>>>>
>>>>
>>>>
>>>> How can I figure out the encoding problem? Or is there any method
>>>> for my problem?
>>>>
>>>> Thank for your help.
>>>>
>>>>
>>>>
>>>> Sincerely yours,
>>>>
>>>> Dr. Myungjin Lee
>>>>
>>>
>>>
>>
>
>





RE: Problem SPARQL query encoding

Posted by 이명진 <xm...@gmail.com>.
Thank you for your responses, Andy Seaborne and Miguel Bento Alves.

My problem was Jena libraries in my project.
I tried it again using Jena 2.12.1, it worked well.

Actually, I re-implemented all of Jena interface to use other triple store instead of TDB and SDB.
Maybe, I missed encoding codes of re-implemented ARQ.

I have new mission to figure out it. :)

Thanks once again.


-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org] 
Sent: Thursday, November 06, 2014 7:39 PM
To: users@jena.apache.org
Subject: Re: Problem SPARQL query encoding

On 06/11/14 10:27, 이명진 wrote:
> Thank you for your response, Andy Seaborne.
>
> What happened?

I got:

http://ca.dbpedia.org/resource/Acanthogobius_flavimanus
http://ceb.dbpedia.org/resource/Acanthogobius_flavimanus
http://es.dbpedia.org/resource/Acanthogobius_flavimanus
http://ja.dbpedia.org/resource/マハゼ
http://nl.dbpedia.org/resource/Acanthogobius_flavimanus
http://sv.dbpedia.org/resource/Acanthogobius_flavimanus
http://war.dbpedia.org/resource/Acanthogobius_flavimanus
http://zh.dbpedia.org/resource/黃鰭刺鰕虎魚
http://www.wikidata.org/entity/Q1073434

> Did my test code work well?

Just fine.

A difference is that the query prints as input, not with %-encoding.

If
<http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
were used, it would be re-encoded with each % as %25.

http://ko.dbpedia.org seems to have the resources in unencoded form.


> But it does not still work in my computer.

Which version of Jena are you using (as far as I can remember, this shouldn't matter).

By the way, my system runs UTF-8 (I use Ubuntu):

LANG=en_GB.utf8



>
> My code was developed in Eclipse.
> I checked my Eclipse environment, but my Eclipse project was set UTF-8.

A useful check is display the file with another text editor.


You could try the query in reverse:

PREFIX owl: <http://www.w3.org/2002/07/owl#> SELECT * WHERE {
   ?x owl:sameAs <http://sv.dbpedia.org/resource/Acanthogobius_flavimanus> .
}

I get:

http://ko.dbpedia.org/resource/문절망둑

	Andy

>
>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Thursday, November 06, 2014 7:16 PM
> To: users@jena.apache.org
> Subject: Re: Problem SPARQL query encoding
>
> Hi there,
>
> I tried you test code from your second message here and it worked for me, getting 9 results.
>
> Your first email was in
>
> Content-Type: text/plain; charset="ks_c_5601-1987"
>
> and displayed correctly so it is wrong for unicode.  I switched to unicode display and it was wrong.
>
> Your second email was
>
> Content-Type: text/plain; charset="UTF-8"
>
> SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.
>
>
> Just to confuse things, when I cut&paste into Eclipse from your charset="ks_c_5601-1987" email, it does get converted to unicode.
>
> My guess is that the environment you wrote the example in is set to be a charset other than unicode.
>
> What environment are you writing your code in?
>
> 	Andy
>
>
> On 06/11/14 09:40, Miguel Bento Alves wrote:
>> Hi,
>>
>> you only can get the variables that are in Select clause. Try this and will work:
>>
>> ….
>> String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT ?x\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + 
>> "}"; ….
>>
>> "SELECT ?x” instead of "SELECT *”
>>
>> Miguel
>>
>>
>>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>>
>>> Thank you for your response.
>>>
>>> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
>>> My test code is:
>>>
>>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>>> 		String allSameAsQuery = ""
>>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>> 			+ "SELECT *\n" + "WHERE {\n"
>>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>>> 		Query query = QueryFactory.create(allSameAsQuery);
>>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
>>> 		ResultSet results = httpQuery.execSelect();
>>> 		while (results.hasNext()) {
>>> 			QuerySolution solution = results.next();
>>> 			String species = solution.getResource("?x").getURI();
>>> 			System.out.println(species);
>>> 		}
>>>
>>> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
>>>
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>
>>> SELECT  *
>>> WHERE
>>>    { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>>
>>> This query is the same as SPARQL query in my test code.
>>> Thank you.
>>>
>>> Sincerely yours,
>>> Dr. Myungjin Lee
>>>
>>>
>>> -----Original Message-----
>>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>>> Sent: Thursday, November 06, 2014 5:24 PM
>>> To: users@jena.apache.org
>>> Subject: Re: Problem SPARQL query encoding
>>>
>>> Hi Myunjin,
>>>
>>> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
>>> See the example below.
>>>
>>> Miguel
>>>
>>>
>>> 	String service = "http://dbpedia.org/sparql";
>>>          String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>>>          QueryExecution qe
>>>                  = QueryExecutionFactory.sparqlService(service,
>>> query);
>>>
>>>          ResultSet rs = qe.execSelect();
>>>
>>>          while(rs.hasNext()) {
>>>              QuerySolution qs = rs.next();
>>>              System.out.println("Concept -> "+qs.get("Concept").toString());
>>>          }
>>>
>>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>>
>>>> Hello. My name is Myunjin Lee.
>>>>
>>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>>
>>>> For that, I implemented simple test code, but I had URI encoding 
>>>> problem of SPARQL query that has Korean character.
>>>>
>>>>
>>>>
>>>> My simple query is:
>>>>
>>>>
>>>>
>>>>         String allSameAsQuery = ""Myunjin
>>>>
>>>>                        + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>>>
>>>>                        + "SELECT *\n" + "WHERE {\n"
>>>>
>>>>                        + "  <http://ko.dbpedia.org/resource/문절망둑>
>>>> owl:sameAs ?x .\n" + "}";
>>>>
>>>>
>>>>
>>>> And then, to process query, I construct Query object.
>>>>
>>>>
>>>>
>>>> Query query = QueryFactory.create(allSameAsQuery);
>>>>
>>>> System.out.println(query.toString());
>>>>
>>>>
>>>>
>>>> Problem is that the query string is encoded when I make a Query object.
>>>> Print out result is:
>>>>
>>>>
>>>>
>>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>>
>>>>
>>>>
>>>> SELECT  *
>>>>
>>>> WHERE
>>>>
>>>> {
>>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%9
>>>> 1
>>>>>
>>>> owl:sameAs ?x }
>>>>
>>>>
>>>>
>>>> So that, I cannot get any owl:sameAs resource.
>>>>
>>>>
>>>>
>>>> How can I figure out the encoding problem? Or is there any method 
>>>> for my problem?
>>>>
>>>> Thank for your help.
>>>>
>>>>
>>>>
>>>> Sincerely yours,
>>>>
>>>> Dr. Myungjin Lee
>>>>
>>>
>>>
>>
>
>



Re: Problem SPARQL query encoding

Posted by Andy Seaborne <an...@apache.org>.
On 06/11/14 10:27, 이명진 wrote:
> Thank you for your response, Andy Seaborne.
>
> What happened?

I got:

http://ca.dbpedia.org/resource/Acanthogobius_flavimanus
http://ceb.dbpedia.org/resource/Acanthogobius_flavimanus
http://es.dbpedia.org/resource/Acanthogobius_flavimanus
http://ja.dbpedia.org/resource/マハゼ
http://nl.dbpedia.org/resource/Acanthogobius_flavimanus
http://sv.dbpedia.org/resource/Acanthogobius_flavimanus
http://war.dbpedia.org/resource/Acanthogobius_flavimanus
http://zh.dbpedia.org/resource/黃鰭刺鰕虎魚
http://www.wikidata.org/entity/Q1073434

> Did my test code work well?

Just fine.

A difference is that the query prints as input, not with %-encoding.

If 
<http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91> 
were used, it would be re-encoded with each % as %25.

http://ko.dbpedia.org seems to have the resources in unencoded form.


> But it does not still work in my computer.

Which version of Jena are you using (as far as I can remember, this 
shouldn't matter).

By the way, my system runs UTF-8 (I use Ubuntu):

LANG=en_GB.utf8



>
> My code was developed in Eclipse.
> I checked my Eclipse environment, but my Eclipse project was set UTF-8.

A useful check is display the file with another text editor.


You could try the query in reverse:

PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT *
WHERE {
   ?x owl:sameAs <http://sv.dbpedia.org/resource/Acanthogobius_flavimanus> .
}

I get:

http://ko.dbpedia.org/resource/문절망둑

	Andy

>
>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Thursday, November 06, 2014 7:16 PM
> To: users@jena.apache.org
> Subject: Re: Problem SPARQL query encoding
>
> Hi there,
>
> I tried you test code from your second message here and it worked for me, getting 9 results.
>
> Your first email was in
>
> Content-Type: text/plain; charset="ks_c_5601-1987"
>
> and displayed correctly so it is wrong for unicode.  I switched to unicode display and it was wrong.
>
> Your second email was
>
> Content-Type: text/plain; charset="UTF-8"
>
> SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.
>
>
> Just to confuse things, when I cut&paste into Eclipse from your charset="ks_c_5601-1987" email, it does get converted to unicode.
>
> My guess is that the environment you wrote the example in is set to be a charset other than unicode.
>
> What environment are you writing your code in?
>
> 	Andy
>
>
> On 06/11/14 09:40, Miguel Bento Alves wrote:
>> Hi,
>>
>> you only can get the variables that are in Select clause. Try this and will work:
>>
>> ….
>> String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT ?x\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" +
>> "}"; ….
>>
>> "SELECT ?x” instead of "SELECT *”
>>
>> Miguel
>>
>>
>>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>>
>>> Thank you for your response.
>>>
>>> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
>>> My test code is:
>>>
>>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>>> 		String allSameAsQuery = ""
>>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>> 			+ "SELECT *\n" + "WHERE {\n"
>>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>>> 		Query query = QueryFactory.create(allSameAsQuery);
>>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
>>> 		ResultSet results = httpQuery.execSelect();
>>> 		while (results.hasNext()) {
>>> 			QuerySolution solution = results.next();
>>> 			String species = solution.getResource("?x").getURI();
>>> 			System.out.println(species);
>>> 		}
>>>
>>> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
>>>
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>
>>> SELECT  *
>>> WHERE
>>>    { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>>
>>> This query is the same as SPARQL query in my test code.
>>> Thank you.
>>>
>>> Sincerely yours,
>>> Dr. Myungjin Lee
>>>
>>>
>>> -----Original Message-----
>>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>>> Sent: Thursday, November 06, 2014 5:24 PM
>>> To: users@jena.apache.org
>>> Subject: Re: Problem SPARQL query encoding
>>>
>>> Hi Myunjin,
>>>
>>> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
>>> See the example below.
>>>
>>> Miguel
>>>
>>>
>>> 	String service = "http://dbpedia.org/sparql";
>>>          String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>>>          QueryExecution qe
>>>                  = QueryExecutionFactory.sparqlService(service,
>>> query);
>>>
>>>          ResultSet rs = qe.execSelect();
>>>
>>>          while(rs.hasNext()) {
>>>              QuerySolution qs = rs.next();
>>>              System.out.println("Concept -> "+qs.get("Concept").toString());
>>>          }
>>>
>>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>>
>>>> Hello. My name is Myunjin Lee.
>>>>
>>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>>
>>>> For that, I implemented simple test code, but I had URI encoding
>>>> problem of SPARQL query that has Korean character.
>>>>
>>>>
>>>>
>>>> My simple query is:
>>>>
>>>>
>>>>
>>>>         String allSameAsQuery = ""Myunjin
>>>>
>>>>                        + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>>>
>>>>                        + "SELECT *\n" + "WHERE {\n"
>>>>
>>>>                        + "  <http://ko.dbpedia.org/resource/문절망둑>
>>>> owl:sameAs ?x .\n" + "}";
>>>>
>>>>
>>>>
>>>> And then, to process query, I construct Query object.
>>>>
>>>>
>>>>
>>>> Query query = QueryFactory.create(allSameAsQuery);
>>>>
>>>> System.out.println(query.toString());
>>>>
>>>>
>>>>
>>>> Problem is that the query string is encoded when I make a Query object.
>>>> Print out result is:
>>>>
>>>>
>>>>
>>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>>
>>>>
>>>>
>>>> SELECT  *
>>>>
>>>> WHERE
>>>>
>>>> {
>>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91
>>>>>
>>>> owl:sameAs ?x }
>>>>
>>>>
>>>>
>>>> So that, I cannot get any owl:sameAs resource.
>>>>
>>>>
>>>>
>>>> How can I figure out the encoding problem? Or is there any method
>>>> for my problem?
>>>>
>>>> Thank for your help.
>>>>
>>>>
>>>>
>>>> Sincerely yours,
>>>>
>>>> Dr. Myungjin Lee
>>>>
>>>
>>>
>>
>
>


RE: Problem SPARQL query encoding

Posted by 이명진 <xm...@gmail.com>.
Thank you for your response, Andy Seaborne.

What happened?
Did my test code work well?
But it does not still work in my computer.

My code was developed in Eclipse.
I checked my Eclipse environment, but my Eclipse project was set UTF-8.


-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org] 
Sent: Thursday, November 06, 2014 7:16 PM
To: users@jena.apache.org
Subject: Re: Problem SPARQL query encoding

Hi there,

I tried you test code from your second message here and it worked for me, getting 9 results.

Your first email was in

Content-Type: text/plain; charset="ks_c_5601-1987"

and displayed correctly so it is wrong for unicode.  I switched to unicode display and it was wrong.

Your second email was

Content-Type: text/plain; charset="UTF-8"

SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.


Just to confuse things, when I cut&paste into Eclipse from your charset="ks_c_5601-1987" email, it does get converted to unicode.

My guess is that the environment you wrote the example in is set to be a charset other than unicode.

What environment are you writing your code in?

	Andy


On 06/11/14 09:40, Miguel Bento Alves wrote:
> Hi,
>
> you only can get the variables that are in Select clause. Try this and will work:
>
> ….
> String allSameAsQuery = ""
> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
> 			+ "SELECT ?x\n" + "WHERE {\n"
> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + 
> "}"; ….
>
> "SELECT ?x” instead of "SELECT *”
>
> Miguel
>
>
>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>
>> Thank you for your response.
>>
>> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
>> My test code is:
>>
>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>> 		String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT *\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>> 		Query query = QueryFactory.create(allSameAsQuery);
>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
>> 		ResultSet results = httpQuery.execSelect();
>> 		while (results.hasNext()) {
>> 			QuerySolution solution = results.next();
>> 			String species = solution.getResource("?x").getURI();
>> 			System.out.println(species);
>> 		}
>>
>> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
>>
>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>
>> SELECT  *
>> WHERE
>>   { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>
>> This query is the same as SPARQL query in my test code.
>> Thank you.
>>
>> Sincerely yours,
>> Dr. Myungjin Lee
>>
>>
>> -----Original Message-----
>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>> Sent: Thursday, November 06, 2014 5:24 PM
>> To: users@jena.apache.org
>> Subject: Re: Problem SPARQL query encoding
>>
>> Hi Myunjin,
>>
>> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
>> See the example below.
>>
>> Miguel
>>
>>
>> 	String service = "http://dbpedia.org/sparql";
>>         String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>>         QueryExecution qe
>>                 = QueryExecutionFactory.sparqlService(service, 
>> query);
>>
>>         ResultSet rs = qe.execSelect();
>>
>>         while(rs.hasNext()) {
>>             QuerySolution qs = rs.next();
>>             System.out.println("Concept -> "+qs.get("Concept").toString());
>>         }
>>
>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>
>>> Hello. My name is Myunjin Lee.
>>>
>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>
>>> For that, I implemented simple test code, but I had URI encoding 
>>> problem of SPARQL query that has Korean character.
>>>
>>>
>>>
>>> My simple query is:
>>>
>>>
>>>
>>>        String allSameAsQuery = ""Myunjin
>>>
>>>                       + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>>
>>>                       + "SELECT *\n" + "WHERE {\n"
>>>
>>>                       + "  <http://ko.dbpedia.org/resource/문절망둑>
>>> owl:sameAs ?x .\n" + "}";
>>>
>>>
>>>
>>> And then, to process query, I construct Query object.
>>>
>>>
>>>
>>> Query query = QueryFactory.create(allSameAsQuery);
>>>
>>> System.out.println(query.toString());
>>>
>>>
>>>
>>> Problem is that the query string is encoded when I make a Query object.
>>> Print out result is:
>>>
>>>
>>>
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>
>>>
>>>
>>> SELECT  *
>>>
>>> WHERE
>>>
>>> {
>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91
>>> >
>>> owl:sameAs ?x }
>>>
>>>
>>>
>>> So that, I cannot get any owl:sameAs resource.
>>>
>>>
>>>
>>> How can I figure out the encoding problem? Or is there any method 
>>> for my problem?
>>>
>>> Thank for your help.
>>>
>>>
>>>
>>> Sincerely yours,
>>>
>>> Dr. Myungjin Lee
>>>
>>
>>
>



Re: Problem SPARQL query encoding

Posted by Miguel Bento Alves <mb...@gmail.com>.
Hi, 

Sorry but in my last mail I gave a wrong information. The command works well. BTW, I also cut-paste the code and worked fine (NetBeans IDE) and I didn’t realize that the problem could be about charset. 

Miguel

> On 06 Nov 2014, at 10:15, Andy Seaborne <an...@apache.org> wrote:
> 
> Hi there,
> 
> I tried you test code from your second message here and it worked for me, getting 9 results.
> 
> Your first email was in
> 
> Content-Type: text/plain; charset="ks_c_5601-1987"
> 
> and displayed correctly so it is wrong for unicode.  I switched to unicode display and it was wrong.
> 
> Your second email was
> 
> Content-Type: text/plain; charset="UTF-8"
> 
> SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.
> 
> 
> Just to confuse things, when I cut&paste into Eclipse from your charset="ks_c_5601-1987" email, it does get converted to unicode.
> 
> My guess is that the environment you wrote the example in is set to be a charset other than unicode.
> 
> What environment are you writing your code in?
> 
> 	Andy
> 
> 
> On 06/11/14 09:40, Miguel Bento Alves wrote:
>> Hi,
>> 
>> you only can get the variables that are in Select clause. Try this and will work:
>> 
>> ….
>> String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT ?x\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>> ….
>> 
>> "SELECT ?x” instead of "SELECT *”
>> 
>> Miguel
>> 
>> 
>>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>> 
>>> Thank you for your response.
>>> 
>>> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
>>> My test code is:
>>> 
>>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>>> 		String allSameAsQuery = ""
>>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>> 			+ "SELECT *\n" + "WHERE {\n"
>>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>>> 		Query query = QueryFactory.create(allSameAsQuery);
>>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
>>> 		ResultSet results = httpQuery.execSelect();
>>> 		while (results.hasNext()) {
>>> 			QuerySolution solution = results.next();
>>> 			String species = solution.getResource("?x").getURI();
>>> 			System.out.println(species);
>>> 		}
>>> 
>>> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
>>> 
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>> 
>>> SELECT  *
>>> WHERE
>>>  { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>> 
>>> This query is the same as SPARQL query in my test code.
>>> Thank you.
>>> 
>>> Sincerely yours,
>>> Dr. Myungjin Lee
>>> 
>>> 
>>> -----Original Message-----
>>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>>> Sent: Thursday, November 06, 2014 5:24 PM
>>> To: users@jena.apache.org
>>> Subject: Re: Problem SPARQL query encoding
>>> 
>>> Hi Myunjin,
>>> 
>>> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
>>> See the example below.
>>> 
>>> Miguel
>>> 
>>> 
>>> 	String service = "http://dbpedia.org/sparql";
>>>        String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>>>        QueryExecution qe
>>>                = QueryExecutionFactory.sparqlService(service, query);
>>> 
>>>        ResultSet rs = qe.execSelect();
>>> 
>>>        while(rs.hasNext()) {
>>>            QuerySolution qs = rs.next();
>>>            System.out.println("Concept -> "+qs.get("Concept").toString());
>>>        }
>>> 
>>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>> 
>>>> Hello. My name is Myunjin Lee.
>>>> 
>>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>> 
>>>> For that, I implemented simple test code, but I had URI encoding
>>>> problem of SPARQL query that has Korean character.
>>>> 
>>>> 
>>>> 
>>>> My simple query is:
>>>> 
>>>> 
>>>> 
>>>>       String allSameAsQuery = ""Myunjin
>>>> 
>>>>                      + "PREFIX owl: <http://www.w3.org/2002/07/owl# <http://www.w3.org/2002/07/owl#>>\n"
>>>> 
>>>>                      + "SELECT *\n" + "WHERE {\n"
>>>> 
>>>>                      + "  <http://ko.dbpedia.org/resource/문절망둑 <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>>
>>>> owl:sameAs ?x .\n" + "}";
>>>> 
>>>> 
>>>> 
>>>> And then, to process query, I construct Query object.
>>>> 
>>>> 
>>>> 
>>>> Query query = QueryFactory.create(allSameAsQuery);
>>>> 
>>>> System.out.println(query.toString());
>>>> 
>>>> 
>>>> 
>>>> Problem is that the query string is encoded when I make a Query object.
>>>> Print out result is:
>>>> 
>>>> 
>>>> 
>>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl# <http://www.w3.org/2002/07/owl#>>
>>>> 
>>>> 
>>>> 
>>>> SELECT  *
>>>> 
>>>> WHERE
>>>> 
>>>> {
>>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91 <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>>
>>>> owl:sameAs ?x }
>>>> 
>>>> 
>>>> 
>>>> So that, I cannot get any owl:sameAs resource.
>>>> 
>>>> 
>>>> 
>>>> How can I figure out the encoding problem? Or is there any method for
>>>> my problem?
>>>> 
>>>> Thank for your help.
>>>> 
>>>> 
>>>> 
>>>> Sincerely yours,
>>>> 
>>>> Dr. Myungjin Lee


Re: Problem SPARQL query encoding

Posted by Andy Seaborne <an...@apache.org>.
Hi there,

I tried you test code from your second message here and it worked for 
me, getting 9 results.

Your first email was in

Content-Type: text/plain; charset="ks_c_5601-1987"

and displayed correctly so it is wrong for unicode.  I switched to 
unicode display and it was wrong.

Your second email was

Content-Type: text/plain; charset="UTF-8"

SPARQL is unicode (UTF-8 specifically).  Miguel's email was UTF-8.


Just to confuse things, when I cut&paste into Eclipse from your 
charset="ks_c_5601-1987" email, it does get converted to unicode.

My guess is that the environment you wrote the example in is set to be a 
charset other than unicode.

What environment are you writing your code in?

	Andy


On 06/11/14 09:40, Miguel Bento Alves wrote:
> Hi,
>
> you only can get the variables that are in Select clause. Try this and will work:
>
> ….
> String allSameAsQuery = ""
> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
> 			+ "SELECT ?x\n" + "WHERE {\n"
> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
> ….
>
> "SELECT ?x” instead of "SELECT *”
>
> Miguel
>
>
>> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
>>
>> Thank you for your response.
>>
>> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
>> My test code is:
>>
>> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
>> 		String allSameAsQuery = ""
>> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 			+ "SELECT *\n" + "WHERE {\n"
>> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
>> 		Query query = QueryFactory.create(allSameAsQuery);
>> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
>> 		ResultSet results = httpQuery.execSelect();
>> 		while (results.hasNext()) {
>> 			QuerySolution solution = results.next();
>> 			String species = solution.getResource("?x").getURI();
>> 			System.out.println(species);
>> 		}
>>
>> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
>>
>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>
>> SELECT  *
>> WHERE
>>   { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
>>
>> This query is the same as SPARQL query in my test code.
>> Thank you.
>>
>> Sincerely yours,
>> Dr. Myungjin Lee
>>
>>
>> -----Original Message-----
>> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
>> Sent: Thursday, November 06, 2014 5:24 PM
>> To: users@jena.apache.org
>> Subject: Re: Problem SPARQL query encoding
>>
>> Hi Myunjin,
>>
>> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
>> See the example below.
>>
>> Miguel
>>
>>
>> 	String service = "http://dbpedia.org/sparql";
>>         String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>>         QueryExecution qe
>>                 = QueryExecutionFactory.sparqlService(service, query);
>>
>>         ResultSet rs = qe.execSelect();
>>
>>         while(rs.hasNext()) {
>>             QuerySolution qs = rs.next();
>>             System.out.println("Concept -> "+qs.get("Concept").toString());
>>         }
>>
>>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>>>
>>> Hello. My name is Myunjin Lee.
>>>
>>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>>>
>>> For that, I implemented simple test code, but I had URI encoding
>>> problem of SPARQL query that has Korean character.
>>>
>>>
>>>
>>> My simple query is:
>>>
>>>
>>>
>>>        String allSameAsQuery = ""Myunjin
>>>
>>>                       + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>>>
>>>                       + "SELECT *\n" + "WHERE {\n"
>>>
>>>                       + "  <http://ko.dbpedia.org/resource/문절망둑>
>>> owl:sameAs ?x .\n" + "}";
>>>
>>>
>>>
>>> And then, to process query, I construct Query object.
>>>
>>>
>>>
>>> Query query = QueryFactory.create(allSameAsQuery);
>>>
>>> System.out.println(query.toString());
>>>
>>>
>>>
>>> Problem is that the query string is encoded when I make a Query object.
>>> Print out result is:
>>>
>>>
>>>
>>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>>>
>>>
>>>
>>> SELECT  *
>>>
>>> WHERE
>>>
>>> {
>>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
>>> owl:sameAs ?x }
>>>
>>>
>>>
>>> So that, I cannot get any owl:sameAs resource.
>>>
>>>
>>>
>>> How can I figure out the encoding problem? Or is there any method for
>>> my problem?
>>>
>>> Thank for your help.
>>>
>>>
>>>
>>> Sincerely yours,
>>>
>>> Dr. Myungjin Lee
>>>
>>
>>
>


RE: Problem SPARQL query encoding

Posted by 이명진 <xm...@gmail.com>.
Thank you for your response.
But your response is nothing to do with me.

* character in SELECT clause means all variables bound in WHERE clause.
So my test query works well on SPARQL endpoint even if I do not use "SELECT ?x" instead of "SELECT *".

Please let me know how to figure out encoding problem when query string contains Korean characters.

Sincerely yours,
Myungjin Lee


-----Original Message-----
From: Miguel Bento Alves [mailto:mbentoalves@gmail.com] 
Sent: Thursday, November 06, 2014 6:41 PM
To: users@jena.apache.org
Subject: Re: Problem SPARQL query encoding

Hi, 

you only can get the variables that are in Select clause. Try this and will work:

….
String allSameAsQuery = ""
			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
			+ "SELECT ?x\n" + "WHERE {\n"
			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}"; ….

"SELECT ?x” instead of "SELECT *”

Miguel


> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
> 
> Thank you for your response.
> 
> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
> My test code is:
> 
> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
> 		String allSameAsQuery = ""
> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
> 			+ "SELECT *\n" + "WHERE {\n"
> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
> 		Query query = QueryFactory.create(allSameAsQuery);
> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
> 		ResultSet results = httpQuery.execSelect();
> 		while (results.hasNext()) {
> 			QuerySolution solution = results.next();
> 			String species = solution.getResource("?x").getURI();
> 			System.out.println(species);
> 		}
> 
> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
> 
> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
> 
> SELECT  *
> WHERE
>  { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
> 
> This query is the same as SPARQL query in my test code.
> Thank you.
> 
> Sincerely yours,
> Dr. Myungjin Lee
> 
> 
> -----Original Message-----
> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com]
> Sent: Thursday, November 06, 2014 5:24 PM
> To: users@jena.apache.org
> Subject: Re: Problem SPARQL query encoding
> 
> Hi Myunjin,
> 
> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
> See the example below. 
> 
> Miguel
> 
> 
> 	String service = "http://dbpedia.org/sparql";
>        String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>        QueryExecution qe 
>                = QueryExecutionFactory.sparqlService(service, query);
> 
>        ResultSet rs = qe.execSelect();
> 
>        while(rs.hasNext()) {
>            QuerySolution qs = rs.next();
>            System.out.println("Concept -> "+qs.get("Concept").toString());
>        }
> 
>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>> 
>> Hello. My name is Myunjin Lee.
>> 
>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>> 
>> For that, I implemented simple test code, but I had URI encoding 
>> problem of SPARQL query that has Korean character.
>> 
>> 
>> 
>> My simple query is:
>> 
>> 
>> 
>>       String allSameAsQuery = ""
>> 
>>                      + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 
>>                      + "SELECT *\n" + "WHERE {\n"
>> 
>>                      + "  <http://ko.dbpedia.org/resource/문절망둑>
>> owl:sameAs ?x .\n" + "}";
>> 
>> 
>> 
>> And then, to process query, I construct Query object.
>> 
>> 
>> 
>> Query query = QueryFactory.create(allSameAsQuery);
>> 
>> System.out.println(query.toString());
>> 
>> 
>> 
>> Problem is that the query string is encoded when I make a Query object.
>> Print out result is:
>> 
>> 
>> 
>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>> 
>> 
>> 
>> SELECT  *
>> 
>> WHERE
>> 
>> {
>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
>> owl:sameAs ?x }
>> 
>> 
>> 
>> So that, I cannot get any owl:sameAs resource.
>> 
>> 
>> 
>> How can I figure out the encoding problem? Or is there any method for 
>> my problem?
>> 
>> Thank for your help.
>> 
>> 
>> 
>> Sincerely yours,
>> 
>> Dr. Myungjin Lee
>> 
> 
> 



Re: Problem SPARQL query encoding

Posted by Miguel Bento Alves <mb...@gmail.com>.
Hi, 

you only can get the variables that are in Select clause. Try this and will work:

….
String allSameAsQuery = ""
			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
			+ "SELECT ?x\n" + "WHERE {\n"
			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
….

"SELECT ?x” instead of "SELECT *”

Miguel


> On 06 Nov 2014, at 09:29, 이명진 <xm...@gmail.com> wrote:
> 
> Thank you for your response.
> 
> My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
> My test code is:
> 
> 		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
> 		String allSameAsQuery = ""
> 			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
> 			+ "SELECT *\n" + "WHERE {\n"
> 			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
> 		Query query = QueryFactory.create(allSameAsQuery);
> 		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
> 		ResultSet results = httpQuery.execSelect();
> 		while (results.hasNext()) {
> 			QuerySolution solution = results.next();
> 			String species = solution.getResource("?x").getURI();
> 			System.out.println(species);
> 		}
> 
> If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.
> 
> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
> 
> SELECT  *
> WHERE
>  { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }
> 
> This query is the same as SPARQL query in my test code.
> Thank you.
> 
> Sincerely yours,
> Dr. Myungjin Lee
> 
> 
> -----Original Message-----
> From: Miguel Bento Alves [mailto:mbentoalves@gmail.com] 
> Sent: Thursday, November 06, 2014 5:24 PM
> To: users@jena.apache.org
> Subject: Re: Problem SPARQL query encoding
> 
> Hi Myunjin,
> 
> what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
> See the example below. 
> 
> Miguel
> 
> 
> 	String service = "http://dbpedia.org/sparql";
>        String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
>        QueryExecution qe 
>                = QueryExecutionFactory.sparqlService(service, query);
> 
>        ResultSet rs = qe.execSelect();
> 
>        while(rs.hasNext()) {
>            QuerySolution qs = rs.next();
>            System.out.println("Concept -> "+qs.get("Concept").toString());
>        }
> 
>> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
>> 
>> Hello. My name is Myunjin Lee.
>> 
>> I am testing simple SPARQL query from Korean DBpedia SPARQL
>> endpoint(http://ko.dbpedia.org/sparql) using Jena.
>> 
>> For that, I implemented simple test code, but I had URI encoding 
>> problem of SPARQL query that has Korean character.
>> 
>> 
>> 
>> My simple query is:
>> 
>> 
>> 
>>       String allSameAsQuery = ""
>> 
>>                      + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
>> 
>>                      + "SELECT *\n" + "WHERE {\n"
>> 
>>                      + "  <http://ko.dbpedia.org/resource/문절망둑>
>> owl:sameAs ?x .\n" + "}";
>> 
>> 
>> 
>> And then, to process query, I construct Query object.
>> 
>> 
>> 
>> Query query = QueryFactory.create(allSameAsQuery);
>> 
>> System.out.println(query.toString());
>> 
>> 
>> 
>> Problem is that the query string is encoded when I make a Query object.
>> Print out result is:
>> 
>> 
>> 
>> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
>> 
>> 
>> 
>> SELECT  *
>> 
>> WHERE
>> 
>> { 
>> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
>> owl:sameAs ?x }
>> 
>> 
>> 
>> So that, I cannot get any owl:sameAs resource.
>> 
>> 
>> 
>> How can I figure out the encoding problem? Or is there any method for 
>> my problem?
>> 
>> Thank for your help.
>> 
>> 
>> 
>> Sincerely yours,
>> 
>> Dr. Myungjin Lee
>> 
> 
> 


RE: Problem SPARQL query encoding

Posted by 이명진 <xm...@gmail.com>.
Thank you for your response.

My question is that my test code does not work if SPARQL query has Korean characters because query string is encoded.
My test code is:

		String dbpediKoEndpoint = "http://ko.dbpedia.org/sparql";
		String allSameAsQuery = ""
			+ "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
			+ "SELECT *\n" + "WHERE {\n"
			+ "  <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x .\n" + "}";
		Query query = QueryFactory.create(allSameAsQuery);
		QueryEngineHTTP httpQuery = new QueryEngineHTTP(dbpediKoEndpoint, query);
		ResultSet results = httpQuery.execSelect();
		while (results.hasNext()) {
			QuerySolution solution = results.next();
			String species = solution.getResource("?x").getURI();
			System.out.println(species);
		}

If you input SPARQL query like below on http://ko.dbpedia.org/sparql, you can get 9 resources.

PREFIX  owl:  <http://www.w3.org/2002/07/owl#>

SELECT  *
WHERE
  { <http://ko.dbpedia.org/resource/문절망둑> owl:sameAs ?x }

This query is the same as SPARQL query in my test code.
Thank you.

Sincerely yours,
Dr. Myungjin Lee


-----Original Message-----
From: Miguel Bento Alves [mailto:mbentoalves@gmail.com] 
Sent: Thursday, November 06, 2014 5:24 PM
To: users@jena.apache.org
Subject: Re: Problem SPARQL query encoding

Hi Myunjin,

what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
See the example below. 

Miguel


	String service = "http://dbpedia.org/sparql";
        String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
        QueryExecution qe 
                = QueryExecutionFactory.sparqlService(service, query);
        
        ResultSet rs = qe.execSelect();
        
        while(rs.hasNext()) {
            QuerySolution qs = rs.next();
            System.out.println("Concept -> "+qs.get("Concept").toString());
        }

> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
> 
> Hello. My name is Myunjin Lee.
> 
> I am testing simple SPARQL query from Korean DBpedia SPARQL
> endpoint(http://ko.dbpedia.org/sparql) using Jena.
> 
> For that, I implemented simple test code, but I had URI encoding 
> problem of SPARQL query that has Korean character.
> 
> 
> 
> My simple query is:
> 
> 
> 
>        String allSameAsQuery = ""
> 
>                       + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
> 
>                       + "SELECT *\n" + "WHERE {\n"
> 
>                       + "  <http://ko.dbpedia.org/resource/문절망둑>
> owl:sameAs ?x .\n" + "}";
> 
> 
> 
> And then, to process query, I construct Query object.
> 
> 
> 
> Query query = QueryFactory.create(allSameAsQuery);
> 
> System.out.println(query.toString());
> 
> 
> 
> Problem is that the query string is encoded when I make a Query object.
> Print out result is:
> 
> 
> 
> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
> 
> 
> 
> SELECT  *
> 
> WHERE
> 
>  { 
> <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
> owl:sameAs ?x }
> 
> 
> 
> So that, I cannot get any owl:sameAs resource.
> 
> 
> 
> How can I figure out the encoding problem? Or is there any method for 
> my problem?
> 
> Thank for your help.
> 
> 
> 
> Sincerely yours,
> 
> Dr. Myungjin Lee
> 



Re: Problem SPARQL query encoding

Posted by Miguel Bento Alves <mb...@gmail.com>.
Hi Myunjin,

what you did is not enough. You need to create a QueryExecution and create a ResultSet to have a cursor pointing to the results.
See the example below. 

Miguel


	String service = "http://dbpedia.org/sparql";
        String query = "select distinct ?Concept where {[] a ?Concept} LIMIT 100";
        QueryExecution qe 
                = QueryExecutionFactory.sparqlService(service, query);
        
        ResultSet rs = qe.execSelect();
        
        while(rs.hasNext()) {
            QuerySolution qs = rs.next();
            System.out.println("Concept -> "+qs.get("Concept").toString());
        }

> On 06 Nov 2014, at 07:13, 이명진 <xm...@gmail.com> wrote:
> 
> Hello. My name is Myunjin Lee.
> 
> I am testing simple SPARQL query from Korean DBpedia SPARQL
> endpoint(http://ko.dbpedia.org/sparql) using Jena.
> 
> For that, I implemented simple test code, but I had URI encoding problem of
> SPARQL query that has Korean character.
> 
> 
> 
> My simple query is:
> 
> 
> 
>        String allSameAsQuery = ""
> 
>                       + "PREFIX owl: <http://www.w3.org/2002/07/owl#>\n"
> 
>                       + "SELECT *\n" + "WHERE {\n"
> 
>                       + "  <http://ko.dbpedia.org/resource/문절망둑>
> owl:sameAs ?x .\n" + "}";
> 
> 
> 
> And then, to process query, I construct Query object.
> 
> 
> 
> Query query = QueryFactory.create(allSameAsQuery);
> 
> System.out.println(query.toString());
> 
> 
> 
> Problem is that the query string is encoded when I make a Query object.
> Print out result is:
> 
> 
> 
> PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
> 
> 
> 
> SELECT  *
> 
> WHERE
> 
>  { <http://ko.dbpedia.org/resource/%EB%AC%B8%EC%A0%88%EB%A7%9D%EB%91%91>
> owl:sameAs ?x }
> 
> 
> 
> So that, I cannot get any owl:sameAs resource.
> 
> 
> 
> How can I figure out the encoding problem? Or is there any method for my
> problem?
> 
> Thank for your help.
> 
> 
> 
> Sincerely yours,
> 
> Dr. Myungjin Lee
>