swift-hoot

0.2.0

Swift implementation of HOOT (Hierarchical Ontology-Optimized Tokens)
hoot-format/swift-hoot

What's New

swift-hoot v0.2.0

2026-02-14T08:58:08Z

swift-hoot v0.2.0

New Features

  • Default prefix optimization — compact mode で非標準プレフィックスが1つだけの場合、自動的にデフォルトプレフィックス(空文字)に変換。これにより全 IRI から冗長なプレフィックス名を除去し、トークン数を削減。

    Before: ex:Person, ex:Organization, ex:locatedIn
    After: :Person, :Organization, :locatedIn

  • HootDocument.usingDefaultPrefix(_:) — 任意の名前付きプレフィックスをデフォルトプレフィックスに変換する public API

Tests

157 tests (+8 new: default prefix conversion)

swift-hoot

Swift implementation of HOOT (Hierarchical Ontology-Optimized Tokens).

Installation

// swift-tools-version: 6.2
dependencies: [
    .package(url: "https://github.com/hoot-format/swift-hoot.git", branch: "main"),
],
targets: [
    .target(dependencies: [
        .product(name: "Hoot", package: "swift-hoot"),
    ]),
]

Usage

import Hoot

let doc = HootDocument(
    prefixes: [HootPrefix(name: "ex", iri: "http://example.org/")],
    sections: [
        .classHierarchy(HootClassHierarchy(
            root: "owl:Thing",
            classes: [
                HootClass(iri: "ex:Person", label: "Person", children: [
                    HootClass(iri: "ex:Politician", label: "Politician"),
                ]),
            ]
        )),
        .tabular(HootTabularSection(
            name: "ObjectProperty",  // Encoded as "->"
            fields: ["iri", "label", "inverse"],
            rows: [
                ["ex:partOf", "part of", "ex:hasPart"],
            ]
        )),
    ]
)

// Lossless (round-trip with Turtle)
let lossless = HootEncoder(mode: .lossless).encode(doc)

// Compact (minimum tokens)
let compact = HootEncoder(mode: .compact).encode(doc)

Lossless output:

@ex //example.org

class owl:Thing
 ex:Person "Person"
  ex:Politician "Politician"

->{iri,label,inverse}:
 ex:partOf,part of,ex:hasPart

API

HootDocument

HootDocument(prefixes: [HootPrefix], sections: [HootSection])

HootSection

Case Type Description
.classHierarchy HootClassHierarchy OWL class hierarchy
.tabular HootTabularSection ObjectProperty, DataProperty, etc.
.disjoint HootDisjointSection Disjoint class sets
.subjectBlock HootSubjectBlock General-purpose triples

HootValue

Case Example
.iri("ex:Person") IRI reference
.literal("text", datatype: "xsd:string") Typed literal
.literal("hello", language: "en") Language-tagged literal
.number("42") Numeric literal
.boolean(true) Boolean literal
.blankNode("b0") Blank node reference
.inlineBlankNode([...]) Anonymous blank node
.collection([...]) RDF collection

HootEncoder

let encoder = HootEncoder(mode: .lossless)  // or .compact
let output = encoder.encode(document)

Requirements

  • Swift 6.2+
  • No external dependencies

License

MIT

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

Last updated: Fri Apr 10 2026 16:30:52 GMT-0900 (Hawaii-Aleutian Daylight Time)