Created
August 7, 2012 08:55
Revisions
-
dhoelzgen revised this gist
Aug 7, 2012 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ANSWERSET 1: fact numbers(1), numbers(2), numbers(3), numbers(4), ..., numbers(10) test(a), test(b), test(c) -
dhoelzgen revised this gist
Aug 7, 2012 . 1 changed file with 1 addition and 1 deletion.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 charactersOriginal file line number Diff line number Diff line change @@ -29,7 +29,7 @@ def printCurrent(number) elsif arg.size < 6 puts " " + arg.map {|a| "#{pred}#{a}"}.join(", ") else puts " " + arg[0..3].map {|a| "#{pred}#{a}"}.join(", ") + ", ..., #{pred}#{arg[-1]}" end end -
dhoelzgen revised this gist
Aug 7, 2012 . 2 changed files with 13 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ test(a). test(b). numbers(1..10). test(c) :- test(a), test(b). test(d) :- test(a), not test(b). 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ ANSWERSET 1: fact numbers(1), numbers(2), numbers(3), numbers(4), numbers(5), ... test(a), test(b), test(c) -
dhoelzgen revised this gist
Aug 7, 2012 . 1 changed file with 0 additions and 2 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 charactersOriginal file line number Diff line number Diff line change @@ -35,8 +35,6 @@ def printCurrent(number) puts "" @answerset = Hash.new end -
dhoelzgen created this gist
Aug 7, 2012 .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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,78 @@ #!/usr/bin/env ruby output = %x(/usr/local/bin/dlv-complex -silent #{ARGV[0]}) output = output.scan(/[[:print:]]/).join @answerset = Hash.new def reset @bracket_level = 0 @current_pred = "" @current_arg = "" end def addLiteral return unless @current_pred && @current_pred.any? @answerset[@current_pred] ||= Array.new @answerset[@current_pred] << @current_arg reset end def printCurrent(number) puts "ANSWERSET #{number}:" @answerset.sort {|a,b| a[0] <=> b[0]}.each do |pred, arg| if arg.size < 2 puts " #{pred}#{arg}" elsif arg.size < 6 puts " " + arg.map {|a| "#{pred}#{a}"}.join(", ") else puts " " + arg[0..4].map {|a| "#{pred}#{a}"}.join(", ") + ", ..." end end puts "" puts @answerset.map {|a,b| b.count}.inject{|sum,x| sum + x } @answerset = Hash.new end curlyLevel = 0; i = 0 output.each_char do |c| # Several answersets if c == '{' && curlyLevel == 0 reset curlyLevel = 1 elsif c == '}' && curlyLevel == 1 curlyLevel = 0 addLiteral printCurrent(i+=1) else # Within answerset next if c == ' ' && @bracket_level == 0 if c == ',' && @bracket_level == 0 addLiteral else curlyLevel += 1 if c == '{' curlyLevel -= 1 if c == '}' @bracket_level += 1 if c == '(' if @bracket_level == 0 @current_pred += c else @current_arg += c end @bracket_level -= 1 if c == ')' end end end