Working sample code?
Working sample code?
Posted on: Wed, 03/04/2009 - 18:55
Can somebody point me to sample code for using symantic proxy?
I tried calling "http://service.semanticproxy.com/processurl/"+URLEncoder.encode("my api key", "UTF-8")+"/rdf/"+"<web site url>", I get response. but parsing is mess and I have been getting "Failed to parse RDF - root tag is not string - rdf:RDF". It happens for most of URLs, but if I go through browser url response looks fine.
When I tried, json format, its such a mess too, first I need to parse the flat json and build hierarchy.
I use java client and I am open to use either RDF or json, I would really appreciate for any pointers on this?
Thanks
Trackback URL for this post:
http://www.opencalais.com/trackback/17207

Hi,
The reason for the rdf parsing exception is a difference in response formats. In one format the RDF is wrapped inside a <string> node. In the other it is not.
The simplest way to fix this would be to stick to RDF response format and wrap the response with <string>...</string>.
So, if you have the response you get from semantic proxy in a String variable called rdf, instead of passing rdf to the parser, pass "<string>" + rdf + "</string>".
In case the rdf you get begins with an XML declaration - i.e. <?xml version=...><rdf:RDF>..., you'd need to add the opening <string> tag after the declaration instead of at the very beginning.
Hope this helps,
Shai
Thank you, having <string> around fixed it.
Hi,
As for JSON the documentation is here http://www.opencalais.com/JSON and there is also TestJSON example attachment in this page (if you are logged in to the opencalais.com portal).
This should help you parse the JSON output of SemanticProxy.
Please let us know if that helps.
Can you share with us what is the application you are trying to build?
Ofer
I have seen that example. Looks appropriate for client side processing.
We build sharing tools for publishers. I am building a subsystem which takes these shared articles and use Open calai's semantic proxy to generate metadata for every shared article. As I have mentioned, I am ok with parsing either json or rdf response. Also I have mentioned, its not straight forward to parse json, as it needs to be cleaned up first and then build heirarchy, You have provided utitlity javascript methods which could be processed on client side. Any better way of doing it on server side?
While trying rdf, I am getting root tag not found exception. As I am stuck at this point, I would really appreciate any pointers on these? Any other better alternative suggesions?
Thanks