FrankTan
FrankTan

Reputation: 1686

Convert text to URL

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?

Upvotes: 0

Views: 342

Answers (2)

chooban
chooban

Reputation: 9256

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".

Upvotes: 0

Joop Eggen
Joop Eggen

Reputation: 109547

Use

URLEncoder.encode(textAfterQuestionMark);

Upvotes: 3

Related Questions