Skip to content

Commit

Permalink
Py3-compatible 0.7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
aolieman committed Jul 18, 2016
1 parent 6f8b5f3 commit 7de3403
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 41 deletions.
14 changes: 4 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ pyspotlight

is a thin python wrapper around `DBpedia Spotlight`_'s `REST Interface`_.

The currently supported DBpedia Spotlight versions are 0.5 and 0.6.5.
However, as long as there are no major API overhauls, this wrapper might also
work with future versions. If you encounter a bug with a newer DBpedia version,
feel free to create an issue here on github.

Note that I'm trying to track DBpedia Spotlight release version numbers, so you can
easily see which pyspotlight version has been tested with which Spotlight
release. Therefore all pyspotlight 0.5 releases are tested against
Spotlight 0.5.
This repository contains a fork of the original `pyspotlight` that aims at providing compatibility
with newer releases of DBpedia Spotlight. The orignal seems unmaintained; pull requests are not being
reviewed and merged.

.. _`DBpedia Spotlight`: https://github.com/dbpedia-spotlight/dbpedia-spotlight#dbpedia-spotlight
.. _`REST Interface`: https://github.com/dbpedia-spotlight/dbpedia-spotlight/wiki/Web-service
Expand All @@ -29,7 +23,7 @@ Therefore installation is as easy as::
Requirements for installation from source/github
================================================

This module has been tested with Python 2.6 and Python 2.7.
This module has been tested with Python 2.7 and Python 3.5.

As long as you use the ``setup.py`` for the installation
(``python setup.py install``), you'll be fine because Python takes care of the
Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,32 @@
"Development Status :: 5 - Production/Stable",
]

requires = ["requests=>2.10.0", ]
requires = ["requests", ]

# This might not be the best idea.
try:
import json
except ImportError:
requires.append('simplejson>=2.0')
requires.append('simplejson')


# Python 2.6 does not ship with an OrderedDict implementation.
# God save the cheeseshop!
try:
from collections import OrderedDict
except ImportError:
requires.append('ordereddict>=1.1')
requires.append('ordereddict')


setup(name='pyspotlight',
version='0.6.5.2',
version='0.7.0',
license='BSD',
url='https://github.com/newsgrape/pyspotlight',
url='https://github.com/aolieman/pyspotlight',
packages=find_packages(),
description='Python interface to the DBPedia Spotlight REST API',
long_description=open('README.rst').read(),
keywords="dbpedia spotlight semantic",
classifiers=classifiers,
install_requires=requires,
test_suite='nose2.collector.collector',
)
46 changes: 20 additions & 26 deletions spotlight/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@
This is just a simple interface to a Spotlight API.
Tested with DBPedia Spotlight 0.5 and 0.6.5.
Note that I'm trying to track Spotlight release version numbers, so you can
easily see which pyspotlight version has been tested with which Spotlight
release.
I hope the code and the small documentation speaks for itself :-)
If you should encounter any problems, feel free to contact me on github
(originell). I'm happy to help out with anything related to my code.
Tested with DBPedia Spotlight 0.7.
"""
__version_info__ = (0, 6, 5)
__version_info__ = (0, 7, 0)
__version__ = '.'.join(map(str, __version_info__))


Expand All @@ -42,7 +33,7 @@ def _convert_number(value):
# Workaround for footnotes being put into Resources.surfaceForm and then
# having them parsed by the JSON parser into a list. (issue #4)
if isinstance(value, list):
value = unicode(value)
value = str(value)

try:
return int(value)
Expand All @@ -61,7 +52,7 @@ def _dict_cleanup(dic, dict_type=dict):
That way we can avoid stack fails.
"""
clean = dict_type()
for key, value in dic.iteritems():
for key, value in dic.items():
if value is None:
continue

Expand All @@ -70,7 +61,7 @@ def _dict_cleanup(dic, dict_type=dict):
try:
# If this is a string or bool,
# go straight to type conversion.
if (isinstance(value, basestring) or
if (hasattr(value, 'strip') or
isinstance(value, bool)):
raise AttributeError
# Test for an iterable (list, tuple, set)
Expand All @@ -86,12 +77,7 @@ def _dict_cleanup(dic, dict_type=dict):


# Main functions.
#
# I was inspired to go back to a function based approach after seeing this
# awesome talk by Jack Diederich: Stop Writing Classes
# http://pyvideo.org/video/880/stop-writing-classes
# Most of the class-based approach had the problems he described.
# Embarrassing!

def annotate(address, text, confidence=0.0, support=0,
spotter='Default', disambiguator='Default',
filters=None, headers=None):
Expand Down Expand Up @@ -157,9 +143,13 @@ def annotate(address, text, confidence=0.0, support=0,
:rtype: list of resources
"""
payload = {'confidence': confidence, 'support': support,
'spotter': spotter, 'disambiguator': disambiguator,
'text': text}
payload = {
'confidence': confidence,
'support': support,
'text': text,
'spotter': spotter,
'disambiguator': disambiguator
}

filter_kwargs = {'policy': 'whitelist'}
filter_kwargs.update(filters or {})
Expand Down Expand Up @@ -204,9 +194,13 @@ def candidates(address, text, confidence=0.0, support=0,
:rtype: list of surface forms
"""
payload = {'confidence': confidence, 'support': support,
'spotter': spotter, 'disambiguator': disambiguator,
'text': text}
payload = {
'confidence': confidence,
'support': support,
'text': text,
'spotter': spotter,
'disambiguator': disambiguator
}

filter_kwargs = {'policy': 'whitelist'}
filter_kwargs.update(filters or {})
Expand Down

0 comments on commit 7de3403

Please sign in to comment.