Skip to content

Latest commit

 

History

History
225 lines (173 loc) · 11.5 KB

File metadata and controls

225 lines (173 loc) · 11.5 KB

Simpsons Example for Prototype Modeling

ProtoScript’s Prototypes excel at modeling real-world entities and relationships within a dynamic, graph-based ontology, offering a flexible alternative to traditional ontologies like OWL or RDF. This section uses the fictional dataset from The Simpsons to demonstrate how ProtoScript creates an ontology-like structure to represent characters, locations, and their interconnections. By modeling entities such as Homer, Marge, and the Simpsons’ house as Prototypes, we illustrate how ProtoScript’s unified graph framework captures complex relationships (e.g., family ties, locations) with ease, supports runtime adaptability, and enables reasoning through structural patterns. This example highlights ProtoScript’s ability to go beyond traditional ontologies, which often rely on static schemas and formal axioms, by providing a developer-friendly, dynamic approach to knowledge representation.

Why This Example Matters

The Simpsons dataset is relatable and rich with relationships, making it an ideal case study for demonstrating ProtoScript’s ontology capabilities:

  • Real-World Modeling: Characters (e.g., Homer, Marge) and locations (e.g., Springfield) form a network of relationships, mirroring real-world ontologies like geographic or social systems.
  • Dynamic Ontology: ProtoScript’s Prototypes allow runtime modifications (e.g., adding new relationships), unlike OWL’s rigid class hierarchies.
  • Cross-Domain Potential: The model can integrate with other domains (e.g., linking characters to a database or natural language queries), showcasing ProtoScript’s versatility.
  • Reasoning and Relationships: The graph enables discovery of relationships (e.g., family structures) and transformations (e.g., generating queries about characters).

ProtoScript’s Prototypes support runtime evolution, unify different entity types under a single construct, and rely on structural generalization for reasoning, offering a practical contrast to OWL’s static schemas and formal axioms.

Analogy to Familiar Concepts

For C# developers:

  • Prototypes are like classes that can represent people, places, or relationships in a graph, similar to an ORM mapping objects to a database but with dynamic, graph-based flexibility.
  • Think of this as building a social network model where objects (characters) link to others (locations, family) in a graph database.

For JavaScript developers:

  • Prototypes resemble JavaScript objects in a graph, where each object (e.g., Homer) can inherit from multiple prototypes and link to others, like a JSON-based knowledge graph.

For database developers:

  • The ontology is like a graph database where nodes (Prototypes) represent entities and edges (properties) define relationships, but with programmable behaviors via functions.

Modeling The Simpsons Ontology

This example models key characters (Homer, Marge, Bart) and locations (Simpsons’ house, Springfield) from The Simpsons, demonstrating how ProtoScript creates a graph-based ontology. We’ll define Prototypes, establish relationships, and show how the model supports querying and reasoning.

Prototype Definitions

Below is ProtoScript code to model the Simpsons ontology using canonical syntax (lowercase string for literals and direct literal initializers).

prototype Entity {
string Name = "";
}
prototype Location : Entity {
string Address = "";
}
prototype Person : Entity {
string Gender = "";
Location Location = new Location();
Collection ParentOf = new Collection();
Person Spouse = new Person();
int Age = 0;
}
prototype SimpsonsHouse : Location {
Name = "Simpsons House";
Address = "742 Evergreen Terrace";
}
prototype Springfield : Location {
Name = "Springfield";
Address = "Unknown";
}
prototype Homer : Person {
Name = "Homer Simpson";
Gender = "Male";
Location = SimpsonsHouse;
ParentOf = [Bart, Lisa, Maggie];
Spouse = Marge;
Age = 39;
}
prototype Marge : Person {
Name = "Marge Simpson";
Gender = "Female";
Location = SimpsonsHouse;
ParentOf = [Bart, Lisa, Maggie];
Spouse = Homer;
Age = 36;
}
prototype Bart : Person {
Name = "Bart Simpson";
Gender = "Male";
Location = SimpsonsHouse;
Age = 10;
}
prototype Lisa : Person {
Name = "Lisa Simpson";
Gender = "Female";
Location = SimpsonsHouse;
Age = 8;
}
prototype Maggie : Person {
Name = "Maggie Simpson";
Gender = "Female";
Location = SimpsonsHouse;
Age = 1;
}

What’s Happening?

  • Entity is a base Prototype with a Name property, acting as a root for all entities.
  • Location inherits from Entity, adding an Address property.
  • Person inherits from Entity, defining properties for Gender, Location, ParentOf, Spouse, and Age, using lowercase types (string, int) with direct literals.
  • Specific instances (Homer, Marge, Bart, SimpsonsHouse) set literal values (e.g., "Male", 39), which the runtime translates to NativeValuePrototypes.
  • Relationships are established via properties (e.g., Homer.Spouse = Marge, Homer.ParentOf = [Bart, Lisa, Maggie]).
  • Graph View: Nodes for Homer, Marge, and SimpsonsHouse are linked via edges (Spouse, Location, ParentOf), forming a network of relationships.

Syntax Notes:

  • Use lowercase string, bool, int for primitive types with direct literals (e.g., "Homer Simpson", 39).
  • Avoid constructor-style wrappers for primitives unless explicitly needed, aligning with examples like string Name = "Buffalo".
  • Collection represents lists (e.g., ParentOf), matching document conventions.

Ontology Structure

The Simpsons model forms a graph-based ontology:

  • Classes: Entity, Location, Person act as conceptual classes, like OWL classes, but are dynamic Prototypes.
  • Individuals: Homer, Marge, SimpsonsHouse are instances, akin to RDF individuals, linked via properties.
  • Properties: Spouse, ParentOf, Location are edges, similar to OWL object properties, but support runtime additions and cycles (e.g., Homer.Spouse ↔ Marge.Spouse).
  • Reasoning: The graph enables structural queries (e.g., finding all parents) without formal axioms.

ProtoScript models can add properties at runtime (e.g., introducing an Occupation property to Person), use the same prototype construct for characters and locations, and integrate with external data sources such as databases.

Querying the Ontology

ProtoScript’s graph model supports querying relationships using functions and operators:

prototype Person {
string Gender = "";
Location Location = new Location();
Collection ParentOf = new Collection();
Person Spouse = new Person();
int Age = 0;
function IsParent() : bool {
return ParentOf.Count > 0;
}
function LivesInSpringfield() : bool {
return Location -> Location { this.Name == "Springfield" };
}
}

What’s Happening?

  • IsParent checks if a Person has children by counting ParentOf entries.
  • LivesInSpringfield uses the -> operator to verify if the Location’s Name is "Springfield".
  • Usage: Homer.IsParent() returns true, Homer.LivesInSpringfield() returns true (if SimpsonsHouse links to Springfield).
  • Graph View: IsParent traverses ParentOf edges, LivesInSpringfield follows Location to check Name.
  • Queries use structural traversal rather than OWL-style axiomatic reasoning.

Discovering Relationships

The graph enables discovery of relationships:

  • Family Structure: Homer.ParentOf and Marge.ParentOf both link to Bart, Lisa, Maggie, revealing shared parenthood.
  • Location-Based Grouping: Querying Person nodes with Location = SimpsonsHouse identifies residents (Homer, Marge, Bart, Lisa, Maggie).
  • Spousal Symmetry: Homer.Spouse = Marge and Marge.Spouse = Homer form a bidirectional relationship, modeled naturally as a cycle.

Example Function:

prototype Person {
Collection ParentOf = new Collection();
function GetChildrenNames() : Collection {
Collection names = new Collection();
foreach (Person child in ParentOf) {
names.Add(child.Name);
}
return names;
}
}

What’s Happening?

  • GetChildrenNames collects Name properties from ParentOf nodes.
  • Homer.GetChildrenNames() returns a collection with "Bart Simpson", "Lisa Simpson", "Maggie Simpson".
  • The dynamic query uses ProtoScript’s native graph traversal instead of predefined SPARQL queries.

Cross-Domain Transformations

The Simpsons ontology can integrate with other domains:

  • Database Integration: Link Person to a database table Residents with columns Name, Gender, Age, mapping Homer.Name to a record.

Natural Language: Transform a query like "Who lives in Springfield?" into a ProtoScript function:
prototype Query {
string Question = "";
function ToPersonList() : Collection {
Collection people = new Collection();
if (Question == "Who lives in Springfield?") {
foreach (Person p in AllPersons) {
if (p.LivesInSpringfield()) {
people.Add(p);
}
}
}
return people;
}
}

    • What’s Happening?: The function maps a natural language question to a list of Person nodes, leveraging the ontology.
    • The transformation unifies NLP and graph querying without relying on OWL-specific processing pipelines.

Internal Mechanics

The Simpsons ontology operates within ProtoScript’s graph-based runtime:

  • Nodes: Prototypes (Homer, SimpsonsHouse) are nodes with unique IDs.
  • Edges: Properties (Spouse, ParentOf, Location) create edges, including cycles (e.g., Homer ↔ Marge).
  • Runtime: Translates literals (e.g., "Male", 39) to NativeValuePrototypes, manages instantiation, and supports traversal.
  • Querying: Functions and operators (->, typeof) traverse the graph to evaluate relationships.

Why This Example Matters

The Simpsons ontology showcases ProtoScript’s strengths:

  • Dynamic Modeling: Prototypes capture complex relationships (family, location) with runtime flexibility, surpassing OWL’s static schemas.
  • Unified Framework: The same constructs model characters and locations, simplifying development compared to ontology-specific tools.
  • Relationship Discovery: The graph reveals family structures and location-based groupings naturally.
  • Cross-Domain Potential: The model supports integration with databases or NLP, enabling transformations like query generation.
  • Developer-Friendly: C#-like syntax makes ontology creation accessible to developers, not just ontology experts.

Moving Forward

This Simpsons example demonstrates how ProtoScript’s Prototypes create a dynamic, graph-based ontology that models real-world entities with ease and flexibility. Next: Relationships in ProtoScript, covering the taxonomy of associations and computed links that power connectivity.


Previous: Examples of Prototype Creation | Next: Relationships in ProtoScript