Phiras’s Blog

December 24, 06

Automatic Arabic Text Classification With Bayesian Learning

Filed under: AI — phiras @ 11:48 am

Automatic text Classification (or categorization) is becoming more important with the growing amount of data present in our society. The Naїve Bayesian classifier has proven to be a good choice in this area; in this paper we are going to explain how the Bayesian learning algorithm works, and how to implement a simple Arabic text classifier.

the paper

December 23, 06

How to read and write files in php

Filed under: WEB-APP — phiras @ 12:58 am

It’s too easy to work with files in PHP.

To open a file for reading :

$handle = fopen($filename, "r");

“r” means that you can just read from the file, to write on the file you have to put “w”, see the next table for more details :

'r' Open for reading only; place the file pointer at the beginning of the file.
'r+' Open for reading and writing; place the file pointer at the beginning of the file.
'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it.
'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.
'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.

To read the file’s content :

$contents = fread($handle, filesize($filename));

To write to the file :

fwrite($handle, $contents ) ;

and Finlay you have to close the file :

fclose($handle);

December 21, 06

Windows Vista on my laptop

Filed under: Uncategorized — phiras @ 9:48 am

Finlay I install the latest windows version “Windows Vista Home premium ” on my laptop.
I don’t like the performance very much, and maybe i’m going to upgrade the main memory, but the UI is great :D .

December 19, 06

8-queen problem in LISP

Filed under: AI — phiras @ 1:08 am

Here is a simple lisp implementation to the 8-queen problem

(define mainDiag (vector #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f))
(define subDiag (vector #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f))
(define row (vector #f #f #f #f #f #f #f #f))
(define sol (vector 0 0 0 0 0 0 0 0))
(define solNum 0)

(define print (lambda (i j)
(if (< i 8 )
(begin (if (= j (vector-ref sol i)) (display ” Q “) (display ” X “))
(if (< j 8 ) (print i (+ 1 j)) (begin (newline) (print (+ i 1) 1)))
)
)
)
)

(define visit (lambda (r c)
(begin
(vector-set! row r #t)
(vector-set! subDiag (- (+ 8 c) r) #t)
(vector-set! mainDiag (+ c r) #t)
)
)
)

(define unVisit (lambda (r c)
(begin
(vector-set! row r #f)
(vector-set! subDiag (- (+ 8 c) r) #f)
(vector-set! mainDiag (+ c r) #f)
)
)
)

(define solve (lambda (c)
(if (= c 8 )
(begin (set! solNum (+ solNum 1)) (display “Solution : “)(display solNum) (newline) (display sol) (newline) (print 0 1) (newline))
(backTrackLoop 0 c)
)
)
)

(define backTrackLoop (lambda (r c)
(if (not (= r 8))
(if (and (not (vector-ref subDiag (- (+ 8 c) r)))
(not (vector-ref mainDiag (+ c r)))
(not (vector-ref row r)))
(begin (vector-set! sol c (+ 1 r)) (visit r c) (solve (+ c 1)) (unVisit r c) (backTrackLoop (+ r 1) c))
(backTrackLoop (+ r 1) c)
)
)
)
)

(solve 0)

Blog at WordPress.com.