MySQL
  Home arrow MySQL arrow Page 4 - Lord Of The Strings Part 1
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Lord Of The Strings Part 1
By: Simon White
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 53
    2004-03-15

    Table of Contents:
  • Lord Of The Strings Part 1
  • Word Lists and Databases
  • Word Lists
  • Loading the Text Files to the DB
  • Running the Query

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Lord Of The Strings Part 1 - Loading the Text Files to the DB


    (Page 4 of 5 )

    In addition to the word and its language, there is an identifier (word_id), which is the primary key for the table. Note that I used an enum type for the lang column, since we know we are only going to use a limited set of languages. By using an enum, only one byte need be used to store the value of that column – far less data than if I’d used a varchar. I also added indexes for the lang and word columns to improve execution times for queries that constrain these columns.
    Now for each language, I loaded the words from the text file into the database table. The following two SQL commands load the word list for Danish; the other languages were loaded similarly.


    load data infile 'C:\temp\danish.txt' into table words(word);
    update words set lang
    ='danish' where lang is null;

    Once the word lists were in the database, I carried out one further data cleansing action. I removed any words that were less than three characters long:


    mysqldelete from words where length(word)<3;
    Query OK
    2112 rows affected (4.70 sec)

    Checking the Data
    At this point it is reassuring to run a query to get an overview of the data that we have stored. First, let’s check how many words are in the database. As we have one word per row of the database table, that’s the same as counting the number of rows in the table. The following query counts the number of rows, but also stores that value in a variable, called @total.


    mysqlselect @total:=count(*) as wordcount from words;
    +-----------+
    wordcount |
    +-----------+
    |   1343410 |
    +-----------+
    1 row in set 
    (0.00 sec)

    Now let’s look at the breakdown of the word lists into languages:


    mysqlselect lang as languagecount(word) as wordcount 
           from words group by lang
    ;
    +-----------+-----------+
    language  wordcount |
    +-----------+-----------+
    DANISH    |     25291 |
    DUTCH     |    178341 |
    ENGLISH   |     56355 |
    FINNISH   |    287231 |
    FRENCH    |    138168 |
    GERMAN    |    159989 |
    HUNGARIAN |     17818 |
    JAPANESE  |    115291 |
    LATIN     |     77049 |
    NORWEGIAN |     61679 |
    POLISH    |    109343 |
    SPANISH   |     85965 |
    SWAHILI   |     18363 |
    SWEDISH   |     12057 |
    TOLKIEN   |       470 |
    +-----------+-----------+
    15 rows in set 
    (3.55 sec)

    More MySQL Articles
    More By Simon White


     

    MYSQL ARTICLES

    - MySQL and BLOBs
    - Two Lessons in ASP and MySQL
    - Lord Of The Strings Part 2
    - Lord Of The Strings Part 1
    - Importing Data into MySQL with Navicat
    - Building a Sustainable Web Site
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - PhpED 3.2 – More Features Than You Can Poke ...
    - Creating An Online Photo Album with PHP and ...
    - Creating An Online Photo Album with PHP and ...
    - Security and Sessions in PHP
    - Setup Your Personal Reminder System Using PHP
    - Create a IP-Country Database Using PERL and ...
    - Developing a Dynamic Document Search in PHP ...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway