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.
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.
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.
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.
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?
Entityis a base Prototype with aNameproperty, acting as a root for all entities.Locationinherits fromEntity, adding anAddressproperty.Personinherits fromEntity, defining properties forGender,Location,ParentOf,Spouse, andAge, 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, andSimpsonsHouseare linked via edges (Spouse,Location,ParentOf), forming a network of relationships.
Syntax Notes:
- Use lowercase
string,bool,intfor 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". Collectionrepresents lists (e.g.,ParentOf), matching document conventions.
The Simpsons model forms a graph-based ontology:
- Classes:
Entity,Location,Personact as conceptual classes, like OWL classes, but are dynamic Prototypes. - Individuals:
Homer,Marge,SimpsonsHouseare instances, akin to RDF individuals, linked via properties. - Properties:
Spouse,ParentOf,Locationare 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.
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?
IsParentchecks if aPersonhas children by countingParentOfentries.LivesInSpringfielduses the->operator to verify if theLocation’sNameis"Springfield".- Usage:
Homer.IsParent()returnstrue,Homer.LivesInSpringfield()returnstrue(ifSimpsonsHouselinks toSpringfield). - Graph View:
IsParenttraversesParentOfedges,LivesInSpringfieldfollowsLocationto checkName. - Queries use structural traversal rather than OWL-style axiomatic reasoning.
The graph enables discovery of relationships:
- Family Structure:
Homer.ParentOfandMarge.ParentOfboth link toBart,Lisa,Maggie, revealing shared parenthood. - Location-Based Grouping: Querying
Personnodes withLocation = SimpsonsHouseidentifies residents (Homer, Marge, Bart, Lisa, Maggie). - Spousal Symmetry:
Homer.Spouse = MargeandMarge.Spouse = Homerform 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?
GetChildrenNamescollectsNameproperties fromParentOfnodes.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.
The Simpsons ontology can integrate with other domains:
- Database Integration: Link
Personto a database tableResidentswith columnsName,Gender,Age, mappingHomer.Nameto 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
Personnodes, leveraging the ontology. - The transformation unifies NLP and graph querying without relying on OWL-specific processing pipelines.
- What’s Happening?: The function maps a natural language question to a list of
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.
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.
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