dasch-swiss / knora-ui

Reusable GUI elements for Knora
https://dasch-swiss.github.io/knora-ui
7 stars 1 forks source link

Design Documentation for OntologyCache Service #83

Open tobiasschweizer opened 5 years ago

tobiasschweizer commented 5 years ago

OntologyCacheService

Scope

The service OntologyCacheService requests ontology entity definitions from Knora and caches them. The service works with the Knora v2 complex API.

Whenever resource class Iris or property Iris (entity definitions) have to be resolved, this service can be used. Entity definitions are contained in responses returned by the Knora v2 complex API, e.g., when doing a full resource request or a search.

Methods

OntologyInformation

Whenever entity definitions are requested, an instance of OntologyInformation is returned. OntologyInformation contains only the information requested, also if more information is cached.

Reading information

OntologyInformation offers methods to access this information:

Updating information

When doing a search, results have to be fetched by page by page. With each new page, unknown entity Iris may have to be resolved. The new information can be attached to the existing information using the method updateOntologyInformation(ontologyInfo: OntologyInformation): void. Just call this method on the existing instance of OntologyInformation, passing the OntologyInformation obtained.

tobiasschweizer commented 5 years ago

Design

OntologyCache

Whenever information is requested from OntologyCacheService, the information will be returned from the cache or requested from Knora and cached. OntologyCacheService holds a single instance of OntologyCache containing all the cached information. This instance is never exposed to the outside but only used internally. Requested information will be sent back as an instance of OntologyInformation.

Requesting information from Knora

Whenever information is requested from Knora, whole ontologies are requested. Given the Iri of a resource class or a property, the ontology it belongs to can be determined automatically and requested from Knora.

OntologyService performs the actual HTTP requests to Knora and returns the result to OntologyCacheService as JSON-LD. OntologyCacheService takes care of processing the JSON-LD and expand the Iris.

Writing to the cache

Whenever information is requested that is not cached already, the information is requested from Knora, written to the cache and then served from the cache. This last steps works the same way when already cached information is served.

Properties from other ontologies

When a definition of a resource class is requested that has cardinalities for properties that are defined in another ontology, that ontology is requested from Knora and cached automatically by OntologyCacheService. With a resource definitions, the definitions for all properties the resource class has cardinalities for are served too.

This works in a hierarchical way: getResourceClassDefinitions is called when calling getEntityDefinitionsForOntologies and getResourceClassDefinitions calls getPropertyDefinitions.

tobiasschweizer commented 5 years ago

@flavens @kilchenmann @andreas-aeschlimann Could you give me a feedback if this is good enough? Is there anything unclear or missing?

flavens commented 5 years ago

@tobiasschweizer I do not really understand §"Writing to the cache"

tobiasschweizer commented 5 years ago

I do not really understand §"Writing to the cache"

"Writing to the cache" means that the information obtained from Knora is stored in an instance of OntologyCache. Every time new information is queried, it is added.

OntologyCacheService holds a single instance of OntologyCache (cacheOntology).

tobiasschweizer commented 5 years ago

Dependency: OntologyService