Eksperimentelle tjenester

1.13. Eksperimentelle tjenester#

from dhlab.future.corpus_conc_coll import Corpus, Concordance, Collocations, Frequencies
c = Corpus.build(doctype="digibok")
c.head(2)
dhlabid urn title authors oaiid sesamid isbn10 city timestamp year publisher langs subjects ddc genres literaryform doctype ocr_creator ocr_timestamp
c.get_freqs().display_names()
---------------------------------------------------------------------------
JSONDecodeError                           Traceback (most recent call last)
File ~/.local/lib/python3.10/site-packages/requests/models.py:971, in Response.json(self, **kwargs)
    970 try:
--> 971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError

File /usr/lib/python3.10/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:

File /usr/lib/python3.10/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
    333 """Return the Python representation of ``s`` (a ``str`` instance
    334 containing a JSON document).
    335 
    336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

File /usr/lib/python3.10/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

JSONDecodeError                           Traceback (most recent call last)
Cell In[3], line 1
----> 1 c.get_freqs().display_names()

File ~/prosjekter/DHLAB/dhlab/future/corpus_conc_coll.py:71, in Corpus.get_freqs(self)
     70 def get_freqs(self):
---> 71     return Frequencies.get_freqs(self)

File ~/prosjekter/DHLAB/dhlab/future/corpus_conc_coll.py:108, in Frequencies.get_freqs(self, corpus, words)
    106 @classmethod
    107 def get_freqs(self, corpus, words=None):
--> 108     res = get_document_frequencies(urns=urnlist(corpus), words=words)
    109     self._title_dct = {k: v for k, v in zip(corpus.dhlabid, corpus.title)}
    110     return Frequencies(res)

File ~/prosjekter/DHLAB/dhlab/api/dhlab_api.py:559, in get_document_frequencies(urns, cutoff, words, sparse)
    557 params = locals()
    558 r = requests.post(f"{BASE_URL}/frequencies", json=params)
--> 559 result = r.json()
    560 # check if words are passed - return differs a bit
    561 if words is None:

File ~/.local/lib/python3.10/site-packages/requests/models.py:975, in Response.json(self, **kwargs)
    971     return complexjson.loads(self.text, **kwargs)
    972 except JSONDecodeError as e:
    973     # Catch JSON-related errors and raise as requests.JSONDecodeError
    974     # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975     raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)

JSONDecodeError: Expecting value: line 1 column 1 (char 0)
c.get_freqs().sum_freqs()
frequencies
. 15660.0
, 12880.0
och 688.0
år 913.0
du 512.0
... ...
NYE 3.0
UKJENT 3.0
WILLIAM 3.0
GAMLE 6.0
TESTAMENTET 9.0

49061 rows × 1 columns

Concordance.get_concordances(corpus=c, words="konge").head()
index docid urn concordance link
0 0 100279411 URN:NBN:no-nb_digibok_2016011848084 ... Mwaash eller Woot < Mashamboy > er Kubas f... <a target='_blank' href = 'https://urn.nb.no/U...
Collocations.get_collocations(corpus=c, words=["konge", "kongeriket"])
counts
, 1
første 1
den 1
Kubas 1
er 1
alle 1
> 1
i 1
Mashamboy 1
Kuba-kulturen 1
< 1
kan 1
Woot 1
føre 1
sin 1
eller 1
Mwaash 1
avstamning 1
. 1
tilbake 1
blir 2
Kubas 1
der 1
seremonier 1
mytiske 1
under 1
opprinnelse 1
båret 1
frem 1
De 1
sti 1
lt 1
. 1
, 1
) 1
men 1
Zaire 1
tidligere 1
også 1