Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imported the code, first smoke tests pass
- Loading branch information
0 parents
commit c68210c
Showing
34 changed files
with
2,514 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in wongi-engine.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2012 Valeri Sokolov <ulfurinn@ulfurinn.net> | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Wongi::Engine | ||
|
||
TODO: Write a gem description | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
gem 'wongi-engine' | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install wongi-engine | ||
|
||
## Usage | ||
|
||
TODO: Write usage instructions here | ||
|
||
## Contributing | ||
|
||
1. Fork it | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Added some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
include Wongi::Engine | ||
|
||
ds = Dataset.new | ||
|
||
ds << WME.new( "Alice", "friend", "Bob" ) | ||
|
||
puts "Enumerate all:" | ||
|
||
ds.each do |wme| | ||
puts wme | ||
end | ||
|
||
puts "Enumerate by pattern:" | ||
|
||
ds.each nil, "friend", nil do |wme| | ||
puts wme | ||
end | ||
|
||
puts "Mismatching pattern:" | ||
|
||
ds.each nil, "foe", nil do |wme| | ||
puts wme | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
include Wongi::Engine | ||
|
||
ds = Dataset.new | ||
|
||
ds << ruleset { | ||
|
||
name "Example" | ||
|
||
rule "reflexive" do | ||
forall { | ||
has :P, "reflexive", true | ||
has :A, :P, :B | ||
} | ||
make { | ||
gen :B, :P, :A | ||
} | ||
end | ||
|
||
} | ||
|
||
puts "Installed ruleset" | ||
|
||
ds << WME.new( "friend", "reflexive", true ) | ||
ds << WME.new( "Alice", "friend", "Bob" ) | ||
|
||
puts "Asserted facts" | ||
|
||
puts ds.wmes | ||
|
||
puts "Should output 3 facts" | ||
|
||
ds.retract WME.new( "Alice", "friend", "Bob" ) | ||
|
||
puts ds.wmes | ||
|
||
puts "Should output 1 fact" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Wongi | ||
module Engine | ||
# Your code goes here... | ||
end | ||
end | ||
|
||
require 'wongi-engine/version' | ||
require 'wongi-engine/core_ext' | ||
require 'wongi-engine/template' | ||
require 'wongi-engine/wme' | ||
require 'wongi-engine/wme_match_data' | ||
require 'wongi-engine/token' | ||
require 'wongi-engine/alpha_memory' | ||
require 'wongi-engine/beta' | ||
require 'wongi-engine/dsl' | ||
require 'wongi-engine/error_generator' | ||
require 'wongi-engine/ruleset' | ||
require 'wongi-engine/dataset' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module Wongi::Engine | ||
|
||
class AlphaMemory | ||
|
||
attr_reader :betas, :template, :rete | ||
|
||
def initialize template, rete = nil | ||
@template = template | ||
@rete = rete | ||
@betas = [] | ||
@wmes = [] | ||
@frozen = false | ||
end | ||
|
||
def wmes force_real = nil | ||
if rete.in_snapshot? && force_real != :forced | ||
[] | ||
else | ||
@wmes | ||
end | ||
end | ||
|
||
def activate wme | ||
betas.each do |beta| | ||
beta.right_activate wme | ||
end | ||
@wmes << wme | ||
wme.alphas << self | ||
end | ||
|
||
def remove wme | ||
@wmes.delete wme | ||
# we don't need to unlink ourselves from the wme | ||
# because this is only called from WME#destroy | ||
# so the wme will take care of it itself | ||
end | ||
|
||
def snapshot! alpha | ||
alpha.wmes.map( &:dup ).each do |wme| | ||
activate wme | ||
end | ||
end | ||
|
||
def inspect | ||
"<Alpha #{__id__} template=#{template} wmes=#{wmes :forced}>" | ||
end | ||
|
||
def to_s | ||
inspect | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'wongi-engine/beta/beta_node' | ||
require 'wongi-engine/beta/beta_memory' | ||
require 'wongi-engine/beta/filter_node' | ||
require 'wongi-engine/beta/join_node' | ||
require 'wongi-engine/beta/ncc_partner' | ||
require 'wongi-engine/beta/ncc_node' | ||
require 'wongi-engine/beta/neg_node' | ||
require 'wongi-engine/beta/optional_node' | ||
require 'wongi-engine/beta/or_node' | ||
require 'wongi-engine/beta/production_node' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Wongi::Engine | ||
|
||
class BetaMemory < BetaNode | ||
attr_reader :tokens, :last_token | ||
|
||
def initialize parent | ||
super | ||
@tokens = [] | ||
end | ||
|
||
def seed assignments = {} | ||
t = Token.new( nil, nil, assignments ) | ||
t.node = self | ||
@tokens << t | ||
end | ||
|
||
def subst valuations | ||
token = @tokens.first | ||
token.delete true | ||
valuations.each { |variable, value| token.subst variable, value } | ||
self.children.each do |child| | ||
child.left_activate token | ||
end | ||
end | ||
|
||
def left_activate token, wme, assignments | ||
# puts "MEMORY #{@id} left-activated with #{wme}" | ||
t = Token.new( token, wme, assignments) | ||
t.node = self | ||
@last_token = t | ||
@tokens << t | ||
self.children.each do |child| | ||
if child.kind_of? BetaMemory | ||
child.left_activate t, nil, {} | ||
else | ||
child.left_activate t | ||
end | ||
end | ||
end | ||
|
||
# => TODO: investigate if we really need this | ||
#def beta_memory | ||
# self | ||
#end | ||
|
||
end | ||
|
||
end |
Oops, something went wrong.