OpenSextant Python API
mubaldino
released this
29 Mar 16:01
·
23 commits
to master
since this release
OpenSextant ("Xponents") Python library
This library provides the most common data model, utilities and Xponents REST client to interact with OpenSextant/Xponents solutions. The main resources interfaced here are:
- Xponents REST API (
opensextant.xlayer
package offersXlayerClient
) - Xponents Gazetteer API (
opensextant.gazetteer
package offers Solr Gazetter mechanics) - Xponents Gazetteer ETL (
opensextant.gazetteer
offers classes used to curate the gazetteer in./solr
from raw sources)
Version: opensextant
library, v1.5 (2024-March), attached below.
Install: pip install opensextant-1.5.8.tar.gz
Details
- Xponents REST usage for Python
- Gazetteer queries for example, See Python section at bottom.
- opensextant API pydoc
For the REST client below, please deploy Docker image per https://hub.docker.com/r/mubaldino/opensextant
Use the resulting server_host:port
as url
below
Correct usage for opensextant.xlayer
with REST API looks like this:
from opensextant.xlayer import XlayerClient
client = XlayerClient(url) # opensextant server URL or simply "server_host:port"
tags = client.process(docid, text, features=["geo", "postal"])
# Confidence threshold = 20
# Array of opensextant.TextMatch,
# -- Consult subclass -- PlaceCandidate is a match that has geographic information
# -- Consult label to determine nature of tag. It is one of "country", "coord", "postal", "place"
# -- Consult TextMatch.attrs dictionary for useful metadata, e.g., as shown geolocation "confidence" should be used wisely.
# 100 point scale, where 20 is a default cut-off (below that tag is unlikely a location or correct.)
# -- Consult PlaceCandidate metadata in attrs as well as the place attribute for location metadata.
for t in tags:
if t.filtered_out:
# Add "filtered" to features to see what is filtered out.
continue
conf = int(t.attrs.get("confidence", -1))
if isinstance(t, PlaceCandidate):
if t.label == "coord":
print("Found a coordinate")
if conf >= 25:
print("Found a high confidence place")