»
S
I
D
E
B
A
R
«
Ged2DB
Aug 4th, 2009 by Ben Harrington

About

Ged2DB is a small program which converts Genealogical Database Communication (GEDCOM) files to a relational database. This allows much faster access to specific data within the file.

Ged2DB is written in Java so it can run on any system with a compatible runtime environment. The SQL commands used to create and manage the database follow the ANSI SQL-92 standard. The program should work with most JDBC drivers and is known to work with MySQL, PostgreSQL, and HypersonicSQL databases.

This documentation assumes you are familiar with Java, JDBC, and basic database systems. The versions of software such as Java and Ant are based on what I used to build the system. Older versions may work but have not been tested.

Demonstration
Harrington Crest
crest

The Harrington Genealogy Page created and maintained by Donald Harrington relies on Ged2DB for populating the database. The download section contains example websites using Java Server Pages and PHP.

The structure of the database is shown in the entity relationship diagram below. The entities Individual and Family correspond to the individual and family entries in the GEDCOM file. Individuals can be connected via marriage or lineage.

Entity Relationship Diagram
diagram
Downloads
Ged2DB

* Ged2DB 1.0 Binaries (zip)
* Ged2DB 1.0 Binaries (tar.gz)
* Ged2DB 1.0 Source (zip)
* Ged2DB 1.0 Source (tar.gz)

Example Websites

* JSP Website Source (zip)
* JSP Website Source (tar.gz)
* PHP Website Source (zip)
* PHP Website Source (tar.gz)

Installing

Download the appropriate archive from the Ged2DB website. Extract the archive where you want to have Ged2DB installed. After you have extracted the files, open ged.ini and set the properties for the database you want to run. You will need to download the appropriate JDBC drivers for the database you wish to use. Ged2DB will need to use an account that has permission to perform drop, create, and insert commands.

Running

Running Ged2DB requires a Java Runtime Environment 1.3 or higher which is available from http://java.sun.com. To run java must be in your path and type the following command:

java -classpath jdbc_driver.jar -jar ged2db.jar

This will create the database using the settings in ged.ini. The it will use the gedcom specified by the gedcom attribute in the ged.ini file. You can override this property by specifying a file as a parameter, such as:

java -classpath jdbc_driver.jar -jar ged2db.jar mygedcom.ged

It will only look at the first parameter. Any other parameters will be ignored.

Building

If you want to build Ged2DB download and extract one of the source archives. In order to build Ged2DB you will need a Java Software Development Kit 1.3 or higher which is available from http://java.sun.com. You will also need Ant 1.4 which is available from http://ant.apache.org.

To build you must have ant setup and in your path. When this is done, you can build by simply typing ant in the directory where build.xml is located.

VT100 Print Stream
Oct 25th, 2007 by Brian

This class is for generating custom output for ANSI/VT100 terminals. Note, this is not portable and should only be used in environments that understand the ANSI/VT100 control codes. For example, it will not work under the Microsoft Windows Command Prompt. Furthermore, not all systems will support all capabilities such as colors. More information about the terminal control codes can be found at:

This is a fairly simple class. If you need to do complex CUI’s look at CHARVA or JCurses.

Example of Use

This example draws a red box on the screen and puts some cyan text in the middle indicating the progress for printing a test message.

 
public class PrintMode 
{
    public static void main(String[] args)
    {
        VT100PrintStream out=new VT100PrintStream(System.out);
        out.attributeSave();
        out.setDefaultFont(VT100PrintStream.GRAPHICS);
        out.setForeground(VT100PrintStream.RED);
        out.setBackground(VT100PrintStream.BLACK);
 
        // Get dimensions and clear the screen
        int[] dim=out.getDimensions(System.in);
        out.eraseScreen();
 
        // Top of box
        out.cursorTo(1, 1);
        out.print("\u006C");
        for(int i=2; i<dim[0]; i++)
            out.print("\u0071");
        out.print("\u006B");
 
        // Sides of box
        for(int i=2; i<dim[1]; i++)
        {
            out.cursorTo(i, 1);
            out.print("\u0078");
            out.cursorTo(i, dim[0]);
            out.print("\u0078");
        }
 
        // Bottom of box
        out.cursorTo(dim[1], 1);
        out.print("\u006D");
        for(int i=2; i<dim[0]; i++)
            out.print("\u0071");
        out.print("\u006A");
 
        // Put text in the middle
        out.setDefaultFont(VT100PrintStream.US_ASCII);
        out.setForeground(VT100PrintStream.CYAN);
        int textWidth=35;
        int rowOffset=(dim[1]-2)/2;
        int colOffset=(dim[0]-2-textWidth)/2;
        out.cursorTo(rowOffset, colOffset);
        out.print("Please wait, printing something...");
 
        // Print something
        out.startTransparentPrintMode();
        out.println("This is a test page printed from a terminal.");
        out.stopTransparentPrintMode();
 
        // Tell, user they are done
        out.cursorTo(rowOffset+1, colOffset);
        out.print("Done printing, press any key to continue...");
 
        // Pause
        try
        {
            System.in.read();
        }
        catch(Exception e)
        {}
        out.eraseScreen();
        out.attributeRestore();
    }
}

For this example to work correctly the terminal needs to be put in raw mode so that input is not buffered until a newline is encountered. On UNIX systems this can be done using the stty command. For example, the following bash script could be used. This step only needs to be done if a function which takes an input stream as a parameter is used.

#!/bin/bash
stty raw
java -classpath . PrintMode
stty sane

On Mac OS X using the Terminal application this example has the following output.

Download

Website Check
Oct 25th, 2007 by Brian

I occasionally have problems with the power or with a machine that causes the web server on the machine to be inaccessible. This program was written to regularly check the sites that I administer. The program checks a set of URL’s to ensure that it can connect and download the content. A report is generated that gives the status, either “ok” or the message from the exception, of each URL, and the report is sent to me via email. I use cron to run the program at the desired interval.

Example

To use the program you must first setup a configuration file. The first part provides the information needed to send the report:

to           = you@yourdomain.com
from         = you@yourdomain.com
subject      = Website Status Report
mail_server  = cs.unt.edu

The second part provides a list of URL’s to visit. The protocol specifier will be added automatically. Any number of sites can be checked. It will loop through the sites starting with site_0 and will keep going until there is no key site_n. A sample properties file is available in the downloads section.

site_0       = www.yourdomain.com
site_1       = www.yourdomain.com:8080
site_2       = www.someotherdomain.com

To run:

1. Set the classpath with the program itself and the jar files for Commons Email, JavaMail, and the Activation Framework.
2. Run the program with the path to the configuration file as the only parameter.

If everything is in the current working directory the command would look like:

shell$ export CLASSPATH=./:commons-email.jar:javamail.jar:activation.jar
shell$ java SiteCheck sample.properties

Third Party Libraries

* Commons Email: Used to send report via email.
* JavaMail: Needed for commons email.
* Activation Framework: Needed for JavaMail.

Download

* SiteCheck.java
* sample.properties

Web Page Redirection
Oct 25th, 2007 by Brian

I occasionally need to create a page that redirects to another page, e.g, when a site is moved. Three versions are provided here:

* A JSP page that sends a 301 status code indicating a permanent move.
* A PHP page that sends a 301 status code.
* A plain HTML page using the meta refresh tag.

JSP Page

<%
response.setStatus(301);
response.setHeader("Location", "http://www.newurl.com");
%>

PHP Page

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newurl.com");
exit();
?>

Meta Refresh Tag

<html>
 
<head>
    <title>Page Moved</title>
    <meta http-equiv="Refresh" 
        content="0; url=http://www.newurl.com">
</head>
 
<body>
    <h1>Page Moved</h1>
    <p>This page has been moved to <a href="http://www.newurl.com">
        http://www.newurl.com</a>.</p>
</body>
 
</html>
C++ String Utilities
Oct 25th, 2007 by Brian

This project contains the following string functions:

* Levenshtein distance (code from Wikipedia Levenshtein Distance article)

* Soundex, Refined soundex, Metaphone, and Double metaphone (based on code from from Jakarta Commons Codec project)

* Case conversion, trimming whitespace, and startsWith/endsWith. These were mostly to make porting from Java easier.

It is released under the same license as the Jakarta Commons projects, i.e., Apache License Version 2.0.

Building

To build on systems other than FreeBSD:

% tar -xzvf stringutils.tar.gz
% cd stringutils
% make

To build on FreeBSD (uses gmake instead of make):

% tar -xzvf stringutils.tar.gz
% cd stringutils
% make -f makefile.freebsd

It is a good idea to run the test program after building. This should find any problems with the code on your particular system.

% make test

This code has been compiled and tested on the following systems without warnings or errors:

    * gcc (GCC) 4.0.2 20051125 (Red Hat 4.0.2-8)
    * i686-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5250)
    * powerpc-apple-darwin8-gcc-4.0.0 (GCC) 4.0.0 (Apple Computer, Inc. build 5026)
    * gcc (GCC) 3.4.2 (mingw-special)
    * gcc (GCC) 3.3.5 (Debian 1:3.3.5-13)
    * gcc (GCC) 3.3.3 (cygwin special)
    * gcc (GCC) 2.95.4 (FreeBSD 4.11-RELEASE-p14 i386) 

Example of Use

The following example shows the basic use of string encoders for the various phonetic encoding methods (EncoderExample.cpp).

 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
 
#include "Soundex.h"
#include "Metaphone.h"
 
using namespace std;
 
int main(int argc, char* argv[])
{
    vector<Encoder *> encoders;
    encoders.push_back(new Soundex());
    encoders.push_back(new RefinedSoundex());
    encoders.push_back(new Metaphone());
    encoders.push_back(new DoubleMetaphone());
    encoders.push_back(new DoubleMetaphone(false));
 
    string names[]={"Soundex", "Refined soundex", "Metaphone", 
        "Double metaphone (pri)", "Double metaphone (alt)"};
 
    for(int i=1; i<argc; i++)
    {
        cout<<setw(30)<<"Word"<<": "<<argv[i]<<endl;
        for(unsigned j=0; j<encoders.size(); j++)
            cout<<setw(30)<<names[j]<<": "<<encoders[j]->encode(argv[i])<<endl;
        cout<<endl;
    }
 
    while(!encoders.empty())
    {
        Encoder *e=encoders.back();
        encoders.pop_back();
        delete e;
    }
    return 0;
}

The double metaphone class always calculates the primary and alternate. To access both without recalculating use the encodeString function as shown in the example below (DMExample.cpp).

 
#include <iostream>
#include <iomanip>
#include <string>
 
#include "Metaphone.h"
 
using namespace std;
 
int main(int argc, char* argv[])
{
    DoubleMetaphone dm;
 
    for(int i=1; i<argc; i++)
    {
        DoubleMetaphoneResult result=dm.encodeString(argv[i]);
        cout<<setw(30)<<"Word"<<": "<<argv[i]<<endl;
        cout<<setw(30)<<"Primary"<<": "<<result.getPrimary()<<endl;
        cout<<setw(30)<<"Alternate"<<": "<<result.getAlternate()<<endl;
        cout<<endl;
    }
 
    return 0;
}

These techniques and a few other convenient functions are also available through the StringUtils class as shown in the example below (StringUtilsExample.cpp).

 
#include <iostream>
#include <iomanip>
#include <string>
 
#include "StringUtils.h"
 
using namespace std;
 
int main(int argc, char* argv[])
{
    for(int i=1; i<argc; i++)
    {
        cout<<setw(30)<<"Word"<<": ["<<argv[i]<<"]"<<endl;
 
        cout<<setw(30)<<"toUpperCase"<<": ["
            <<StringUtils::toUpperCase(argv[i])<<"]"<<endl;
        cout<<setw(30)<<"toLowerCase"<<": ["
            <<StringUtils::toLowerCase(argv[i])<<"]"<<endl;
 
        cout<<setw(30)<<"trim"<<": ["
            <<StringUtils::trim(argv[i])<<"]"<<endl;
 
        if(StringUtils::startsWith(argv[i], "b"))
            cout<<setw(30)<<"startsWith"<<": b -> [yes]"<<endl;
        else
            cout<<setw(30)<<"startsWith"<<": b -> [no]"<<endl;
        if(StringUtils::endsWith(argv[i], "b"))
            cout<<setw(30)<<"endsWith"<<": b -> [yes]"<<endl;
        else
            cout<<setw(30)<<"endsWith"<<": b -> [no]"<<endl;
 
        cout<<setw(30)<<"levenshtein"<<": b -> ["
            <<StringUtils::levenshtein(argv[i], "b")<<"]"<<endl;
 
        cout<<setw(30)<<"soundex"<<": ["
            <<StringUtils::soundex(argv[i])<<"]"<<endl;
        cout<<setw(30)<<"refinedSoundex"<<": ["
            <<StringUtils::refinedSoundex(argv[i])<<"]"<<endl;
        cout<<setw(30)<<"metaphone"<<": ["
            <<StringUtils::metaphone(argv[i])<<"]"<<endl;    
        cout<<setw(30)<<"doubleMetaphone (pri)"<<": ["
            <<StringUtils::doubleMetaphone(argv[i])<<"]"<<endl;    
        cout<<setw(30)<<"doubleMetaphone (alt)"<<": ["
            <<StringUtils::doubleMetaphone(argv[i], false)<<"]"<<endl;    
 
        cout<<endl;
    }
    return 0;
}

Download

stringutils.tar.gz

»  Substance: WordPress   »  Style: Ahren Ahimsa