olaf.repository.serialiser package¶
Subpackages¶
- olaf.repository.serialiser.rdf_owl_serialisers package
Submodules¶
olaf.repository.serialiser.kr_serialisers module¶
- class olaf.repository.serialiser.kr_serialisers.KRJSONSerialiser[source]¶
Bases:
object
JSON serialiser for KR objects.
- build_cos_from_strings(co_texts: Iterable[str], spacy_model: Language, docs: list[Doc]) set[Span] [source]¶
Create corpus occurrences from a set of strings label and a corpus.
Parameters¶
- co_textsIterable[str]
The strings to use for corpus occurrences extraction.
- spacy_modelspacy.language.Language
The spaCy model to retrieve the corpus occurrences.
- docslist[spacy.tokens.Doc]
The corpus in which to find the corpus occurrences.
Returns¶
- set[CandidateTerm]
The set of corpus occurrences.
- get_concepts_json(kr: KnowledgeRepresentation) list[dict[str]] [source]¶
Construct the JSON serialisation of KR concepts.
Parameters¶
- krKnowledgeRepresentation
The KR to serialise the concepts.
Returns¶
- list[dict[str]]
The serialised concepts JSON-like object.
- get_metarelations_json(kr: KnowledgeRepresentation) list[dict[str]] [source]¶
Construct the JSON serialisation of KR metarelations.
Parameters¶
- krKnowledgeRepresentation
The KR to serialise the metarelations.
Returns¶
- list[dict[str]]
The serialised metarelations JSON-like object.
- get_relations_json(kr: KnowledgeRepresentation) list[dict[str]] [source]¶
Construct the JSON serialisation of KR relations.
Parameters¶
- krKnowledgeRepresentation
The KR to serialise the relations.
Returns¶
- list[dict[str]]
The serialised relations JSON-like object.
- load(pipeline: Pipeline, file_path: PathLike) None [source]¶
Load a KR object from a JSON serialisation.
Parameters¶
- pipelinePipeline
The pipeline to use when loading the KR. It is used to access the corpus and spacy model to reconstruct the linguistic realisations.
- file_pathPathLike
The path to the file containing the JSON serialised KR object.
- load_concepts_from_json(concepts_json: list[dict[str]], concepts_idx: dict[int, Concept], pipeline: Pipeline) set[Concept] [source]¶
Load concepts from the concepts portion of the KR JSON serialisation.
Parameters¶
- concepts_jsonlist[dict[str]]
The concepts portion of the KR JSON serialisation.
- concepts_idxdict[int, Concept]
A dictionary object to store the concept index.
- pipelinePipeline
The pipeline to use for reconstructing the linguistic realisations.
Returns¶
- set[Concept]
The set of Concepts.
- load_metarelations_from_json(metarelations_json: list[dict[str]], concepts_idx: dict[int, Concept], pipeline: Pipeline) set[Metarelation] [source]¶
Load metarelations from the metarelations portion of the KR JSON serialisation.
Parameters¶
- metarelations_jsonlist[dict[str]]
The metarelations portion of the KR JSON serialisation.
- concepts_idxdict[int, Concept]
The concept index mapping concept IDs to concept instances.
- pipelinePipeline
The pipeline to use for reconstructing the linguistic realisations.
Returns¶
- set[Metarelation]
The set of metarelations.
- load_relations_from_json(relations_json: list[dict[str]], concepts_idx: dict[int, Concept], pipeline: Pipeline) set[Relation] [source]¶
Load relations from the relations portion of the KR JSON serialisation.
Parameters¶
- relations_jsonlist[dict[str]]
The relations portion of the KR JSON serialisation.
- concepts_idxdict[int, Concept]
The concept index mapping concept IDs to concept instances.
- pipelinePipeline
The pipeline to use for reconstructing the linguistic realisations.
Returns¶
- set[Relation]
The set of Relations.
- serialise(kr: KnowledgeRepresentation, file_path: PathLike) None [source]¶
Serialise the KR object into a JSON formatted file.
Parameters¶
- krKnowledgeRepresentation
The KR object to serialise.
- file_pathPathLike
The path to the file to save the serialised KR object.