Free Tutorials, Linux Command, Source Code Architecture,  Software Engineering, Intelligent Systems, RDBMS, Computer Accounting,  Operations Research, Discrete Mathematics, Network, SAD Lay Networks Lay Networks
Computer Science Networking Operating Systems Linux and Unix Source Code Script & Languages Protocols Glossary
Web laynetworks.com
Google
 


 TMA 2001

Following is the example of a program that accepts an arbitrarily long text as input and produces a list of words and their frequency of occurrence as output.

(The program is in ICON** V. 9.0 programming language)

** = Icon is a very high level general-purpose programming language with extensive features for processing strings (text) and data structures. Icon is an imperative, procedural language with a syntax that is reminiscent of C and Pascal, but with semantics at a much higher level.

global uses, lineno, width

procedure main(args)

width := 15 # width of word field

uses := table()

lineno := 0

every tabulate(words()) # tabulate all citations

output() # print the citations

end

# Add line number to citations for word

#

procedure tabulate(word)

/uses[word] := set()

insert(uses[word], lineno)

return

end

# Generate words

#

procedure words()

while line := read() do {

lineno +:= 1

write(right(lineno, 6), " ", line)

map(line) ? while tab(upto(&letters)) do {

s := tab(many(&letters))

if *s >= 3 then suspend s# skip short words

}

}

end

# Print the results

#

procedure output()

write() # blank line

uses := sort(uses, 3) # sort citations

while word := get(uses) do {

line := ""

numbers := sort(get(uses))

while line ||:= get(numbers) || ", "

write(left(word, width), line[1:-2])

}

end

The program reads a line, writes it out with an identifying line number, and processes every word in the line. Words less than three characters long are considered to be "noise" and are discarded. A table, uses, is keyed by the words. Every key has a corresponding set of line numbers. The first time a word is encountered, a new set is created for it. The line number is inserted in any event. Since a value can be in a set only once, duplicate line numbers are suppressed automatically.

After all the input has been read, the table of words is sorted by key. Each corresponding set of line numbers is sorted and the line numbers are appended to the line to be written.

For example, if the input file is

On the Future!-how it tells

Of the rapture that impells

To the swinging and the ringing

Of the bells, bells, bells-

Of the bells, bells, bells, bells,

Bells, bells, bells-

To the rhyming and the chiming of the bells!

the output is

1 On the Future!-how it tells

2 Of the rapture that impells

3 To the swinging and the ringing

4 Of the bells, bells, bells-

5 Of the bells, bells, bells, bells,

6 Bells, bells, bells-

7 To the rhyming and the chiming of the bells!

and 3, 7

bells 4, 5, 6, 7

chiming 7

future 1

how 1

impells 2

rapture 2

rhyming 7

ringing 3

swinging 3

tells 1

that 2

the 1, 2, 3, 4, 5, 7



Back
Next
FDDI Frequently Asked Questions (FAQ), The function and frame format of FDDI,Aloha,Comparative analysis between two types of ATM Switches,Knockout Switch,Barcher-Banyan Switch,Various popular standards for compressing multimedia data,Distributed Multimedia Survey: Standards, ASCII to hex value chart,Comparative analysis - TCP - UDP, Addressing Formats and QoS parameters, Bellman Ford's Algorithm Lay networks, free, java, java script, asp, vb, linux, ignou, tutorial, Unix commands, System Analysis, System Design, Ipv6, quiz, download, free, Computer Architecture, Object Oriented System, Relational Database Management Systems, Object Oriented System, Operating Systems, Software Engineering, Communications and Networks, Discrete Mathematics, Intelligent Systems, Operations Research, Accounting and Finance on Computersmca, networking, protocols, glossary, assignment, project, tma, programming source code, programming, source code, unix, free
 
Book Mark/Share this site at BlinkBits BlinkList Blogmarks co.mments Delicious Digg Fark Furl it! Google Ma.gnolia Netvouz NewsVine RawSugar Reddit Shadows Simpy Stumble Technorati YahooMyWeb

Copyright © 2000- 2007 Lay Networks All rights reserved. 
This website is best viewed in Firefox 1.0.1 above.

Web Hosting sponsored by Customized Software Company India
Web Site Designed by Web Designing, Flash Animation, Multimedia Presentations, Broacher/catalogue designing, Web Promotion 
Refer to your freind About Us Legal IGNOU Contact Us Feedback Donate to laynetworks.com Download Management Tutorials Tutorials History Search here