This is a python client sdk for accessing semantha (the semantic platform)
Project description
semantha® SDK
The semantha SDK is a high-level REST client to access the semantha API. The SDK is still under development. An overview of the current progress (i.e. implemented and tested resources and endpoints) may be found at the end of this document (State of Development). The semantha SDK is compatible with python >= 3.8.
Disclaimer
IMPORTANT: The SDK is under development and interfaces may change at any time without notice. Use with caution and on own risk.
Update Note
Version 4.5.0 comes with a major restructuring of the SDK.
All sub-resources are directly accessible (instead of invoking getters).
That also means that (except for a few) all functions are plain get/post/delete/put/patch.
For example, in Versions < 4.5.0 a domain resource was fetched using semantha_sdk.domains.get_one("domain_name")
.
Starting with 4.5.0 it is semantha_sdk.domains("domain_name")
.
That also means that get/post/put/patch functions return semantha model objects (and never resources), which makes usage more consistent.
Access
To access semantha's API you will need an API and a server url. Both can be requested via this contact form.
Basic Usage
Import
import semantha_sdk
Authentication
semantha = semantha_sdk.login(url="<semantha platform server URL>", key="<your key>")
# or
semantha = semantha_sdk.login(url="<semantha platform server URL>", key_file="<path to your key file (json format)>")
End-point (Resource) Access
# end-points (resp. resources) can be used like objects
current_user = semantha.currentuser
my_domain = semantha.domains("my_domain")
# they may have sub-resources, which can be retrieved as objects as well
reference_documents = my_domain.referencedocuments
CRUD on End-points
# CRUD operations are functions
domain_settings = my_domain.settings.get()
my_domain.referencedocuments.delete() (deletes ALL reference document/library entries)
Function Return Types & semantha Data Model
# some functions only return None, e.g.
my_domain.referencedocuments.delete() # returns NoneType
# others return built in types, e.g
roles_list = currentuser.roles.get() # returns list[str]
# but most return objects of the semantha Data Model
# (all returned objects are instances of frozen dataclasses)
settings = my_domain.settings.get() # returns instance of DomainSettings
# attributes can be accessed as properties, e.g.
settings.enable_tagging # returns true or false
# Data Model objects may be complex
document = my_domain.references.post(file=a, referencedocument=b) # returns instance of Document
# the following returns the similarity value of the first references of the first sentence of the
# the first paragraph on the first page of the document (if a reference was found for this sentence)
similarity = pages[0].contents[0].paragraphs[0].references[0].similarity # returns float
State of Development
The following resources and end-points are fully functional and (partially) tested:
- login -> API
- .currentuser -> CurrentUser
- get -> UserData(SemanthaModelEntity)
- roles -> CurrentUserRoles
- get -> list[str]
- .diff -> Diff
- post -> list[Diff(SemanthaModelEntity)]
- .info -> VersionInfo
- get -> VersionInfo
- .languages -> list[str]
- .domains -> Domains
- get -> list[Domain(SemanthaModelEntity)]
- .domains("domain_name") -> Domain
- .documentannotations -> DocumentAnnotations
- post -> not yet implemented
- .documentclasses -> DocumentClasses
- get -> list[DocumentClass(SemanthaModelEntity)]
- post -> DocumentClass(SemanthaModelEntity)
- delete -> None
- .documentclasses("id") -> DocumentClass
- get -> DocumentClass(SemanthaModelEntity)
- delete -> None
- put -> DocumentClass(SemanthaModelEntity)
- documentclasses -> InnerDocumentClasses
- get -> list[DocumentClass(SemanthaModelEntity)]
- post -> DocumentClass(SemanthaModelEntity)
- referencedocuments -> InnerReferenceDocuments
- get -> list[Document(SemanthaModelEntity)]
- patch -> None
- delete -> None
- .documentcomparisons -> DocumentComparisons
- post -> not yet implemented
- .documents -> Documents
- post -> list[Document(SemanthaModelEntity)]
- .modelinstances -> ModelInstance
- .modelclasses -> ModelClass
- .referencedocuments -> ReferenceDocuments
- get -> ReferenceDocuments(SemanthaModelEntity)
- delete -> None
- post -> list[DocumentInformation(SemanthaModelEntity)]
- .clusters -> DocumentCluster
- get -> DocumentCluster(SemanthaModelEntity)
- .statistic -> Statistics
- get -> Statistic(SemanthaModelEntity)
- .namedentities -> NamedEntities
- get -> Optional[NamedEntities(SemanthaModelEntity)]
- .referencedocuments("id") -> ReferenceDocument
- get -> Document(SemanthaModelEntity)
- delete -> None
- patch -> DocumentInformation(SemanthaModelEntity)
- .paragraphs("id") -> ReferenceDocumentParagraph
- get -> Paragraph(SemanthaModelEntity)
- patch -> Paragraph(SemanthaModelEntity)
- delete -> None
- .sentences("id") -> ReferenceDocumentSentence
- get -> Sentence(SemanthaModelEntity)
- .references -> References
- post -> Document(SemanthaModelEntity)
- .settings -> DomainSettings
- get -> DomainSettings(SemanthaModelEntity)
- patch -> DomainSettings(SemanthaModelEntity)
- .similaritymatrix -> List[MatrixRow]
- .clusters -> List[MatrixRow]
- .tags -> DomainTags
- get -> list[str]
- .("tag").referencedocuments
- get
- delete
- .validation -> SemanticModel
- .documentannotations -> DocumentAnnotations
- .model
- .domains("domain_name")
- .boostwords -> Boostwords
- get -> list[Boostword(SemanthaModelEntity)]
- delete -> None
- post_word -> Boostword(SemanthaModelEntity)
- post_regex -> Boostword(SemanthaModelEntity)
- .boostwords("id") -> Boostword
- get -> Boostword(SemanthaModelEntity)
- delete -> None
- put_word -> Boostword(SemanthaModelEntity)
- put_regex -> Boostword(SemanthaModelEntity)
- .synonyms -> Synonyms
- get -> list[Synonym(SemanthaModelEntity)]
- delete -> None
- post_word -> Synonym(SemanthaModelEntity)
- post_regex -> Synonym(SemanthaModelEntity)
- .synonyms("id") -> Synonym
- get -> Synonym(SemanthaModelEntity)
- delete -> None
- put_word -> Synonym(SemanthaModelEntity)
- put_regex -> Synonym(SemanthaModelEntity)
- .datatypes -> list[str]
- .boostwords -> Boostwords
- .domains("domain_name")
- .currentuser -> CurrentUser
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for semantha_sdk-4.7.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 143fb183fd78008422fcd5d5b5dedfd7da63e1ebe68680a2d64d59e8cd5ed839 |
|
MD5 | 908e835bf113362bb676ebd55e48f322 |
|
BLAKE2b-256 | eee4dbda57122fe9e7e9cef84ae3412a080e1b22886920d67455af435078b00a |