Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active June 6, 2017 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/074f856a32c64e287a92b4292eb7d3c3 to your computer and use it in GitHub Desktop.
Save kenwebb/074f856a32c64e287a92b4292eb7d3c3 to your computer and use it in GitHub Desktop.
Categorical Data IDE - AQL - Employees 2
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Tue Jun 06 2017 07:56:50 GMT-0400 (EDT)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: Categorical Data IDE - AQL - Employees 2
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 074f856a32c64e287a92b4292eb7d3c3 based on 4bcedd9749d84f40195334532c3eb883 based on 3a1e678e9b98c16eb94f1763dbca5a47 (Category Theory)
Keywords:
My Notes
--------
June 1, 2017
In this workbook, I create the type of Xholon model that would be generatetd by CatAql.java in the new CatTheory mechanism.
Add "_" to end of attribute names that are Xholon keywords, such as: first_ last_ name_
The AQL file
------------
typeside Ty = literal {
types
string
nat
constants
Al Akin Bob Bo Carl Cork Dan Dunn Math CS : string
zero : nat
functions
succ : nat -> nat
plus : nat, nat -> nat
equations
forall x. plus(zero, x) = x
forall x, y. plus(succ(x),y) = succ(plus(x,y))
options
prover = completion
}
schema S = literal : Ty {
entities
Employee
Department
foreign_keys
manager : Employee -> Employee
worksIn : Employee -> Department
secretary : Department -> Employee
path_equations
manager.worksIn = worksIn
secretary.worksIn = Department
attributes
first last : Employee -> string
age : Employee -> nat
cummulative_age: Employee -> nat
name : Department -> string
observation_equations
forall e. cummulative_age(e) = plus(age(e), age(manager(e)))
options
prover = completion
}
instance I = literal : S {
generators
a b c : Employee
m s : Department
equations
first(a) = Al
first(b) = Bob last(b) = Bo
first(c) = Carl
name(m) = Math name(s) = CS
age(a) = age(c)
manager(a) = b manager(b) = b manager(c) = c
worksIn(a) = m worksIn(b) = m worksIn(c) = s
secretary(s) = c secretary(m) = b
secretary(worksIn(a)) = manager(a)
worksIn(a) = worksIn(manager(a))
age(a) = zero.succ.succ
age(manager(a)) = zero.succ
options
prover = completion
completion_precedence = "zero a b c m s Al Akin Bob Bo Carl Cork Dan Dunn Math CS first last name age manager worksIn secretary succ plus"
}
]]></Notes>
<_-.XholonClass>
<CatTheorySystem/>
<!-- typeside types -->
<string/>
<nat/>
<strings/>
<nats/>
<!-- schema entities -->
<Employee/>
<Department/>
<Employees/>
<Departments/>
<!-- check the Schema after everything has been loaded and configured -->
<AqlSchemaChecker/>
</_-.XholonClass>
<xholonClassDetails>
<Employee xhType="XhtypePureActiveObject"/>
<Employees xhType="XhtypePureActiveObject">
<!-- AQL foreign_keys -->
<port name="manager" connector="."/>
<port name="worksIn" connector="../Departments"/>
<!-- AQL attributes -->
<port name="first_" connector="../strings"/>
<port name="last_" connector="../strings"/>
<port name="age" connector="../nats"/>
</Employees>
<Department xhType="XhtypePureActiveObject"/>
<Departments xhType="XhtypePureActiveObject">
<port name="secretary" connector="../Employees"/>
<port name="name_" connector="../strings"/>
</Departments>
</xholonClassDetails>
<CatTheorySystem>
<Employees>
<Employee roleName="a" first_="Al" age="2">
<port name="manager" connector="../Employee[@roleName='b']"/>
<port name="worksIn" connector="../Department[@roleName='m']"/>
</Employee>
<Employee roleName="b" first_="Bob" last_="Bo">
<port name="manager" connector="../Employee[@roleName='b']"/>
<port name="worksIn" connector="../../Departments/Department[@roleName='m']"/>
</Employee>
<Employee roleName="c" first_="Carl" age="2">
<port name="manager" connector="../Employee[@roleName='c']"/>
<port name="worksIn" connector="../../Departments/Department[@roleName='s']"/>
</Employee>
</Employees>
<Departments>
<Department roleName="m" name_="Math">
<port name="secretary" connector="../../Employees/Employee[@roleName='b']"/>
</Department>
<Department roleName="s" name_="CS">
<port name="secretary" connector="../../Employees/Employee[@roleName='c']"/>
</Department>
</Departments>
<strings/>
<nats/>
<AqlSchemaChecker/>
<!-- TESTING
I've put each statement on its own line, where possible.
-->
<CatAql><![CDATA[
typeside Ty = literal {
types
string
nat
constants
Al Akin Bob Bo Carl Cork Dan Dunn Math CS : string
zero : nat
functions
succ : nat -> nat
plus : nat, nat -> nat
equations
forall x. plus(zero, x) = x
forall x, y. plus(succ(x),y) = succ(plus(x,y))
options
prover = completion
}
schema S = literal : Ty {
entities
Employee
Department
Dummy
foreign_keys
manager : Employee -> Employee
worksIn : Employee -> Department
secretary : Department -> Employee
junk : Dummy -> Employee
path_equations
manager.worksIn = worksIn
secretary.worksIn = Department
attributes
first last : Employee -> string
age : Employee -> nat
cummulative_age : Employee -> nat
name : Department -> string
observation_equations
forall e. cummulative_age(e) = plus(age(e), age(manager(e)))
options
prover = completion
}
instance I = literal : S {
generators
a b c : Employee
m s : Department
equations
first(a) = Al
first(b) = Bob
last(b) = Bo
first(c) = Carl
name(m) = Math
name(s) = CS
// age(a) = age(c)
manager(a) = b
manager(b) = b
manager(c) = c
worksIn(a) = m
worksIn(b) = m
worksIn(c) = s
secretary(s) = c
secretary(m) = b
// secretary(worksIn(a)) = manager(a)
// worksIn(a) = worksIn(manager(a))
// age(a) = zero.succ.succ
// age(manager(a)) = zero.succ
options
prover = completion
completion_precedence = "zero a b c m s Al Akin Bob Bo Carl Cork Dan Dunn Math CS first last name age manager worksIn secretary succ plus"
}
]]></CatAql>
</CatTheorySystem>
<AqlSchemaCheckerbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
// check foreign keys, path equations, and equations
var me, beh = {
postConfigure: function() {
me = this.cnode.parent();
me.println(me.xhc().name());
var node = me.parent().first();
while (node) {
switch (node.xhc().name()) {
case "Employee":
var links = node.links(false, true);
$wnd.console.log(links);
for (var i = 0; i < links.length; i++) {
var link = links[i];
var rnode = link.reffedNode;
if (rnode) {
switch (link.fieldName) {
case "manager":
// manager : Employee -> Employee
this.checkForeigKeyType("manager : Employee -> Employee ", rnode, "Employee");
// foreign_keys manager.worksIn = worksIn
me.println("manager.worksIn = worksIn " + (node.manager.worksIn == node.worksIn));
break;
case "worksIn":
// worksIn : Employee -> Department
this.checkForeigKeyType("worksIn : Employee -> Department ", rnode, "Department");
// equations secretary(worksIn(a)) = manager(a)
me.println("secretary(worksIn(a)) = manager(a) " + (node.worksIn.secretary == node.manager));
break;
default: break;
}
}
}
break;
case "Department":
var links = node.links(false, true);
$wnd.console.log(links);
for (var i = 0; i < links.length; i++) {
var link = links[i];
var rnode = link.reffedNode;
if (rnode) {
switch (link.fieldName) {
case "secretary":
// foreign_keys secretary : Department -> Employee
this.checkForeigKeyType("secretary : Department -> Employee ", rnode, "Employee");
// path_equation secretary.worksIn = Department
me.println("secretary.worksIn = Department " + (node.secretary.worksIn.xhc().name() == "Department"));
break;
default: break;
}
}
}
break;
default: break;
}
node = node.next();
}
},
checkForeigKeyType: function(label, node, expectedTypeName) {
me.println(label + (node.xhc().name() == expectedTypeName));
}
}
]]></AqlSchemaCheckerbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Employee</title>
<rect id="PhysicalSystem/Employee" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>AqlSchemaChecker</title>
<rect id="PhysicalSystem/AqlSchemaChecker" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment