Skip to content

twalmsley/FoundationTS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FoundationTS

A TypeScript translation of the Foundation ontology - a comprehensive framework for modeling entities, events, and temporal relationships.

Overview

FoundationTS provides a type-safe, object-oriented approach to modeling complex domains with temporal aspects. It's particularly useful for:

  • Modeling entities with temporal existence
  • Representing events and their relationships
  • Managing collections and classifications
  • Handling quantitative properties and measurements
  • Modeling possible worlds and scenarios

Installation

npm install foundation-ts

Core Concepts

UniquelyIdentifiable

The base interface for all entities in the ontology. Every entity must have a unique identifier.

import { UniquelyIdentifiable } from 'foundation-ts';

interface Person extends UniquelyIdentifiable {
  getIdentifier(): string; // e.g., "person-123"
  getName(): string;
}

TimePeriod

Represents entities with temporal boundaries.

import { TimePeriod } from 'foundation-ts';

interface Meeting extends TimePeriod {
  getFrom(): Date | null; // Start time
  getTo(): Date | null;   // End time
  duration(): number | null; // Duration in milliseconds
}

Event

Significant occurrences that mark transitions or changes.

import { Event } from 'foundation-ts';

interface BirthEvent extends Event {
  getFrom(): Date; // When the birth occurred
  getTo(): Date;   // Same as from for instantaneous events
  getIdentifier(): string;
}

Individual

Entities that exist as single things with temporal boundaries.

import { Individual, Event } from 'foundation-ts';

interface Person extends Individual<BirthEvent, DeathEvent> {
  getBeginning(): BirthEvent;
  getEnding(): DeathEvent;
  getIdentifier(): string;
}

Class

Collections of entities that share common characteristics.

import { Class, UniquelyIdentifiable } from 'foundation-ts';

interface PeopleClass extends Class<Person> {
  getMembers(): Set<Person>;
  getIdentifier(): string;
}

Key Features

Type Safety

All interfaces use TypeScript generics to ensure type safety:

// Type-safe event boundaries
interface Car extends Individual<ManufacturedEvent, ScrappedEvent> {
  // Car can only be bounded by manufacturing and scrapping events
}

Temporal Reasoning

Built-in support for temporal calculations and validation:

const duration = meeting.duration(); // Returns duration in milliseconds
const range = person.range(); // Returns min/max duration range

Quantitative Properties

Support for measurements with units:

import { ScalarValue, Unit } from 'foundation-ts';

interface Weight extends ScalarValue<number, WeightUnit> {
  getValue(): number; // e.g., 75
  getUnit(): WeightUnit; // e.g., kilograms
}

Possible Worlds

Model alternative scenarios and hypothetical situations:

import { PossibleWorld, Event } from 'foundation-ts';

interface AlternativeScenario extends PossibleWorld<CreatedEvent, DeletedEvent> {
  getParts(): Set<Individual<any, any>>; // Entities in this scenario
}

Usage Examples

Creating a Simple Entity

import { UniquelyIdentifiable, TimePeriod } from 'foundation-ts';

class Project implements UniquelyIdentifiable, TimePeriod {
  constructor(
    private id: string,
    private startDate: Date,
    private endDate: Date
  ) {}

  getIdentifier(): string {
    return this.id;
  }

  getFrom(): Date | null {
    return this.startDate;
  }

  getTo(): Date | null {
    return this.endDate;
  }

  duration(): number | null {
    return this.endDate.getTime() - this.startDate.getTime();
  }

  ensureValid(from: Date | null, to: Date | null): void {
    if (from && to && from.getTime() > to.getTime()) {
      throw new Error("Start date must be before end date");
    }
  }
}

Modeling Events

import { Event } from 'foundation-ts';

class ProjectStartedEvent implements Event {
  constructor(
    private id: string,
    private timestamp: Date
  ) {}

  getIdentifier(): string {
    return this.id;
  }

  getFrom(): Date | null {
    return this.timestamp;
  }

  getTo(): Date | null {
    return this.timestamp; // Instantaneous event
  }

  duration(): number | null {
    return 0; // Instantaneous
  }

  ensureValid(from: Date | null, to: Date | null): void {
    // Validation logic
  }
}

Working with Collections

import { Class, UniquelyIdentifiable } from 'foundation-ts';

class ProjectTeam implements Class<Person> {
  constructor(
    private id: string,
    private members: Set<Person>
  ) {}

  getIdentifier(): string {
    return this.id;
  }

  getMembers(): Set<Person> {
    return this.members;
  }
}

API Reference

Foundation Interfaces

  • UniquelyIdentifiable - Base interface for all entities
  • TimePeriod - Entities with temporal boundaries
  • Event - Significant occurrences and transitions
  • EventBounded - Entities bounded by events
  • Individual - Single entities with temporal existence
  • Class - Collections of related entities
  • State - Temporal parts of individuals
  • Activity - Partially ordered sets of actions

Property and Attribute Interfaces

  • Property - Sets of entities with common properties
  • ScalarProperty - Numeric properties with units
  • Attribute - Property values applied to individuals over time
  • ScalarAttribute - Numeric attributes with units

Measurement Interfaces

  • Unit - Units of measure
  • ScalarValue - Numeric values with units

Collection Interfaces

  • Aggregate - Quantities of similar things
  • Agglomerate - Arbitrary collections of objects
  • PossibleWorld - Sets of individuals in scenarios

Utility Classes

  • Range<T> - Represents uncertainty over values

Contributing

This is a TypeScript translation of the original Java Foundation ontology. Contributions are welcome to:

  • Add missing event types
  • Improve type definitions
  • Add utility functions
  • Enhance documentation
  • Add tests

License

MIT License - see LICENSE file for details.

Author

Tony Walmsley - Original Java ontology author

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published