GeoNames Home | Postal Codes | Download / Webservice | About 

GeoNames Forum
  [Search] Search   [Recent Topics] Recent Topics   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Retrieve Wikipedia information by URL  XML
Forum Index -> General
Author Message
bradamant



Joined: 03/11/2011 16:07:26
Messages: 6
Offline

I'm processing some data where I will have the title (and thus, once it's encoded, the URL) of some Wikipedia articles that I want the coordinates for. I can't find an example of doing this using the Java APi, though it seems to work fine on the web (http://api.geonames.org/wikipediaSearch?title=Philadelphia&maxRows=1&username=demo).

Naively, I want something like this:
Code:
 myPlace.setWikipediaUrl("http://en.wikipedia.org/wiki/Philadelphia"); //OR
 myPlace.setTitle("Philadelphia"); //and then...
 Double lat = myPlace.getLatitude();
 Double lon = myPlace.getLongitude();


But that doesn't actually search anything. However, Webservice.wikipediaSearch doesn't look like it allows you specify the title or URL.

Doing this would make my app much more efficient; if I know the article is talking about [[Philadelphia]] I can get the coordinates for the exact place that is meant, whereas a simple search of Geonames for "philadelphia" has 2000+ results!
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

di you try the method Webservice.wikipediaSearchForTitle(title,language) ?

Marc

[WWW]
bradamant



Joined: 03/11/2011 16:07:26
Messages: 6
Offline

Yes, I tried that last week as well.
Code:
WebService.setUserName("myUsername");
 List<WikipediaArticle> wikiResults = WebService.wikipediaSearchForTitle(
                                 "Philadelphia","en");
 for (WikipediaArticle r : wikiResults) {
      System.out.println(r.getLatitude());
 }


Errors start with:
Code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jdom/input/SAXBuilder
 	at org.geonames.WebService.wikipediaSearchForTitle(Unknown Source)
 	at parsetextandurls.ParseTextAndURLs.main(ParseTextAndURLs.java:100)
 Caused by: java.lang.ClassNotFoundException: org.jdom.input.SAXBuilder
 at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
 	at java.security.AccessController.doPrivileged(Native Method)
 	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 	... 2 more


It seems like a jdom error, which doesn't appear to be required (if I "import org.jdom.input.SAXBuilder;" it gets marked as unused, too). I tried adding jdom-1.1 to the classpath and still get the same result.
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

jdom is used by the library not directly by your code. You don't have to import it in your code, but it needs to be on the classpath.
I suspect there is something wrong with your classpath.

Best

Marc

[WWW]
bradamant



Joined: 03/11/2011 16:07:26
Messages: 6
Offline

Thanks, once I knew I was on the right track I was able to solve the classpath problem.

But now that the function's working, I don't think it does quite what I need. For example, if I search for Louisiana, the first result is Shreveport, Louisiana (latitude 32.4681) whereas I want just Louisiana (latitude 31.0139). (For some other searches like Philadelphia, the first result *is* the desired one.)

I already have a function that does a non-exact search of toponym names in GeoNames if it encounters one in free text; I was hoping that if I knew with 100% certainty that a specific Wikipedia article was meant (because it's [[linked]]), I could retrieve just that one location using this alternate method. Is there any way to do that?
marc



Joined: 08/12/2005 07:39:47
Messages: 4501
Offline

You can iterate over the result list and get the one with the same name/url.

Best Regards

Marc

[WWW]
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.5 © JForum Team