Click here for more information

SAMPLE Language & Technology



Please go to
http://sampletalk.8m.com ,
which is updated version of this homepage.
Information below is out-of-date and remains here only for keeping old links.





Build a program immediately from data processing examples




SAMPLE Language & Technology: http://sampletalk.8m.com/.

Build a program immediately from data processing examples. Program Examples


Word Inversion


Compare this program to the next two programs. The under-lines denote the nesting structure on samples.






% Goal:

reverse of the word abcdef is X..

% Program (knowledge base):

reverse of the word AM is NA :- reverse of the word M is N..

reverse of the word A is A..



The output will be reverse of the word abcdef is fedcba.


This program demonstrates how a word processing algorithm can be constructed from natural language phrases describing this algorithm.


 


Word inversion 2


(this program is similar to the previous one but has more compact code).






[abcdef]-->[X].. % Goal

[
AM]-->[NA] :- [M]-->[N].. % Recursive rule

[
A]-->[A].. % Boundary condition



The output will be [abcdef]-->[fedcba]. These examples show that you can easily introduce your own syntax like []-->[] for expressing your favorite designations. The output will be [abcdef]-->[fedcba].


 


  


Inversion of a list of words (separated by /)


Compare this program to the previous two programs for word inversion. The only essential difference is two symbols / in the recursive rule, but performance is quite different.






reverse of the list abc/def/gh is X.. %Goal

reverse of the list A/M is N/A :- reverse of the list M is N.. % Program

reverse of the list A is A..



Output: reverse of the list abc/def/gh is gh/def/abc. Note the readability of such programs: it's hard to imagine a program, which is more readable than what is composed from natural language descriptions of an algorithm.


 


Transformation of infix notation of arithmetic expressions into (polish) prefix notation


% Possible goals:

[[[a + b] * c] * [u2 + u3]] => _..

[[a + b] * c] => ..

[[a + b] * [c - d]] => ..

[[a + b] * [[a - b] / c]] => ..


% Symbols "_" are to be replaced with the prefix notations. Outputs of the program with these goals will be as follows:

[[[a + b] * c] * [u2 + u3]] => * * + a b c + u2 u3..

[[a + b] * c] => * + a b c..

[[a + b] * [c - d]] => * + a b - c d..

[[a + b] * [[a - b] / c]] => * + a b / - a b c..






% The program is as simple as this:

[A Z B] => Z X Y :- A => X,, B => Y..

A => A..



As the result, you will get the polish notations instead of the symbol "_" in the goals.

Note that "=>" isn't a language construction. You can write "-->", or something more expressive like "is translated to", "is" - anything you want to express the meaning of this transformation. For SAMPLE, only matching of sub-word "=>" to other occurrences of sub-words "=>" is important.


  


Replacing sub-words in a word


The goal for this program has the form

(Word2/Word1)SourceExpression=ResultingExpression

This program replaces all occurrences of word1 in the source expression by word2 (upper-case letters stand for text variables). See also applications of this program below.






% Goal:

(
(y+2)/x7)[sin(2x7)+cos(4x7)]=_..

% Program:

(Y/X)[AXM]=[AYN] :- (Y/X)[M]=[N]..

(Y/X)[A]=[A]..



Output: ((y+2)/x7)[sin(2x7)+cos(4x7)]=[sin(2(y+2))+cos(4(y+2))].


Note the similarity of the program constructions to the processed data: they are built just from such data!


  


Palindrome test


This program tests a word whether it is a palindrome and finds its 1-st half (the goal is the 1-st line; the half will replace variable W).






% Goal

[abcddcba]->W..

% Program

[AXA]->AW :- [X]->W..

[AA]->A :- ~~[A]=[CD]..

[A]=[A]..



Output: [abcddcba]->abcd..


 List permutations


This is (probably) the shortest representation of an algorithm for generating list permutations, possible for universal programming languages. You can even exclude the words "permutation for", "is", and the program will do the same.






% Goal

permutation for ({1}{2}{3}{4}) is [W]..

% Program

permutation for A{M}B is [{M}W] :- permutation for AB is [W]..

permutation for () is [ ]..



 


Generating words in the form W [W-1] W:


Generation of words of the type W [W-1] W (see the comment below), which is impossible for CF grammars.






%Goal

[A][B][A]..

%Program

[X][X][X] :- letter [X]..

[AX][XB][AX] :- [A][B][A] ,, letter [X]..

letter [a]..

letter [b]..



Comment: The program generates words [a][a][a], [b][b][b], [aa][aa][aa], [ab][ba][ab], [abab][baba][abab] etc, where the 2-nd word is inverse of the 1-st and 3-rd words which are equal.


 


Bubble sort of a digit list


In this program, just finding the digits in the ascending digit list tests the order of digits.






% Goal (W is to be filled by the sorted list)

sort of begin [2] [5] [9] [3] [7] [4] [4] [3] [5] end is [W]..

% Program

sort of A [M] [N] B is [W] :- [M]<[N] ,, sort of A [N] [M] B is [W]..

sort of A is [A]..

[M]<[N] :- digits [_M_N_]..

digits [/0/1/2/3/4/5/6/7/8/9/]..



Such programs will never need a detailed documentation: since text matching is the main programming concept, the reader will always find explanation of program elements in other similar elements.


 


Bubble sort of numbers


In this program, the order of numbers is tested by incorporated Prolog predicate <.






% Goal:

sort of [begin {2.7} {1024} {9.8} {3.14} end] is W..

% Program:

sort of [A {M} {N} B] is W :- {M
sort of [A] is A..



SAMPLE Language & Technology: http://www.webspawner.com/users/samplex/


 


 




Back to SAMPLE Language @ Technology
Other examples: NL Parsing & Understanding
Other examples: Logics; Recognition of Regularities
Metaphoric Conclusion about SAMPLE Technology

Send E-Mail to: gleibman@yahoo.com

Free Webpages This page created using the webpage creation facilities of Webspawner.
Copyright © 2001 Andrew Gleibman. All Rights Reserved