[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/base/nepomuk-kde/annotation/plugins/geonames
From: Sebastian Trueg <sebastian () trueg ! de>
Date: 2011-02-25 8:04:04
Message-ID: 20110225080405.010CBAC8C0 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1222676 by trueg:
* Made Geonames plugin fully async
* Removed country fetch job as geonames now returns the country code
* Added nepomuk username - sadly we are restricted to a total of 30000 queries per \
day which essentially makes this plugin useless.
* Added the geonames ontology.
M +16 -2 CMakeLists.txt
A geonames_ontology_v2.2.1.rdf
M +10 -48 geonamesannotationplugin.cpp
M +0 -3 geonamesannotationplugin.h
D geonamescountryfetchjob.cpp
D geonamescountryfetchjob.h
M +2 -0 graphretriever.cpp
--- trunk/playground/base/nepomuk-kde/annotation/plugins/geonames/CMakeLists.txt \
#1222675:1222676 @@ -1,10 +1,24 @@
-kde4_add_plugin(nepomuk_geonamesannotationplugin
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+set(geonames_plugin_SRCS
geonamesannotationplugin.cpp
- geonamescountryfetchjob.cpp
graphretriever.cpp
../common/pimoplugintools.cpp
)
+soprano_add_ontology(
+ geonames_plugin_SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/geonames_ontology_v2.2.1.rdf
+ "Geonames"
+ "Nepomuk::Vocabulary"
+ "rdfxml")
+
+kde4_add_plugin(nepomuk_geonamesannotationplugin
+ ${geonames_plugin_SRCS}
+ )
+
target_link_libraries(nepomuk_geonamesannotationplugin
${NEPOMUK_LIBRARIES}
${SOPRANO_LIBRARIES}
--- trunk/playground/base/nepomuk-kde/annotation/plugins/geonames/geonamesannotationplugin.cpp \
#1222675:1222676 @@ -17,7 +17,6 @@
*/
#include "geonamesannotationplugin.h"
-#include "geonamescountryfetchjob.h"
#include "graphretriever.h"
#include "simpleannotation.h"
#include "pimo.h"
@@ -166,7 +165,6 @@
: AnnotationPlugin( parent ),
m_lastRdfJob( 0 )
{
- QTimer::singleShot( 0, this, SLOT( fetchCountryInformation() ) );
}
@@ -195,10 +193,10 @@
kDebug() << "starting geonames query for" << filter;
// build geonames query
- QUrl url( "http://ws5.geonames.org/search" );
+ QUrl url( "http://api.geonames.org/search" );
// search for names of things that start with filter
- url.addQueryItem( "name", filter + '*' );
+ url.addQueryItem( "name", filter );
// no more than 5 results
url.addQueryItem( "maxRows", "5" );
@@ -216,6 +214,11 @@
// and please give us some rdf
url.addQueryItem( "type", "rdf" );
+ // "nepomuk" has been registered as username with geonames
+ // this allows a max of 30000 queries per day which effectively
+ // kills this plugin. :(
+ url.addQueryItem( "username", "nepomuk" );
+
kDebug() << url;
m_lastRdfJob = new GraphRetriever( this );
@@ -238,7 +241,7 @@
"?r a \
<http://www.geonames.org/ontology#Feature> . "
"?r \
<http://www.geonames.org/ontology#name> ?name . "
"?r \
<http://www.geonames.org/ontology#featureClass> ?type . "
- "?r \
<http://www.geonames.org/ontology#inCountry> ?country . " + \
"?r <http://www.geonames.org/ontology#countryCode> ?country . "
\
"OPTIONAL { ?r <http://www.geonames.org/ontology#alternateName> \
?altname . "
\
"FILTER(LANG(?altname) = '%1') . } }" )
.arg( \
normalizedLanguageCode() ), @@ -247,7 +250,7 @@
QUrl featureUri = it.binding( "r" ).uri();
QString name = it.binding( "name" ).toString();
QString altname = it.binding( "altname" ).toString();
- QUrl country = it.binding( "country" ).uri();
+ QString country = it.binding( "country" ).toString();
QUrl type = it.binding( "type" ).uri();
QString displayName = altname.isEmpty() ? name : altname;
@@ -258,7 +261,7 @@
// disembiguate city names
if ( type.fragment() != "A" ) { // makes no sense to have labels \
like "country (country)"
- QString countryName = getCountryNameFromInCountryUri( country );
+ const QString countryName = \
KGlobal::locale()->countryCodeToName(country); if ( !countryName.isEmpty() ) {
displayName = QString( "%1 (%2)" ).arg( displayName, \
countryName ); }
@@ -284,47 +287,6 @@
emitFinished();
}
-
-// geonames' query service does not provide country links in features. Thus, we \
simply
-// cache all countries in the local Nepomuks store. I don't think that anyone would
-// mind having a bit of geographical data at their fingertips. ;)
-void Nepomuk::GeoNamesAnnotationPlugin::fetchCountryInformation()
-{
- if ( !GeoNamesCountryFetchJob::countriesAlreadyFetched() ) {
- GeoNamesCountryFetchJob* job = new GeoNamesCountryFetchJob( this );
- job->start(); // don't care about result, we can't do anything about it \
anyway and will retry the next time
- }
-}
-
-
-QString Nepomuk::GeoNamesAnnotationPlugin::getCountryNameFromInCountryUri( const \
QUrl& uri )
-{
- QString countryName;
-
- // let's see if fetchCountryInformation has already stored the country \
information
- // here we hack a bit: we have no real country link, only the geonames:inCountry \
one which
- // we can only match against the inCountry property of the country which is in \
that country (what?)
- Soprano::QueryResultIterator it
- = ResourceManager::instance()->mainModel()->executeQuery( QString( "select \
?name ?altname where { "
- "?c a \
<http://www.geonames.org/ontology#Feature> . "
- "?c \
<http://www.geonames.org/ontology#featureClass> <http://www.geonames.org/ontology#A> \
. "
- "?c \
<http://www.geonames.org/ontology#inCountry> <%1> . "
- "?c \
<http://www.geonames.org/ontology#name> ?name . "
- "OPTIONAL \
{ ?c <http://www.geonames.org/ontology#alternateName> ?altname . "
- \
"FILTER(LANG(?altname) = '%2') . } }" )
- .arg( \
QString::fromAscii( uri.toEncoded() ) )
- .arg( \
KGlobal::locale()->language() ),
- \
Soprano::Query::QueryLanguageSparql );
-
- if ( it.next() ) {
- countryName = it.binding( "altname" ).toString();
- if ( countryName.isEmpty() )
- countryName = it.binding( "name" ).toString();
- }
-
- return countryName;
-}
-
NEPOMUK_EXPORT_ANNOTATION_PLUGIN( Nepomuk::GeoNamesAnnotationPlugin, \
"nepomuk_geonamesannotationplugin" )
#include "geonamesannotationplugin.moc"
--- trunk/playground/base/nepomuk-kde/annotation/plugins/geonames/geonamesannotationplugin.h \
#1222675:1222676 @@ -44,11 +44,8 @@
private Q_SLOTS:
void slotGeoNamesQueryResult( KJob* );
- void fetchCountryInformation();
private:
- QString getCountryNameFromInCountryUri( const QUrl& uri );
-
GraphRetriever* m_lastRdfJob;
};
}
--- trunk/playground/base/nepomuk-kde/annotation/plugins/geonames/graphretriever.cpp \
#1222675:1222676 @@ -153,6 +153,8 @@
void Nepomuk::GraphRetriever::httpRequestFinished( KJob* job )
{
+ kDebug() << job->errorString();
+
KIO::StoredTransferJob* tj = static_cast<KIO::StoredTransferJob*>( job );
// reset idle counter every time a request is finished
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic