Skip to main content

A lightweight Python library for Store Norske Leksikon and Lex.dk/Den Store Danske APIs.

Project description

Logo

SnlData version Actions Status Documentation Status Coverage Status Build Status License: GPLv3 Downloads PyPI

A lightweight Python library for Store Norske Leksikon and Lex.dk/Den Store Danske APIs

Installation

pip3 install snldata

Quick Start

Raw JSON

import snldata

R = snldata.SnlSession()
R.search(query="fortolket programmeringsspråk", best=True) #Pick the one with the best rank
print(R.json)

Outputs: the JSON object

{
	"title": "fortolket programmeringsspråk",
	"url": "http://snl.no/fortolket_programmeringsspr%C3%A5k",
	"subject_url": "http://snl.no/.taxonomy/3689",
	"subject_title": "Programmering",
	"xhtml_body": "\u003cdiv\u003e\r\n\u003cp\u003eprogrammeringsspråk som ikke blir kompilert til objekt- eller maskinkode, men fortolket av et eget program på vertsmaskinen.\u003c/p\u003e\r\n\u003cp\u003eFordelen med slike språk er at man kan lage programmer som kan gjøre på mange forskjellige \u003ca class=\"crossref\" href=\"https://snl.no/datamaskin\"\u003edatamaskiner\u003c/a\u003e og \u003ca class=\"crossref\" href=\"https://snl.no/operativsystem\"\u003eoperativsystemer\u003c/a\u003e uten å skreddersy dem for hver enkelt plattform.\u003c/p\u003e\r\n\u003cp\u003eEksempler på fortolkede språk:\u003c/p\u003e\r\n\u003cul\u003e\r\n\u003cli\u003e\u003ca class=\"crossref\" href=\"https://snl.no/Python_-_programmeringsspr%C3%A5k\"\u003ePython\u003c/a\u003e\u003c/li\u003e\r\n\u003cli\u003eJavascript\u003c/li\u003e\r\n\u003cli\u003e\u003ca class=\"crossref\" href=\"https://snl.no/Perl_-_IT\"\u003ePHP\u003c/a\u003e\u003c/li\u003e\r\n\u003cli\u003e\u003ca class=\"crossref\" href=\"https://snl.no/Perl_-_IT\"\u003ePerl\u003c/a\u003e\u003c/li\u003e\r\n\u003c/ul\u003e\r\n\u003c/div\u003e",
	"created_at": "2017-12-12T10:34:18.189+01:00",
	"changed_at": "2017-12-12T10:38:37.626+01:00",
	"license_name": "fri",
	"metadata_license_name": "fri",
	"metadata": {
		"lastname": "",
		"firstname": ""
	},
	"authors": [{
		"full_name": "Henrik Dvergsdal"
	}],
	"images": []
}

Licenses for content from Store Norske Leksikon and Lex.dk

Licence Description Read more
fri Creative Commons CC-BY-SA-3.0 license. Everyone is allowed to share, use, copy and adapt the text as long as the author and Store norske leksikon continues to be credited and the article retains the same free license for further use. SNL LEX
begrenset gjenbruk/begrænset genbrug You can't reuse, republish, or adapt the article without first obtaining the author's permission. SNL LEX

Overview of sites/zones

SNL

code Website Note
snl https://snl.no/ Default
nbl https://nbl.snl.no/
sml https://sml.snl.no/
nkl https://nkl.snl.no/
lille https://lille.snl.no/
prototyping - Unstable - for SNL

LEX

code Website Note
lex https://lex.dk/ is Den Store Danske/Danmarks Nationalleksikon
dlh https://dansklitteraturshistorie.lex.dk/
dbl https://biografiskleksikon.lex.dk/
gtl https://teaterleksikon.lex.dk/
nm https://mytologi.lex.dk/
do https://danmarksoldtid.lex.dk/
sl https://symbolleksikon.lex.dk/
dh https://danmarkshistorien.lex.dk/
hob https://bornelitteratur.lex.dk/
pd https://pattedyratlas.lex.dk/
nid https://naturenidanmark.lex.dk/
trap https://trap.lex.dk/
prototyping-lex - Unstable - for LEX pages

Query

Easy Query

import snldata

R = snldata.SnlSession()
R.search(query="Ole Ivars", best=True) #Pick the one with the best rank
print(R.url)

Outputs: https://snl.no/Ole_Ivars

import snldata

R = snldata.SnlSession()
R.search(query="Ole Ivars") #Pick the three best results
for val in R.json:
    print(val["simple"]) #Summery for each index

Outputs:

0. Ole Ivars (rank 576.6): Ole Ivars er et norsk danseband fra Hamar.
1. Spellemannprisen (rank 25.9): Spellemannprisen er den norske platebransjens årlige prisutdeling for å stimulere og markere plateproduksjonen i Norge.
2. danseband (rank 25.1): Danseband, ensemble som spiller til dans, betegner i dag vanligvis en instrumentbesetning som i pop og rock (vokal, elektrisk gitar og bass, keyboards, trommer, eventuelt også saksofon eller andre blåsere).
###Explaining of the values:
<index of the json file> <title> (rank <rank id>): <first sentence>

Pick the article you want from the example above:

R._get(1)
print(R.title)

Outputs: Spellemannprisen

import snldata

R = snldata.SnlSession()
R.search(zone='lex', query="Python", best=True)  #Pick the one with the best rank
print(R.url)

Outputs: https://lex.dk/Python

Advance Query (best for prototyping api)

The prototyping API endpoint has been removed as of May 2023.

No result

If the API returns no results, .json will be given a empty list.

import snldata

R = snldata.SnlSession()
R.search(zone='lex', query="asdadasdasdad", best=True)  #Pick the one with the best rank
print(R.json)

Outputs: {}

import snldata

R = snldata.SnlSession()
R.search(zone='lex', query="jdfhdskjfhsjkdfhksdfh") #Pick the three best results, but there are none
R._get(0)
print(R.json)

Outputs: {}

All of the examples uses text that is CC-BY-SA-3.0. By at least one of the following authors: Henrik Dvergsdal, Jon Vidar Bergan, and Audun Kjus Aahlin. Read more about the license: fri gjenbruk.

To-do

  • Fully support taxonomy
  • Support for ".recent-activities" to JSON.
  • When zero results, return empty dict to tell the user there is no result.

Reporting Issues

If you have suggestions, bugs or other issues specific to this library, file them here. Or just send me a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snldata-1.1.4.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snldata-1.1.4-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file snldata-1.1.4.tar.gz.

File metadata

  • Download URL: snldata-1.1.4.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snldata-1.1.4.tar.gz
Algorithm Hash digest
SHA256 5ed760ba580636eedb4262f35ef3616dec62e227173447570df63103514b549d
MD5 8a5479ee47767e93721ab0d68eb38edb
BLAKE2b-256 bb393ee702a31f9bc1e24f789dbe20479588f604e9dafac6442fbc197913defb

See more details on using hashes here.

Provenance

The following attestation bundles were made for snldata-1.1.4.tar.gz:

Publisher: publish.yml on DiFronzo/SnlData

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file snldata-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: snldata-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for snldata-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ec04321e62a7d0bcef08aa0e610b7f7680151ae01d0bd35d8b5b40888d93f12d
MD5 c50860a57e3353a5f9fbaa90beef2004
BLAKE2b-256 50eba7afa2a0fc65a8e3308dc73900bd19d8ecfc5120fedece10fdd6e10777f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for snldata-1.1.4-py3-none-any.whl:

Publisher: publish.yml on DiFronzo/SnlData

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page