A TypeScript translation of the Foundation ontology - a comprehensive framework for modeling entities, events, and temporal relationships.
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
npm install foundation-tsThe 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;
}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
}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;
}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;
}Collections of entities that share common characteristics.
import { Class, UniquelyIdentifiable } from 'foundation-ts';
interface PeopleClass extends Class<Person> {
getMembers(): Set<Person>;
getIdentifier(): string;
}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
}Built-in support for temporal calculations and validation:
const duration = meeting.duration(); // Returns duration in milliseconds
const range = person.range(); // Returns min/max duration rangeSupport 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
}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
}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");
}
}
}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
}
}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;
}
}UniquelyIdentifiable- Base interface for all entitiesTimePeriod- Entities with temporal boundariesEvent- Significant occurrences and transitionsEventBounded- Entities bounded by eventsIndividual- Single entities with temporal existenceClass- Collections of related entitiesState- Temporal parts of individualsActivity- Partially ordered sets of actions
Property- Sets of entities with common propertiesScalarProperty- Numeric properties with unitsAttribute- Property values applied to individuals over timeScalarAttribute- Numeric attributes with units
Unit- Units of measureScalarValue- Numeric values with units
Aggregate- Quantities of similar thingsAgglomerate- Arbitrary collections of objectsPossibleWorld- Sets of individuals in scenarios
Range<T>- Represents uncertainty over values
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
MIT License - see LICENSE file for details.
Tony Walmsley - Original Java ontology author