0

Is there any way to transform a request like this:

"Annotation text="President Obama called Wednesday on Congress to extend a tax break
for students included in last year's economic stimulus package, arguing that the policy
provides more generous assistance."
confidence="0.2" support="20" 
sparql="SELECT DISTINCT ?x WHERE { ?x a <http://dbpedia.org/ontology/OfficeHolder>; . 
?x ?related <http://dbpedia.org/resource/Chicago>; }" 
policy="whitelist"

Into this?

http://spotlight.dbpedia.org/rest/annotate?text=President%20Obama%20called%20Wednesday%20on%20Congress%20to%20extend%20a%20tax%20break%20for%20students%20included%20in%20last%20year%27s%20economic%20stimulus%20package,%20arguing%20that%20the%20policy%20provides%20more%20generous%20assistance.&confidence=0.2&support=20&sparql=SELECT+DISTINCT+%3Fx%0D%0AWHERE+%7B%0D%0A%3Fx+a+%3Chttp%3A%2F%2Fdbpedia.org%2Fontology%2FOfficeHolder%3E+.%0D%0A%3Fx+%3Frelated+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FChicago%3E+.%0D%0A%7D

I know that spaces are equal to %20 but I don't know the other conversions. Is there any Java library that can do the conversion?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
FrankTan
  • 1,626
  • 6
  • 28
  • 63

2 Answers2

3

Use

URLEncoder.encode(textAfterQuestionMark);
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • 1
    i want point this to this : http://stackoverflow.com/questions/724043/http-url-address-encoding-in-java too – FrankTan Dec 21 '11 at 12:38
0

The single parameter version of encode is marked as deprecated. To be more assured of what the method will return, it's best to specify an encoding character set.

URLEncoder.encode( "foobar", "UTF-8" );

The different is that for the single parameter version, "the resulting string may vary depending on the platform's default encoding".

chooban
  • 9,018
  • 2
  • 20
  • 36