def r_owner_can_action(action): """ The owner of a content can perform the given action on the content """ kb.tell( Rule([ Fact(Person('P1'), Wants(to=action(what=Content('C1'))), Instant('I1')), Fact(Person('P1'), Owns(what=Content('C1')), Duration('T1')), During('I1','T1') ],[ Fact(Person('P1'), action(what=Content('C1')), Instant('I1'))]))
subject = Person mods = {'what': Content,} # If someone hides some content, it stops having any previous state and has private r17 = Rule([ Fact(Person('Person1'), Hide(what=Content('Content1')), Instant('Instant1')), Fact(Content('Content1'), Has(what=public), Duration('Duration1')), During(Instant('Instant1'), Duration('Duration1')) ],[ Finish('Duration1', 'Instant1'), Fact(Content('Content1'), Has(what=private), Duration(start=Instant('Instant1')))]) # if a person is the owner of some content, she can hide it r18 = Rule([ Fact(Person('Person1'), Is_owner(of=Content('Content1')), Duration('Duration1')) ],[ Fact(Person('Person1'), Can(what=Hide(what=Content('Content1'))), Duration('Duration1'))]) # manage_perm is needed to hide anything r19 = Rule([ Fact(Content('Content1'), Has(what=public), Duration('Duration1')) ],[ Fact(manage_perm, Is_needed(for_action=Hide(what=Content('Content1'))), Duration('Duration1'))]) # enter everything into the database kb.tell(admin, member, manager, basic_perm, manage_perm, create_perm, public, private, p1, p2, r10, r1, r2, r3, r4, r5, r6, r7, r9, r12, r13, r14, r15, r16, r17, r18, r19)
def p_role_has_perm(role, perm): """ Role role has permission perm from now on """ kb.tell( Fact(role, Has(what=perm), Duration(start='now')) )
def r_workflow_for_content(content_type, workflow, context): """ assign workflow to content_type in context """ kb.tell( Fact(workflow, Assigned(to=content_type, where=context), Duration(start=Instant('now'))))
def r_transition(action, workflow, initial, final): """ """ kb.tell( Fact(workflow, HasTransition(start=initial, end=final, by=action), Duration(start='now', end='now')) )
def r_permission(action, status, perm): """ """ kb.tell( Fact(perm, Required(to=action, over=status), Duration(start='now', end='now')) )
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with ln. If not, see <http://www.gnu.org/licenses/>. from nl.log import logger from nl import (Noun, Verb, Number, Thing, Exists, Fact, Rule, Subword, Duration, Instant, During, Coincide, Intersection, Finish, MinComStart, MaxComEnd, kb) from people import Person from modality import Wants, Can, Must admin = Person('admin') kb.tell(admin) anonymous = Person('anonymous') kb.tell(anonymous) class Role(Thing): """ The name role, for roles that can be had in contexts by people, and have some associated permissions """ member = Role('member') kb.tell(member) editor = Role('editor') kb.tell(editor)
p4 = Fact(c2, Has_position(x=0, y=100), 1) p5 = Fact(c1, Has_speed(x=-2, y=0), 1) p6 = Fact(c2, Has_speed(x=2, y=0), 1) p7 = Fact(c1, Has_acceleration(x=0, y=0), 1) p8 = Fact(c2, Has_acceleration(x=0, y=0), 1) p9 = Fact(c1, Is_forced(x=0, y=0), 1) p10 = Fact(c2, Is_forced(x=0, y=0), 1) for p in (c1, c2, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, r1, r2, r3, r4, r5): kb.tell(p) kb.extend() def plotPh22(): import Gnuplot resp1 = kb.ask_obj(Fact(c1, Has_position(x='X1', y='X2'), 'X3')) resp2 = kb.ask_obj(Fact(c2, Has_position(x='X1', y='X2'), 'X3')) #resp1 = kb.ask_obj(Fact(c1, Is_forced(newton='X1'), 'X2')) #resp2 = kb.ask_obj(Fact(c2, Is_forced(newton='X1'), 'X2')) line1 = [(float(p.predicate.x.value), float(p.predicate.y.value)) for p in resp1] line2 = [(float(p.predicate.x.value), float(p.predicate.y.value)) for p in resp2]
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with any part of the nlproject. # If not, see <http://www.gnu.org/licenses/>. from nl.log import logger from nl import (Noun, Verb, Number, Thing, Exists, Fact, Rule, Subword, Duration, Instant, During, Coincide, Intersection, Finish, Max_end, Min_end, kb) from people import Person from modality import Wants, Can, Must admin = Person('admin') kb.tell(admin) anonymous = Person('anonymous') kb.tell(anonymous) class Role(Thing): """ The name role, for roles that can be had in contexts by people, and have some associated permissions """ member = Role('member') kb.tell(member) editor = Role('editor') kb.tell(editor)
class Person(Thing): ''' ''' class Food(Thing): ''' ''' b1 = Food('banana1') b2 = Food('banana2') b3 = Food('banana3') b4 = Food('banana4') b5 = Food('banana5') b6 = Food('banana6') kb.tell(b1, b2, b3, b4, b5, b6) class Tries(Exists): subject = Person mods = {'what': Verb} class Feels(Exists): subject = Person mods = {'what': Exists} class Wants(Exists): subject = Person mods = {'what': Verb} class Wanting(Exists): subject = Person