TermSerializer

A Serializer of Terms, e.g. to persist a knowledge base fact or a query solution to disk, or to send it to another process (or another tool, possibly written in another language) as JSON, YAML, or XML. Internally, a TermSerializer typically converts the Term into a plain object via TermObjectifier and then writes that object in the requested MimeType.

Usage example:

val serializer: TermSerializer = TermSerializer.of(MimeType.Json)
val term: Term = Struct.of("f", Atom.of("hello"), Integer.of(2))
val json: String = serializer.serialize(term) // {"fun":"f","args":["hello",2]}

See also

for the inverse operation.

A JVM-only WritingTermSerializer variant writes directly to a java.io.Writer.

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val mimeType: MimeType

The textual format this serializer produces.

Functions

Link copied to clipboard
abstract fun serialize(value: Term): String

Serializes a single value into its textual representation in mimeType.

Link copied to clipboard
abstract fun serializeMany(values: Iterable<Term>): String
open fun serializeMany(values: Sequence<Term>): String
open fun serializeMany(vararg values: Term): String

Serializes several values into a single textual representation of all of them.