Aleph X-Service wrapper.
This module allows you to query Aleph’s X-Services module (Aleph server is defined by aleph.settings.ALEPH_URL in settings.py).
There are two levels of abstraction.
You can use this functions to access Aleph:
searchInAleph(base, phrase, considerSimilar, field)
downloadRecords(search_result, [from_doc])
getDocumentIDs(aleph_search_result, [number_of_docs])
downloadMARCXML(doc_id, library)
downloadMARCOAI(doc_id, base)
Aleph works in strange way, that he won’t allow you to access desired information directly.
You have to create search request by calling searchInAleph() first, which will return dictionary with few important informations about session.
This dictionary can be later used as parameter to getDocumentIDs() function, which will give you list of DocumentID named tuples.
Note
namedtuple() is used, because to access your document, you don’t need just document ID number, but also library ID string.
Depending on your system, there may be just only one accessible library, or multiple ones, and then you will be glad, that you get both of this informations together.
DocumentID can be used as parameter to downloadMARCXML().
Lets look at some code:
ids = getDocumentIDs(searchInAleph("nkc", "test", False, "wrd"))
for id_num, library in ids:
XML = downloadMARCXML(id_num, library)
# processDocument(XML)
There are wrappers, which returns ID’s of matching document in Aleph:
You can theh download them using downloadMARCXML() or downloadMARCOAI().
Count wrappers returns just the number of records with given parameters are there in aleph.
Note
Counting functions are by one request faster than just counting results from standard getters. It is preferred to use them to reduce load to Aleph.
List of valid bases can be obtained by calling getListOfBases(), which returns list of strings.
There is also defined exception tree - see AlephException doc-string for details.
Exception tree:
- AlephException
|- InvalidAlephBaseException
|- InvalidAlephFieldException
|- LibraryNotFoundException
`- DocumentNotFoundException
This structure is used to store “pointer” to document in aleph.
ID of document.
This can be different for each document, depend on your system.
Default “nkc”, but really depends on what bases you have defined in your Aleph server.
This function is here mainly for purposes of unittest
Returns: | list of str –
Valid bases as they are used as URL parameters in links at
|
---|
Send request to the aleph search engine.
Request itself is pretty useless, but it can be later used as parameter for getDocumentIDs(), which can fetch records from Aleph.
Parameters: |
|
---|---|
Returns: | dictionary – consisting from following fields:
|
Example
Returned dict:
{
'session-id': 'YLI54HBQJESUTS678YYUNKEU4BNAUJDKA914GMF39J6K89VSCB',
'set_number': 36520,
'no_records': 1,
'no_entries': 1
}
Raises: |
|
---|
Download MAX_RECORDS documents from search_result starting from from_doc.
Returns: | list – List of XML strings with documents in MARC OAI. |
---|
Get IDs, which can be used as parameters for other functions.
Parameters: |
|
---|---|
Returns: | list – DocumentID named tuples to given aleph_search_result. |
Raises: | AlephException – If Aleph returns unknown format of data. |
Note
Returned DocumentID can be used as parameters to downloadMARCXML().
Download MARC XML document with given doc_id from given library.
Parameters: |
|
---|---|
Returns: | str – MARC XML unicode string. |
Raises: |
Download MARC OAI document with given doc_id from given (logical) base.
Funny part is, that some documents can be obtained only with this function in their full text.
Parameters: |
|
---|---|
Returns: | str – MARC XML Unicode string. |
Raises: |
Download full XML record for given isbn in base.
Parameters: |
|
---|---|
Returns: | str – String with full OAI XML representation of the record. |
Download full XML record for given author in base.
Parameters: |
|
---|---|
Returns: | str – String with full OAI XML representation of the record. |
Download full XML record for given publisher in base.
Parameters: |
|
---|---|
Returns: | str – String with full OAI XML representation of the record. |
Download full XML record for given title in base.
Parameters: |
|
---|---|
Returns: | str – String with full OAI XML representation of the record. |
Get list of DocumentID objects of documents with given isbn.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Get list of DocumentID objects of documents with given author.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Get list of DocumentID objects of documents with given publisher.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Get list of DocumentID objects of documents with given title.
Parameters: |
|
---|---|
Returns: | list – of DocumentID objects |
Get number of records in Aleph which match given isbn.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |
Get number of records in Aleph which match given author.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |
Get number of records in Aleph which match given publisher.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |
Get number of records in Aleph which match given title.
Parameters: |
|
---|---|
Returns: | int – Number of matching documents in Aleph. |