Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,26 +0,0 @@
|
|||
with Ada.Strings.Unbounded;
|
||||
|
||||
package Markov is
|
||||
use Ada.Strings.Unbounded;
|
||||
type Ruleset (Length : Natural) is private;
|
||||
type String_Array is array (Positive range <>) of Unbounded_String;
|
||||
function Parse (S : String_Array) return Ruleset;
|
||||
function Apply (R : Ruleset; S : String) return String;
|
||||
private
|
||||
type Entry_Kind is (Comment, Rule);
|
||||
type Set_Entry (Kind : Entry_Kind := Rule) is record
|
||||
case Kind is
|
||||
when Rule =>
|
||||
Source : Unbounded_String;
|
||||
Target : Unbounded_String;
|
||||
Is_Terminating : Boolean;
|
||||
when Comment =>
|
||||
Text : Unbounded_String;
|
||||
end case;
|
||||
end record;
|
||||
subtype Rule_Entry is Set_Entry (Kind => Rule);
|
||||
type Entry_Array is array (Positive range <>) of Set_Entry;
|
||||
type Ruleset (Length : Natural) is record
|
||||
Entries : Entry_Array (1 .. Length);
|
||||
end record;
|
||||
end Markov;
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
package body Markov is
|
||||
|
||||
function Parse (S : String_Array) return Ruleset is
|
||||
Result : Ruleset (Length => S'Length);
|
||||
begin
|
||||
for I in S'Range loop
|
||||
if Length (S (I)) = 0 or else Element (S (I), 1) = '#' then
|
||||
Result.Entries (I) := (Kind => Comment, Text => S (I));
|
||||
else
|
||||
declare
|
||||
Separator : Natural;
|
||||
Terminating : Boolean;
|
||||
Target : Unbounded_String;
|
||||
begin
|
||||
Separator := Index (S (I), " -> ");
|
||||
if Separator = 0 then
|
||||
raise Constraint_Error;
|
||||
end if;
|
||||
Target :=
|
||||
Unbounded_Slice
|
||||
(Source => S (I),
|
||||
Low => Separator + 4,
|
||||
High => Length (S (I)));
|
||||
Terminating := Length (Target) > 0
|
||||
and then Element (Target, 1) = '.';
|
||||
if Terminating then
|
||||
Delete (Source => Target, From => 1, Through => 1);
|
||||
end if;
|
||||
Result.Entries (I) :=
|
||||
(Kind => Rule,
|
||||
Source => Unbounded_Slice
|
||||
(Source => S (I),
|
||||
Low => 1,
|
||||
High => Separator - 1),
|
||||
Target => Target,
|
||||
Is_Terminating => Terminating);
|
||||
end;
|
||||
end if;
|
||||
end loop;
|
||||
return Result;
|
||||
end Parse;
|
||||
|
||||
procedure Apply
|
||||
(R : Rule_Entry;
|
||||
S : in out Unbounded_String;
|
||||
Modified : in out Boolean)
|
||||
is
|
||||
Pattern : String := To_String (R.Source);
|
||||
Where : Natural := Index (S, Pattern);
|
||||
begin
|
||||
while Where /= 0 loop
|
||||
Modified := True;
|
||||
Replace_Slice
|
||||
(Source => S,
|
||||
Low => Where,
|
||||
High => Where + Pattern'Length - 1,
|
||||
By => To_String (R.Target));
|
||||
Where := Index (S, Pattern, Where + Length (R.Target));
|
||||
end loop;
|
||||
end Apply;
|
||||
|
||||
function Apply (R : Ruleset; S : String) return String is
|
||||
Result : Unbounded_String := To_Unbounded_String (S);
|
||||
Current_Rule : Set_Entry;
|
||||
Modified : Boolean := False;
|
||||
begin
|
||||
loop
|
||||
Modified := False;
|
||||
for I in R.Entries'Range loop
|
||||
Current_Rule := R.Entries (I);
|
||||
if Current_Rule.Kind = Rule then
|
||||
Apply (Current_Rule, Result, Modified);
|
||||
exit when Current_Rule.Is_Terminating or else Modified;
|
||||
end if;
|
||||
end loop;
|
||||
exit when not Modified;
|
||||
end loop;
|
||||
return To_String (Result);
|
||||
end Apply;
|
||||
|
||||
end Markov;
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
with Ada.Command_Line;
|
||||
with Ada.Text_IO.Unbounded_IO;
|
||||
with Ada.Strings.Unbounded;
|
||||
with Markov;
|
||||
|
||||
procedure Test_Markov is
|
||||
use Ada.Strings.Unbounded;
|
||||
package IO renames Ada.Text_IO.Unbounded_IO;
|
||||
Rule_File : Ada.Text_IO.File_Type;
|
||||
Line_Count : Natural := 0;
|
||||
begin
|
||||
if Ada.Command_Line.Argument_Count /= 2 then
|
||||
Ada.Text_IO.Put_Line ("Usage: test_markov ruleset_file source_file");
|
||||
return;
|
||||
end if;
|
||||
Ada.Text_IO.Open
|
||||
(File => Rule_File,
|
||||
Mode => Ada.Text_IO.In_File,
|
||||
Name => Ada.Command_Line.Argument (1));
|
||||
while not Ada.Text_IO.End_Of_File (Rule_File) loop
|
||||
Ada.Text_IO.Skip_Line (Rule_File);
|
||||
Line_Count := Line_Count + 1;
|
||||
end loop;
|
||||
declare
|
||||
Lines : Markov.String_Array (1 .. Line_Count);
|
||||
begin
|
||||
Ada.Text_IO.Reset (Rule_File);
|
||||
for I in Lines'Range loop
|
||||
Lines (I) := IO.Get_Line (Rule_File);
|
||||
end loop;
|
||||
Ada.Text_IO.Close (Rule_File);
|
||||
|
||||
declare
|
||||
Ruleset : Markov.Ruleset := Markov.Parse (Lines);
|
||||
Source_File : Ada.Text_IO.File_Type;
|
||||
begin
|
||||
Ada.Text_IO.Open
|
||||
(File => Source_File,
|
||||
Mode => Ada.Text_IO.In_File,
|
||||
Name => Ada.Command_Line.Argument (2));
|
||||
while not Ada.Text_IO.End_Of_File (Source_File) loop
|
||||
Ada.Text_IO.Put_Line
|
||||
(Markov.Apply (Ruleset, Ada.Text_IO.Get_Line (Source_File)));
|
||||
end loop;
|
||||
Ada.Text_IO.Close (Source_File);
|
||||
end;
|
||||
end;
|
||||
end Test_Markov;
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
class markovparser
|
||||
|
||||
dim aRules
|
||||
public property let ruleset( sBlock )
|
||||
dim i
|
||||
aRules = split( sBlock, vbNewLine )
|
||||
'~ remove blank lines from end of array
|
||||
do while aRules( ubound( aRules ) ) = vbnullstring
|
||||
redim preserve aRules( ubound( aRules ) - 1 )
|
||||
loop
|
||||
'~ parse array
|
||||
for i = lbound( aRules ) to ubound( aRules )
|
||||
if left( aRules( i ), 1 ) = "#" then
|
||||
aRules( i ) = Array( vbnullstring, aRules(i))
|
||||
else
|
||||
aRules( i ) = Split( aRules( i ), " -> ", 2 )
|
||||
end if
|
||||
next
|
||||
end property
|
||||
|
||||
public function apply( sArg )
|
||||
dim ruleapplied
|
||||
dim terminator
|
||||
dim was
|
||||
dim i
|
||||
dim repl
|
||||
dim changes
|
||||
|
||||
ruleapplied = true
|
||||
terminator = false
|
||||
|
||||
do while ruleapplied and (not terminator)
|
||||
changes = 0
|
||||
was = sArg
|
||||
for i = lbound( aRules ) to ubound( aRules )
|
||||
repl = aRules(i)(1)
|
||||
if left( repl, 1 ) = "." then
|
||||
terminator = true
|
||||
repl = mid( repl, 2 )
|
||||
end if
|
||||
sArg = replace( sArg, aRules(i)(0), repl)
|
||||
if was <> sArg then
|
||||
changes = changes + 1
|
||||
if changes = 1 then
|
||||
exit for
|
||||
end if
|
||||
end if
|
||||
if terminator then
|
||||
exit for
|
||||
end if
|
||||
next
|
||||
if changes = 0 then
|
||||
ruleapplied = false
|
||||
end if
|
||||
loop
|
||||
apply = sArg
|
||||
end function
|
||||
|
||||
sub dump
|
||||
dim i
|
||||
for i = lbound( aRules ) to ubound( aRules )
|
||||
wscript.echo eef(aRules(i)(0)=vbnullstring,aRules(i)(1),aRules(i)(0)& " -> " & aRules(i)(1)) & eef( left( aRules(i)(1), 1 ) = ".", " #terminator", "" )
|
||||
next
|
||||
end sub
|
||||
|
||||
private function eef( bCond, sExp1, sExp2 )
|
||||
if bCond then
|
||||
eef = sExp1
|
||||
else
|
||||
eef = sExp2
|
||||
end if
|
||||
end function
|
||||
end class
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
dim m1
|
||||
set m1 = new markovparser
|
||||
m1.ruleset = "# This rules file is extracted from Wikipedia:" & vbNewLine & _
|
||||
"# http://en.wikipedia.org/wiki/Markov_Algorithm" & vbNewLine & _
|
||||
"A -> apple" & vbNewLine & _
|
||||
"B -> bag" & vbNewLine & _
|
||||
"S -> shop" & vbNewLine & _
|
||||
"T -> the" & vbNewLine & _
|
||||
"the shop -> my brother" & vbNewLine & _
|
||||
"a never used -> .terminating rule"
|
||||
wscript.echo m1.apply( "I bought a B of As from T S.")
|
||||
|
||||
dim m2
|
||||
set m2 = new markovparser
|
||||
m2.ruleset = replace( "# Slightly modified from the rules on Wikipedia\nA -> apple\nB -> bag\nS -> .shop\nT -> the\nthe shop -> my brother\na never used -> .terminating rule", "\n", vbNewLine )
|
||||
'~ m1.dump
|
||||
wscript.echo m2.apply( "I bought a B of As from T S.")
|
||||
|
||||
dim m3
|
||||
set m3 = new markovparser
|
||||
m3.ruleset = replace("# BNF Syntax testing rules\nA -> apple\nWWWW -> with\nBgage -> ->.*\nB -> bag" & vbNewLine & _
|
||||
"->.* -> money\nW -> WW\nS -> .shop\nT -> the\nthe shop -> my brother\na never used -> .terminating rule", "\n", vbNewLine )
|
||||
wscript.echo m3.apply("I bought a B of As W my Bgage from T S.")
|
||||
|
||||
set m4 = new markovparser
|
||||
m4.ruleset = "### Unary Multiplication Engine, for testing Markov Algorithm implementations" & vbNewLine & _
|
||||
"### By Donal Fellows." & vbNewLine & _
|
||||
"# Unary addition engine" & vbNewLine & _
|
||||
"_+1 -> _1+" & vbNewLine & _
|
||||
"1+1 -> 11+" & vbNewLine & _
|
||||
"# Pass for converting from the splitting of multiplication into ordinary" & vbNewLine & _
|
||||
"# addition" & vbNewLine & _
|
||||
"1! -> !1" & vbNewLine & _
|
||||
",! -> !+" & vbNewLine & _
|
||||
"_! -> _" & vbNewLine & _
|
||||
"# Unary multiplication by duplicating left side, right side times" & vbNewLine & _
|
||||
"1*1 -> x,@y" & vbNewLine & _
|
||||
"1x -> xX" & vbNewLine & _
|
||||
"X, -> 1,1" & vbNewLine & _
|
||||
"X1 -> 1X" & vbNewLine & _
|
||||
"_x -> _X" & vbNewLine & _
|
||||
",x -> ,X" & vbNewLine & _
|
||||
"y1 -> 1y" & vbNewLine & _
|
||||
"y_ -> _" & vbNewLine & _
|
||||
"# Next phase of applying" & vbNewLine & _
|
||||
"1@1 -> x,@y" & vbNewLine & _
|
||||
"1@_ -> @_" & vbNewLine & _
|
||||
",@_ -> !_" & vbNewLine & _
|
||||
"++ -> +" & vbNewLine & _
|
||||
"# Termination cleanup for addition" & vbNewLine & _
|
||||
"_1 -> 1" & vbNewLine & _
|
||||
"1+_ -> 1" & vbNewLine & _
|
||||
"_+_ -> "
|
||||
'~ m4.dump
|
||||
wscript.echo m4.apply( "_1111*11111_")
|
||||
|
||||
set fso = createobject("scripting.filesystemobject")
|
||||
set m5 = new markovparser
|
||||
m5.ruleset = fso.opentextfile("busybeaver.tur").readall
|
||||
wscript.echo m5.apply("000000A000000")
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
I bought a bag of apples from my brother.
|
||||
I bought a bag of apples from T shop.
|
||||
I bought a bag of apples with my money from T shop.
|
||||
11111111111111111111
|
||||
00011H1111000
|
||||
Loading…
Add table
Add a link
Reference in a new issue