AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 7 2012. Fall. SME., Pukyong Nat ’ l Univ. Kim, Minsoo.

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Advertisements

Reading and Writing Text Files Svetlin Nakov Telerik Corporation
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 4
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Files from Ch4. File Input and Output  Reentering data all the time could get tedious for the user.  The data can be saved to a file. Files can be input.
File AccessCS-2301, B-Term File Access CS-2301, System Programming for Non-Majors (Slides include materials from The C Programming Language, 2 nd.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 11: 1 CMT1000: Introduction to Programming Ed Currie Lecture 10: File Input.
Chapter 8: Exceptions and I/O Streams Copyright 2002, Matthew Evett. These slides are based on slides copyrighted by John Lewis and William Loftus, 2002,
Slides prepared by Rose Williams, Binghamton University Chapter 10 File I/O.
1 Fall 2007ACS-1903 for Loop Writing to a file String conversions Random class.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
7/2/2015CS2621 OO Design and Programming II I/O: Reading and Writing.
Chapter 7. 2 Objectives You should be able to describe: The string Class Character Manipulation Methods Exception Handling Input Data Validation Namespaces.
Lecture 30 Streams and File I/O COMP1681 / SE15 Introduction to Programming.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
Exceptions and IO Dr. Andrew Wallace PhD BEng(hons) EurIng
Chapter 18 I/O in C. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Standard C Library I/O commands.
Python programs How can I run a program? Input and output.
CMPE13 Cyrus Bazeghi Chapter 18 I/O in C. CMPE Standard C Library I/O commands are not included as part of the C language. Instead, they are part.
CIS Computer Programming Logic
Input & Output: Console
AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part Fall. SME., Pukyong Nat ’ l Univ. Kim, Minsoo.
CIS 270—Application Development II Chapter 14—Files and Streams.
Standard Input and Output. Overview Data communication with a C program and the outside world is performed through files Files are a non-volatile way.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Chapter 9 I/O Streams and Data Files
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Copyright © 2012 Pearson Education, Inc. Chapter 5 Loops, File, and Random Numbers.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Chapter 9 1 Chapter 9 – Part 2 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
COMP 110: Spring Announcements Program 5 Milestone 1 was due today Program 4 has been graded.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Generics and file handling Presented by: Abha Kumari Neha Pradip Vhanmane Raj Visa Rashmi Kewlani Suvrat Dixit.
OO Design and Programming II I/O: Reading and Writing
Chapter 2 Introduction to C++ Programming
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
Chapter 7 Text Input/Output Objectives
Chapter 18 I/O in C.
8/30/2018 CPRG 215 Introduction to Object-Oriented Programming with Java Module 5- The java.io Package Topic 5.1 Input and Output Streams, Readers.
I/O Basics.
Files I/O, Streams, I/O Redirection, Reading with fscanf
Chapter 17 Binary I/O Dr. Clincy - Lecture.
Topics Introduction to File Input and Output
CSS 161: Fundamentals of Computing
Beginning C Lecture 11 Lecturer: Dr. Zhao Qinpei
File Input and Output.
Our Environment We will exercise on Microsoft Visual C++ v.6
I/O and Applet from Chapter 12
Module 12 Input and Output
Topics Introduction to File Input and Output
Presentation transcript:

AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part Fall. SME., Pukyong Nat ’ l Univ. Kim, Minsoo

Contents IO Stream General Input and Output

IO Stream Input and Output –Input/Ouput/Error Stream stdIO class –Console application  Old MS-DOS style console class’s default mapping –Input stream  keyboard –Output/Error stream  console screen stdIO class is mapped to console by default –GUI application  Graphic Windows Output Stream  Message Window –vpiMessages class –stdIO class Error Stream  Error and Warning Window

IO Stream Stream: a sequence of bytes – …  , , … Binary mode: no interpretation Text mode(interpreted mode): read stream as letters –VIP supports two codes: ANSI, Unicode ANSI code: an extension of ASCII code –Control codes: ANSI escape sequence(ox1B5B…) Unicode: 16bits base –Try to deliver a code that can be used for every language in the world

IO Stream Start a new project ‘consoleIO’ –Console application

IO Stream –Add a class ‘database’ as a module Uncheck the ‘Create Interface’ box

IO Stream –Add declaration to ‘database.cl’ file. + +

IO Stream –Add implementation to ‘database.pro’ file. + + class facts - persons person : (string Name). clauses storeNames(N) = N :- stdIO::write("\nInput Name ( '0' to stop): "), '0' = stdIO::readChar(), !. storeNames(I) = Number :- stdIO::ungetChar(), Term = stdIO::readLine(), assert(person(Term)), N = I + 1, Number = storeNames(N). fill() :- N = storeNames(0), stdIO::writef("\n%d terms were stored.\nPress any key.\n", N), stdIO::save(persons), _ = stdIO::readChar(), DBFile = outputStream_file::create8("person.txt"), stdIO::setOutputstream(DBFile), stdIO::save(persons), stdIO::flush().

IO Stream After compile, change ‘main.pro’ file. Build & Run! –Check ‘person.txt’ file under Exe directory. + +

IO Stream Predicates for Input Stream –stdIO::getInputStream()  inputStream Returns current input stream –stdIO::setInputStream(inputStream) Sets current input stream as inputStream –stdIO::read()  _ Term Reads a specified term from the input stream To define term’s domain use hasDomain/2 predicate –stdIO::readBytes(byteCount size)  binary Reads a number of bytes from the input stream and stores them into the binary variable Returned bytes’s length can be shorter than size when it encounters the end of stream before.

IO Stream Predicates for Input Stream (continued) –stdIO::readChar()  char –stdIO:readLine()  string Read until it encounter \n or zero-character(string terminative symbol) or end of stream. –stdIO::readString(charCount)  string Tries to read given number of characters from the input stream and stores them into the string. –stdIO::ungetChar() Returns last read character back to the current input stream.

IO Stream Predicates for Output Stream –stdIO::flush() Forces the contents of the internal buffer of the current output stream to be written to the resource(or file) that it is connected to. –stdIO::getOutputStream()  outputStream –stdIO::setOutputStream(outputStream) –stdIO::nl() –stdIO::write(…), writeQuoted(…) –stdIO::writef(string Format [formatString], …) Produces output that is formatted automatically.

IO Stream Predicates for Error Stream –stdIO::flush_error() –stdIO::getErrorStream() –stdIO::setErrorStream(outputStream) –stdIO::nl_error() –stdIO::write_error(…) –stdIO::writeQuoted_error(…) –stdIO::writef_error(…)

IO Stream Special purpose predicates –stdIO::consult(factDB) Reads facts from the current input stream and asserts them in the internal database (factDB) –stdIO::save(factDB) Saves the contents of the facts section with the name specified by factDB variable) –stdIO::save_error(factDB) –stdIO::endOfStream() Checks whether a current position of input stream reaches the end of stream.

IO Stream Add new class ‘readExamples’ to project –Uncheck the ‘Create Interface’ box.

IO Stream –Add declaration to ‘readExamples.cl’ file. + +

IO Stream –Add implementation to ‘readExamples.pro’. + + domains person = person(string Name). class facts intFact : integer := 1. stringFact : string := "This is a string". functorFact : person := person("Thomas"). clauses writeSomeTerms() :- stdIO::write("intFact = ", intFact, "\nstringFact = ", stringFact), stdIO::write("\nfunctorFact = ", functorFact, "\n"). readSomeTerms(IntFile, StringFile, FunctorFile) :- intFact := IntFile:read(), stringFact := StringFile:read(), functorFact := FunctorFile:read().

IO Stream –Create following 3 files under Exe directory Create as text files intSource.txt "here is a string" "here is another string" stringSource.txt person("Another Thomas") person("Anna") functorSource.txt

IO Stream –Change the run clause in ‘main.pro’ file. Build & Run! + + run():- console::init(), readExamples::writeSomeTerms(), IntFile = inputStream_file::openFile8("intSource.txt"), StringFile = inputStream_file::openFile8("stringSource.txt"), FunctorFile = inputStream_file::openFile8("functorSource.txt"), stdIO::write("All inputStream is open. Press."), _ = stdIO::readChar(), readExamples::readSomeTerms(IntFile, StringFile, FunctorFile), readExamples::writeSomeTerms(), readExamples::readSomeTerms(IntFile, StringFile, FunctorFile), readExamples::writeSomeTerms(), _ = stdIO::readChar().

General Input and Output Stream class hierarchy in VIP –OuputStream OutputStream_console OutputStream_file –InputStream OutputStream_console OutputStream_file

General Input and Output Add class ‘copyStream’ to project. –Uncheck the ‘Create Interface’ box.

General Input and Output –Add declaration ‘copyStream.cl’ file. + +

General Input and Output –Add implementation to ‘copyStream.pro’ + + class predicates copyStream : (inputStream InputFile, outputStream OutputFile) procedure (i, i). repeat : () multi (). clauses copyStream(InputFile, OutputFile) :- repeat(), String = InputFile:readLine(), stdIO::write(String, "\n"), OutputFile:write(String, "\n"), InputFile:endOfStream(), !. copyStream(_InputFile, _OutputFile). repeat(). repeat() :- repeat(). copy(InFile, OutFile) :- InputFile = inputStream_file::openFile8(InFile), OutputFile = outputStream_file::create(OutFile), copyStream(InputFile, OutputFile), InputFile:close(), OutputFile:close().

General Input and Output –Change run clause to test the predicates. Build & Run  check file under Exe folder.

General Input and Output Interface stream –close() –getCRLFconversion()  boolean Specifies whether the stream data will be handled with CRLF  LF conversion (if true). –setCRLFconversion(boolean) –getMode()  mode binary, ANSI, Unicode –setMode(mode) –getPosition()  unsigned64 –setPosition(unsigned64)

General Input and Output Interface inputStream –consult(factDB) –reconsult(factDB) Retract the facts from DB and then consult. –endOfStream() –read()  _ Value –readBytes(byteCount)  binary –readChar()  char –readLine()  string –readString(charCount)  string –ungetChar()

General Input and Output Interface outputStream –flush() –nl() –save(factDB) –write(…) –writeBytes(pointer Value, byteCount size) –writeQuoted(…) –writef(string FormatString [formatString], …)

General Input and Output Class inputStream_file –openFile(string) Opens Unicode file for input. –openFile(string, mode) –openFile8(string) Opens ANSI file for input.

General Input and Output Class outputStream_file –append(string) Opens Unicode file for output, setting the stream position to the end of file. –append(string, mode) –append8(string) Opens ANSI file output, setting the stream position to the end of file. –create(string), create(string, mode) –create8(string) –openFile(string), openFile(string, mode) –openFile8(string)