Mail bezanid
Soroush7000@gmail.com
الگوریتم تبدیل تاریخ میلادی به تاریخ شمسی :
پیاده سازی الگوریتم به زبان c :
ما در عصري زندگي مي كنيم كه جامعه شناسان آن را عصر انقلاب كامپيوتر نام نهاده اند و مانند هر انقلاب واقعي ديگر، انقلابي است گسترده و فراگير و تأثير پايداري برجامعه خواهد داشت.
اين انقلاب در اقتصاد امروز و نظم جامعه، به همان ميزان انقلاب صنعتي در قرن 19 تأثير دارداين تحولات قادر است الگوي فكري و فرم زندگي هر فرد را تغيير دهد.
انقلاب كامپيوتر توان ذهني ما را گسترش مي دهد.
عملكرد اولية برنامه نويسي هوش مصنوعي (AI) ايجاد ساختار كنترلي مورد لزوم براي محاسبه سمبوليك است خصوصيات اين ساختارها به مقدار زيادي موجب تشخيص خصوصياتي مي شود كه يك زبان كاربردي مي بايستي فراهم كند.
در اين مقدمه به يك سري خصوصيات مورد نظر براي زبان برنامه نويسي سمبوليك مي پردازيم و زبانهاي برنامه نويسي LISP و PROLOG را معرفي خواهيم كرد.
اين دو زبان علاوه بر اين كه از مهمترين زبانهاي مورد استفاده در هوش مصنوعي هستند، خصوصيات semantic و syntactic آنها نيز باعث شده كه آنها شيوه ها و راه حل هاي قوي براي حل مسئله ارئه كنند.
تأثير قابل توجه اين زبانها بر روي توسعه AI از جمله توانائي آنها به عنوان «ابزارهاي فكر كردن» مي باشد كه از جمله نقاط قوت آنها در زبانهاي برنامه نويسي مي باشد.
همان طور كه هوش مصنوعي مراحل رشد خود را طي مي كند زبانهاي LISP و PROLOG بيشتر مطرح مي شوند.
اين زبانها كار خود را در محدودة توسعه و prototype سازي سيستم هاي AI در صنعت و دانشگاهها دنبال مي كنند.
اطلاعات در مورد اين زبانها به عنوان بخشي از مهارت هر برنامه نويس AI مي باشد ما به بررسي اين دو زبان در هوش مصنوعي مي پردازيم.
آنــــچه را كـــه نمي دانيم موجب دردسر و گرفتاري ما نخواهد شد، بلكه دردسرها از دانسته ها سرچشمه مي گيرند.
لینک دریافت
http://www.4shared.com/file/89432875/50871fae/______.html
با قیمت مناسب (توافقی) اگه خواستید mailبزنید
soroush7000@gmail.com
Preface
Hi, I'm Bart Meijer. I created many programs the last few years, including SnIco Edit (http://www.snidesoft.com/) and a few components. As I didn't find many complete documentation on icons, I decided to create this document. It is also available in DOC format: http://www.snidesoft.com/Updates/documents/ICO.doc. I hope you will find it usefull.
Disclaimer:
Although the format described in this document is used by SnIco Edit there is no 100% guarantee this description is in any way complete or accurate. There is, at least to my knowledge, no official ICO specification made by Microsoft nor any patent or copyright regarding using/editing this format. Use of this information is at your own risk. Comments and suggestions can be sent to meijer
Assumed knowledge of the reader:
- You know what bytes, bits and files are.
- You know somewhat of pixels, colors, palettes, etc.
- You can count :)
Format description
Almost every small image in Windows is an icon. ICO files are small files with small images inside. These images are based on the Bitmap file format. Why not using Bitmaps then? In the early days of Windows 3.11 video cards were expensive and not capable of showing 32-bit colors on a 1024x768 resolution. Because 256 color images would draw awful on a 16 color screen, there was need for images that could be adjusted to the computers. ICO files consist of images in different color depths and Windows can choose the one that best fits the system.
The cursor has CUR as extension. A cursor is an icon that can be used as pointer for you mouse. CUR files are almost identical to icons with exception of the iconinfo structure.
Limitations:
- Up to 65535 images in one file.
- Maximum of 255x255 pixels for each image
- Only one image for each format.
The ICO file
This part of the document describes the ICO file format.
Header
The first 6 bytes in the file is the header. It describes the type and number of icons in this file.
FileHeader (6 bytes)
Reserved (2 bytes), always 0
IconType (2 bytes), if the image is an icon it’s 1, for cursors the value is 2.
IconCount (2 bytes), number of icons in this file.
End
Icon info
After the header for each image in this file there is a 16 byte description. This is useful to determine which image to load rather then browsing the file for each image. If the Icontype is an icon it uses this iconinfo:
IconInfo (icons) (16 bytes)
Width (1 byte), Width of Icon (1 to 255)
Height (1 byte), Height of Icon (1 to 255)
ColorCount (1 byte), Number of colors, either 0 for 24 bit or higher, 2 for monochrome or 16 for 16 color images.
Reserved (1 byte), Not used (always 0)
Planes (2 bytes), always 1
BitCount (2 bytes), number of bits per pixel (1 for monochrome, 4 for 16 colors, 8 for 256 colors, 24 for true colors, 32 for true colors + alpha channel)
ImageSize (4 bytes), Length of resource in bytes
ImageOffset (4 bytes), start of the image in the file.
end
For cursor files the planes is replaced by the x coordinate of the cursor and the bitcount replaced by the y coordinate.
After the image descriptions the actual image data follows. For each image there is a bitmap header, xor-map (referred as color map) and and-map (referred as transparent map).
Image data
First we take a look at the bitmap header. It’s 40 bytes in length and tells us something about the color map.
BitmapHeader (40 bytes)
Size (4 bytes), size of this structure (always 40)
Width (4 bytes), width of the image (same as iconinfo.width)
Height (4 bytes), scanlines in the color map + transparent map (iconinfo.height * 2)
Planes (2 bytes), always 1
BitCount (2 bytes), 1,4,8,24,32 (see iconinfo for details)
Compression (4 bytes), we don’t use this (0)
SizeImage (4 bytes), we don’t use this (0)
XPelsPerMeter (4 bytes), we don’t use this (0)
YPelsPerMeter (4 bytes), we don’t use this (0)
ColorsUsed (4 bytes), we don’t use this (0)
ColorsImportant (4 bytes), we don’t use this (0)
end
We can conclude that this structure is basically added only for compatibility with the bitmap format. If we would add 1 byte to the iconinfo structure we could save 39 bytes for each image. Terrible waste of your disk space ;)
The reading of an image is rather complicated, so I will use the following example to explain: We have a monochrome image (2 colors/1 bit each pixel) with a width and height of 15 pixels.
Following the bitmap header is the palette. This is only used in images with a color depth or 1 (2 colors), 4 (16 colors) or 8 bits (256 colors). I recommend using always the black and white color, because these are necessary for determining inversed transparent pixels. The palette contains for each color 4 bytes (blue, green, red, and not used).
Next the color map. This map contains the color information of every pixel in the image. But watch it: it’s build from bottom up or in other words the first pixel is the bottom-left one.
The value of a pixel in the image is depending on the bitcount either an index of the color in the palette, or an rgb value. For example a bitcount of 1 would every pixel have 2 possibilities: 0 or 1. If the value is 0 the color of the pixel is color 0 in the palette, same goes for a bitcount of 4 or 8. A bitcount of 24 results in 4 bytes for each pixel (blue, green, red, not used). A bitcount of 32 would give the same result as 24 bpp, but the byte ‘not used’ contains the opacity value (0-255) where 0 is fully transparent.
You should read the color map in scanlines. The width of each scanline is (bitcount * width) / 8 bytes rounded up to whole bytes + the number of bytes rounded up to a number dividable by 4, called padding.
The size of the scanline would be
15 pixels x 1 bit = 15 bits
Rounded to whole bytes this makes 2 bytes (16 bits).
The padding of the scanline is 2, because the first number above 2 dividable by 4 is 4.
4 – 2 bytes = 2 bytes padding
The total length of the scanline in bytes is 2 bytes of pixel information and 2 bytes of padding = 4 bytes.
The number of scanlines is the height of the image, the size of the color map in this example would be 4 bytes of the scanline x 15 pixel in height = 60 bytes.
The transparent map is also build out of scanlines. For each pixel there is 1 bit that tells if the pixel is transparent (1) or solid (0). If the pixel is transparent and the color of the pixel is white, the pixel inversed transparent. The width of a scanline is 1\8 * width, rounded to whole bytes, rounded to 4 bytes. You can use the calculation used by the example to calculate this. The size of the transparent map in this example would be 60 bytes.
The total size of the image in this example is the bitmap header (40 bytes) + the palette size (2 colors, 8 bytes) + the size of the color map (60 bytes) + the size of the transparent map (60 bytes) = 168 bytes.
Further information
References
http://www.wotsit.org/download.asp?f=icons, online documentation of icons.
http://www.microsoft.com/, Website of Microsoft creator of Windows.
Definitions
AND-map, transparent map see image data
CUR, extension of the cursor file
Cursor, see format description.
ICO, extension of the icon file
Icon, see format description.
Image, part of an icon file with bitmap header, color map and transparent map.
Palette, array of colors
Windows, the operating system from Microsoft.
XOR-map, color map see image data
Sometimes we need receive alert on client side about some event on SQL server without request. For instance, data is changed and we want notify all client applications. It is possible to realize this option with extended stored procedure contained in dynamic-link library, that send broadcast packets through sockets via UDP. The creation of an extended stored procedure was made in C++ Builder 6, with use of ODS (Open Data Service) API for MS SQL Server 2000. To take into consideration that static library Opends60.lib with this Borland IDE, which realize all services of ODS API, has outdated version and support only MS SQL 7. You may get import library file
from my site or create it self-dependent with Implib utility. Also, to be noticed that UDP not ensure the message delivery, but don’t require a connection, as TCP. This is main reason why UDP was choosen.
The simple example of using alerts is generation event from user audit table's trigger after adding new record. The structure of "EVENT" table consist of unique record identifier, user login and message. The extended stored procedure "xp_event" may has following input parameters:
The TSQLAlerter component has two methods: Start and Stop, which creates new process for port listening and stop it correspondingly, i.e. the client has UDP server roles. The event OnGetMessage comes in the moment of notification delivery, and the pointer to TLabel visual component allows display a getting message at the form. The structure are using for sending broadcast messages has the following view:
// The structure for sending alerts
typedef struct TDATASEND
{
char message[1024];
char login[1024];
long id;
} TDATASEND;
The thread gets an alert and synchronize properties Message, RecordId and Login of TSQLAlerter class object in AddMessage() method. The example of registration procedure and realization of delivery notification you may look in TSQLAlerter.sql script.
In order to talk to Google we need to be able to contact the web server, pretend that we are a regular web browser, and in some cases be able to do a post transaction. Luckily all this is very easy using the standard library WinInet. So here is a small wrapper Delphi unit that will allow you to do exactly that:
This code also requires TRegExpr - a Freeware Delphi Regular Expressions module
unit libWeb; interface uses WinInet; type WebHelper = object BytesRead: Integer; ShouldStop: Boolean; AgentName: string; function DownloadURLAsText( Url: string; var Res: string ): Boolean; function DownloadURLAsFile( Url: string; FileName: string ): Boolean; end; function URLEncode(const S: string): string; implementation uses SysUtils; function URLEncode(const S: string): string; var Idx: Integer; // loops thru characters in string begin Result := ''; for Idx := 1 to Length(S) do begin if S[Idx] in ['A'..'Z', 'a'..'z', '0'..'9', '-', '=', '&', ':', '/', '?', ';', '_', '.'] then Result := Result + S[Idx] else Result := Result + '%' + IntToHex(Ord(S[Idx]), 2); end; end; function WebHelper.DownloadURLAsFile( Url: string; FileName: string ): Boolean; begin end; function WebHelper.DownloadURLAsText( Url: string; var Res: string ): Boolean; const BufferSize = 1024; var hSession, hURL: HInternet; Buffer: array[0..BufferSize] of Byte; BufferLen: Cardinal; f: File; sAppName: string; s: string; begin Result:=False; hSession := InternetOpen(PChar(AgentName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); try hURL := InternetOpenURL(hSession, PChar(Url), nil,0,0,0); try Res := ''; repeat InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen); Buffer[BufferLen] := 0; Res := Res + PChar( @Buffer ); until BufferLen = 0; Result:=True; finally InternetCloseHandle(hURL) end finally InternetCloseHandle(hSession) end end; end.
Now that we have the basics cover let's create the interface for the three functions:
libGoogle.pas - Part 1
unit libGoogle; interface uses Classes, libWeb; function Google_Suggest( phrase_start: string ): TStringList; function Google_Search( keywords: TStringList ): TStringList; function Google_Sets( phrases: string ): TStringList;
Google_Suggest will expand the phrase to the most popular key phrases, and also return the number of results found on Google for each search.
Google_Search is self explanatory, you pass in list of keywords and it will return list of web site titles and URLs
Google_Sets will expand a set of one or more words. For example if you pass in "Los Angeles" and "New York", it will return the following major cities:
Los Angeles, New York, San Francisco, Philadelphia, Dallas, Chicago,
Boston, Seattle, Atlanta, Orlando, Miami, Denver, Minneapolis, Kansas City,
Baltimore, St Louis, Cleveland, Austin, Richmond, Cary Business, Triangle NC
LawyersNC, Atlanta Entrepreneur, Durham Business, Greensboro Business,
Wilmington Business, Charlotte Business, Las Vegas, Washington DC, Houston,
New Orleans, Hawaii, Detroit, San Diego, Pittsburgh, Phoenix, Nashville
Toronto, Sacramento, London, HONOLULU, Portland, Cincinnati, Providence
And now lets look at the implementation of the said functions:
libGoogle.pas - Part 2
implementation uses RegExpr, StrUtils; const UserAgent: string = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'; GoogleSuggestURL: string = 'http://www.google.com/complete/search?hl=en&js=true&qu='; SuggestParse1: string = '^sendRPCDone(frameElement, ".*?", new Array((.*?)), new Array((.*?)), new Array(""));'; GoogleLargeSetsURL: string = 'http://labs.google.com/sets?hl=en&'; function Google_Suggest( phrase_start: string): TStringList; var res: TStringList; web: WebHelper; request: string; t, txt: string; queries, results: string; RegExpr: TRegExpr; p, p2: Integer; begin RegExpr := TRegExpr.Create; request := GoogleSuggestURL + phrase_start; web.AgentName := UserAgent; web.DownloadURLAsText( request, txt ); RegExpr.Expression := SuggestParse1; RegExpr.Exec( txt ); queries := RegExpr.Match[1]; results := RegExpr.Match[2]; Result := TStringList.Create; repeat p := Pos( ',', queries ); if ( p = 0 ) then break; t := MidStr( queries, 1, p - 1 ); queries := MidStr( queries, p + 1, Length( queries ) - p - 1 ); RegExpr.Expression := '"(.*)"'; RegExpr.Exec( t ); txt := RegExpr.Match[1]; p2 := Pos( '",', results ); t := MidStr( results, 1, p2 ); results := MidStr( results, p2 + 2, Length( results ) - p2 - 2 ); RegExpr.Expression := '"(.*)"'; RegExpr.Exec( t ); txt := txt + ' => ' + RegExpr.Match[1]; Result.Add(txt); until p = 0; RegExpr.Free; end; function Google_Search( keywords: TStringList ): TStringList; begin Result := nil; end; function Google_Sets( phrases: string ): TStringList; var request: string; t, txt: string; p: Integer; i: Integer; web: WebHelper; begin request := GoogleLargeSetsURL; i := 0; repeat p := Pos( ',', phrases ); Inc(i); Str(i, txt); request := request + 'q' + txt + '='; if ( p = 0 ) then txt := phrases else txt := LeftStr( phrases, p - 1 ); request := request + txt + ';'; phrases := MidStr( phrases, p + 1, Length(phrases) - p ); until p = 0; request := request + '&btn=Large Set'; request := URLEncode(request); web.AgentName := UserAgent; web.DownloadURLAsText( request, txt ); Result := TStringList.Create; repeat p := Pos( '' , txt ); if ( p = 0 ) then break; txt := RightStr( txt, Length(txt) - p - 7 ); p := Pos( '[/link]', txt ); if ( p = 0 ) then break; if ( p <> Pos( '', txt ) ) then continue; t := LeftStr( txt, p - 1 ); txt := RightStr( txt, Length(txt) - Length(t) - 10 ); Result.Add( t ); until p = 0; end; end.