Skip to content

Commit

Permalink
Initial codes
Browse files Browse the repository at this point in the history
* +autogen.sh:
  - autotools invoking script
* +AUTHORS, +NEWS, +README:
  - Add required files for automake
* +configure.ac, +Makefile.am:
  - autotools stuffs
* +sylstring/Makefile.am:
* +sylstring/sylcomp.h:
* +sylstring/sylcomp.inl:
* +sylstring/sylcomp.cxx:
  - Initial code for Thai syllable components.
* +sylstring/tests/Makefile.am:
* +sylstring/tests/test-sylcomp.cxx:
  - Tests for sylcomp.
  • Loading branch information
thep committed Jan 22, 2018
0 parents commit f1ceb08
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 0 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Theppitak Karoonboonyanan <theppitak@gmail.com>
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SUBDIRS = sylstring

Empty file added NEWS
Empty file.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
thaipronun is a program for transliterating Thai words, either into
Thai pronunciation or in Romanized form.
26 changes: 26 additions & 0 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

set -x

DIE=0

# Detect [g]libtoolize
if libtoolize --version > /dev/null 2>&1; then
LIBTOOLIZE=libtoolize
elif glibtoolize --version > /dev/null 2>&1; then
LIBTOOLIZE=glibtoolize
else
echo "**Error**: Missing 'libtoolize'"
DIE=1
fi

if [ $DIE -eq 1 ]; then
exit 1
fi

${LIBTOOLIZE} --force
aclocal
automake --foreign --add-missing
# Use -f so git-version-gen does refresh
autoconf -f

28 changes: 28 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ([2.69])
AC_INIT([thpronun],
[0.0.0],
[theppitak@gmail.com])
AC_CONFIG_SRCDIR([sylstring/sylcomp.h])
AC_CONFIG_MACRO_DIRS([m4])

AM_INIT_AUTOMAKE(dist-xz no-dist-gzip)

# Checks for programs.
AC_PROG_CXX
AM_PROG_LIBTOOL

# Checks for libraries.

# Checks for header files.

# Checks for typedefs, structures, and compiler characteristics.

# Checks for library functions.

AC_CONFIG_FILES([Makefile
sylstring/Makefile
sylstring/tests/Makefile])
AC_OUTPUT
10 changes: 10 additions & 0 deletions sylstring/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SUBDIRS = tests

lib_LTLIBRARIES = libsylstring.la

libsylstring_la_SOURCES = \
sylcomp.cxx \
sylcomp.h \
sylcomp.inl \
$(NULL)

69 changes: 69 additions & 0 deletions sylstring/sylcomp.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// sylcomp.cxx - Thai syllable fundamental components
// Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
// Created: 2018-01-15

#include "sylcomp.h"

#include <cassert>

using namespace std;

#define IC EInitConstClass

static EInitConstClass InitConstClassTbl_[46] = {
// ก ข ฃ ค ฅ ฆ ง
IC::MID, IC::HIGH, IC::HIGH, IC::LOWP, IC::LOWP, IC::LOWP, IC::LOWS,
// จ ฉ ช ซ ฌ ญ
IC::MID, IC::HIGH, IC::LOWP, IC::LOWP, IC::LOWP, IC::LOWS,
// ฎ ฏ ฐ ฑ ฒ ณ
IC::MID, IC::MID, IC::HIGH, IC::LOWP, IC::LOWP, IC::LOWS,
// ด ต ถ ท ธ น
IC::MID, IC::MID, IC::HIGH, IC::LOWP, IC::LOWP, IC::LOWS,
// บ ป ผ ฝ พ ฟ ภ ม
IC::MID, IC::MID, IC::HIGH, IC::HIGH, IC::LOWP, IC::LOWP, IC::LOWP, IC::LOWS,
// ย ร ฤ ล ฦ ว
IC::LOWS, IC::LOWS, IC::LOWS, IC::LOWS, IC::LOWS, IC::LOWS,
// ศ ษ ส ห ฬ อ ฮ
IC::HIGH, IC::HIGH, IC::HIGH, IC::HIGH, IC::LOWS, IC::MID, IC::LOWP
};

#undef IC

EInitConstClass
InitConstClass (char32_t c)
{
assert (0x0e01 <= c && c <= 0x0e2e);
return InitConstClassTbl_[c - 0x0e01];
}

#define EC EEndConstClass

static EEndConstClass EndConstClassTbl_[46] = {
// ก ข ฃ ค ฅ ฆ ง
EC::KOK, EC::KOK, EC::KOK, EC::KOK, EC::KOK, EC::KOK, EC::KONG,
// จ ฉ ช ซ ฌ ญ
EC::KOT, EC::KOT, EC::KOT, EC::KOT, EC::KOT, EC::KON,
// ฎ ฏ ฐ ฑ ฒ ณ
EC::KOT, EC::KOT, EC::KOT, EC::KOT, EC::KOT, EC::KON,
// ด ต ถ ท ธ น
EC::KOT, EC::KOT, EC::KOT, EC::KOT, EC::KOT, EC::KON,
// บ ป ผ ฝ พ ฟ ภ ม
EC::KOP, EC::KOP, EC::KOP, EC::KOP, EC::KOP, EC::KOP, EC::KOP, EC::KOM,
// ย ร ฤ ล ฦ ว
EC::KOEY, EC::KON, EC::NONE, EC::KON, EC::NONE, EC::KOEW,
// ศ ษ ส ห ฬ อ ฮ
EC::KOT, EC::KOT, EC::KOT, EC::NONE, EC::KON, EC::NONE, EC::NONE
};

#undef EC

EEndConstClass
EndConstClass (char32_t c)
{
assert (0x0e01 <= c && c <= 0x0e2e);
return EndConstClassTbl_[c - 0x0e01];
}

/*
vi:ts=4:ai:expandtab
*/
120 changes: 120 additions & 0 deletions sylstring/sylcomp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// sylcomp.h - Thai syllable fundamental components
// Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
// Created: 2018-01-15

#ifndef SYLCOMP_H
#define SYLCOMP_H

// Internal syllable encoding
// Ex:
// กก -> k_ok1
// โกรธ -> krOt1
// โค้ก -> c_Ok3
// ควาย -> cwAy0
// ไกล -> klay0
// ใกล้ -> klay2

enum class EInitConst {
KA = 'k', // ก
KHA = 'c', // ข ฃ ค ฅ ฆ
NGA = 'g', // ง
JA = 'j', // จ
CHA = 'J', // ฉ ช ฌ
YA = 'y', // ญ ย
DA = 'd', // ฎ ด
TA = 't', // ฏ ต
THA = 'T', // ฐ ฑ ฒ ถ ท ธ
NA = 'n', // ณ น
BA = 'b', // บ
PA = 'p', // ป
PHA = 'P', // ผ พ ภ
FA = 'f', // ฝ ฟ
MA = 'm', // ม
RA = 'r', // ร
LA = 'l', // ล ฬ
WA = 'w', // ว
SA = 's', // ซ ศ ษ ส
HA = 'h', // ห ฮ
A = '?', // อ
};

enum class ESecInitConst {
NONE = '_',
RA = 'r', // ร ควบ
LA = 'l', // ล ควบ
WA = 'w', // ว ควบ
};

enum class EVowel {
A = 'a', // อะ
AA = 'A', // อา
I = 'i', // อิ
II = 'I', // อี
UE = 'v', // อึ
UEE = 'V', // อือ
U = 'u', // อุ
UU = 'U', // อู
E = 'e', // เอะ
EE = 'E', // เอ
AE = 'x', // แอะ
AEE = 'X', // แอ
IA = 'y', // เอียะ
IAA = 'Y', // เอีย
UEA = 'z', // เอือะ
UEAA = 'Z', // เอือ
UA = 't', // อัวะ
UAA = 'T', // อัว
O = 'o', // โอะ
OO = 'O', // โอ
AU = 'c', // เอาะ
AUU = 'C', // ออ
OE = 'w', // เออะ
OEE = 'W', // เออ
};

bool
IsShortVowel (EVowel v);

enum class EEndConstClass {
NONE = '_', // แม่ ก กา
KOK = 'k', // แม่กก
KOT = 't', // แม่กด
KOP = 'p', // แม่กบ
KONG = 'g', // แม่กง
KON = 'n', // แม่กน
KOM = 'm', // แม่กม
KOEY = 'y', // แม่เกย
KOEW = 'w', // แม่เกอว
};

bool
IsDeadEndConst (EEndConstClass c);

enum class ETone {
SAMAN = '0',
EK = '1',
THO = '2',
TRI = '3',
CHATTAWA = '4',
};

enum class EInitConstClass {
HIGH,
MID,
LOWP,
LOWS,
};

EInitConstClass
InitConstClass (char32_t c);

EEndConstClass
EndConstClass (char32_t c);

#include "sylcomp.inl"

#endif // SYLCOMP_H

/*
vi:ts=4:ai:expandtab
*/
20 changes: 20 additions & 0 deletions sylstring/sylcomp.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// sylcomp.inl - Thai syllable fundamental components
// Author: Theppitak Karoonboonyanan <theppitak@gmail.com>
// Created: 2018-01-15

#include <cctype>

inline bool
IsShortVowel (EVowel v)
{
return std::islower (static_cast<int> (v));
}

inline bool
IsDeadEndConstClass (EEndConstClass c)
{
return EEndConstClass::KOK == c ||
EEndConstClass::KOT == c ||
EEndConstClass::KOP == c;
}

15 changes: 15 additions & 0 deletions sylstring/tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TESTS = \
test-sylcomp \
$(NULL)

check_PROGRAMS = \
test-sylcomp \
$(NULL)

AM_CPPFLAGS = -I$(top_srcdir)

test_sylcomp_SOURCES = \
test-sylcomp.cxx \
$(NULL)
test_sylcomp_LDADD = $(top_builddir)/sylstring/libsylstring.la

Loading

0 comments on commit f1ceb08

Please sign in to comment.