Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Sentences

From: al::bri::xtra::co::nz at: 7-May-2002 21:20

Here's a early Sentences implementation in Rebol. This script just displays a sentences database: [ Rebol [ Name: 'Triple Title: "Triple" File: %Triple.r ] ;File: %Flight.r File: %Bookseller.r Liquid: melt load File I: 0 foreach Drop Liquid [ I: I + 1 if block? Drop [ print [I Drop] ] ] save File freeze sort Liquid halt ] These next values are the contents of %Flight.r: arrived at at Flight BA1234 London, Heathrow on [./3 ./1 ./4] [./6 ./5 12-Aug-1998] [./7 ./2 10:25] and these values are the contents of %Bookseller.r: Amazon America at Book Bookpages Britain Country customer of Date Dr No from has earned in is a Legal Entity lives in Mary Davis on orders Person Points Price sells Simon Williams Spycatcher worth [./1 ./14 ./15] [./1 ./23 ./10] [./1 ./23 ./25] [./2 ./14 ./7] [./5 ./14 ./15] [./5 ./23 ./10] [./5 ./23 ./25] [./6 ./14 ./7] [./10 ./14 ./4] [./15 ./23 ./4] [./17 ./8 ./1] [./17 ./14 ./20] [./17 ./16 ./2] [./20 ./8 ./15] [./20 ./16 ./7] [./24 ./8 ./5] [./24 ./14 ./20] [./24 ./16 ./6] [./25 ./14 ./4] [./28 ./13 ./2] [./28 ./13 ./6] [./28 ./26 75] [./29 ./13 ./2] [./29 ./13 ./6] [./29 ./26 50] [./32 ./13 ./2] [./32 ./13 ./6] [./32 ./26 35] [./33 ./13 ./2] [./33 ./26 35] [./36 ./13 ./7] [./36 ./26 ./21] [./37 ./12 750] [./37 ./19 ./25] [./40 ./12 ./21] [./40 ./19 ./4] [./42 ./12 1200] [./42 ./19 ./10] [./46 ./11 1-Mar-2000] [./47 ./11 1-Jan-2000] [./49 ./11 1-Jun-2000] [./50 ./11 1-Jun-2000] [./52 ./11 1-Jan-2000] [./53 ./11 1-Jan-2000] [./55 ./11 1-Jun-2000] [./57 ./11 ./9] [./60 ./18 19-Oct-2000] [./62 ./18 ./9] [./64 ./18 10-Oct-2000] [./65 ./3 $16.00] [./66 ./3 $10.00] [./67 ./3 $12.00] [./68 ./3 $7.00] [./69 ./3 $14.00] [./70 ./3 $8.00] [./71 ./3 $13.00] [./72 ./3 ./22] [./73 ./3 $12.00] [./74 ./3 ./22] [./75 ./3 $10.00] You'll also need %Melt.r: [ Rebol [ Name: 'Melt Title: "Melt" File: %"Melt.r" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 5/May/2002 Acknowledgements: "Romano Paolo Tenca" ] make object! [ Magic: '. ; This must be the same as the 'Freeze function! Melt-Value: function [Ice [block!] Berg] [Value Path] [ Value: :Berg if all [ path? :Berg Magic = first :Berg ] [ Path: :Berg if all [ 2 <= length? :Path integer? second :Path ] [ Value: pick Ice second :Path if all [ 3 = length? :Path integer? third :Path ] [ Value: at Value third :Path ] ] ] :Value ] set 'Melt function [ "Melts Object Ice" Ice [block!] ] [Block Object] [ foreach Berg Ice [ type? Berg switch type?/word :Berg [ block! [ Block: Berg forall Block [ Block/1: Melt-Value Ice pick Block 1 ] ] object! [ first Object: Berg foreach Word next first Object [ set in Object Word Melt-Value Ice get in Object Word ] ] ] ] Ice ; At this point, the 'Ice has become sea. :) ] ] ] And %Freeze.r: [ Rebol [ Name: 'Freeze Title: "Freeze" File: %"Freeze.r" Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 7/May/2002 Acknowledgements: "Romano Paolo Tenca" ] make object! [ Magic: '. ; This must be the same as the 'Melt function! Find-Same: func [Series [series!] Value [any-type!]] [ forever [ if any [ not found? Series: find/only/case Series :Value same? first Series :Value ] [ break/return Series ] Series: next Series ] ] Freeze-Value: function [ Sea [block!] Fish ] [Path Value Index] [ if all [ not lit-path? :Fish not path? :Fish any [ function? :Fish object? :Fish series? :Fish ] ] [ Path: make path! reduce [Magic] Value: either series? :Fish [head :Fish] [:Fish] either found? Index: Find-Same Sea :Value [ Index: index? Index ] [ append/only Sea :Value Index: length? Sea ] append :Path Index if all [ series? :Fish 1 < Index: index? Fish ] [ append/only :Path Index ] Fish: :Path ] :Fish ] set 'Freeze function [ "Freezes Object Sea" Sea [block!] ] [Block Object] [ foreach Fish Sea [ switch type?/word :Fish [ block! [ Block: Fish forall Block [ Block/1: Freeze-Value Sea pick Block 1 ] ] object! [ Object: Fish foreach Word next first Object [ set in Object Word Freeze-Value Sea get in Object Word ] ] ] ] Sea ; At this point, the 'Sea has become ice. :) ] ] ] %Flight.r and %Bookseller.r are example implementations of Lazy Software's examples in the .pdf titled "The Associative Model of Data White Paper". Here's an example of the %Flight.r print out: 6 Flight BA1234 arrived at London, Heathrow 7 Flight BA1234 arrived at London, Heathrow on 12-Aug-1998 8 Flight BA1234 arrived at London, Heathrow on 12-Aug-1998 at 10:25 And here's a 'probe of value of 'Liquid: [ "arrived at" "at" "Flight BA1234" "London, Heathrow" "on" [ "Flight BA1234" "arrived at" "London, Heathrow"] [[ "Flight BA1234" "arrived at" "London, Heathrow"] "on" 12-Aug-1998] [[[ "Flight BA1234" "arrived at" "London, Heathrow"] "on" 12-Aug-1998] "at" 10:25] ] after being 'melt-ed. Note that non-series values should be the third value of the triple. These are values like date!, time!, money!, integer! and so on. Also note that this software may fail on the latest version of Rebol, because of the change in the way path! values are handled. Andrew Martin ICQ: 26227169 http://valley.150m.com/ -><- Rebolutionary