Skip to content

loopwork-ai/Ontology

Repository files navigation

Ontology

A Swift library for working with structured data. This library provides JSON-LD serializable types that can represent entities from various vocabularies, with a focus on Schema.org. It includes convenience initializers for types from Apple frameworks, like Contacts and EventKit.

Requirements

  • Swift 6.0+ / Xcode 16+
  • macOS 14.0+ (Sonoma)
  • iOS 17.0+

Installation

Swift Package Manager

Add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/loopwork-ai/ontology.git", from: "0.2.0")
]

Supported Types

Schema.org Vocabulary

Supported Schema.org types and their Apple framework equivalents:

Schema.org Type Apple Framework Type Description
ContactPoint CNInstantMessageAddress Represents a method of contact like instant messaging
DateTime Date Represents a date and time with ISO 8601 formatting
Event EKEvent Represents an event with start/end dates, location, etc.
Organization CNContact Represents an organization with properties like name and contact info
Person CNContact Represents a person with properties like name, contact info, and relationships
PlanAction EKReminder Represents a planned action or task with properties like name, description, due date, and completion status
PostalAddress CNPostalAddress Represents a physical address with street, city, region, etc.

Weather.gov API Vocabulary

Additional types supporting the National Weather Service API:

Weather.gov Type Description
WeatherForecast Represents detailed weather forecast data including temperature, precipitation probability, and wind information

Usage

Creating objects and encoding as JSON-LD

import Ontology

// Create a Person
var person = Person()
person.givenName = "John"
person.familyName = "Doe"
person.email = ["john.doe@example.com"]

// Create an organization
var organization = Organization()
organization.name = "Example Corp"

// Associate person with organization
person.worksFor = organization

// Encode to JSON-LD
let encoder = JSONEncoder()
let jsonData = try encoder.encode(person)
print(String(data: jsonData, encoding: .utf8)!)

// Output:
// {
//   "@context": "https://schema.org",
//   "@type": "Person",
//   "givenName": "John",
//   "familyName": "Doe"
// }

Initializing from Apple framework types

import Ontology
import Contacts

// Convert from Apple's CNContact to Schema.org Person
let contact = CNMutableContact()
contact.givenName = "Jane"
contact.familyName = "Smith"
contact.emailAddresses = [
    CNLabeledValue(label: CNLabelHome, 
                   value: "jane.smith@example.com" as NSString)
]

// Convert to Schema.org Person
let person = Person(contact)

License

This project is licensed under the Apache License, Version 2.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages