Page 1 of 1

Koinos: PHP Library for working with References and Greek

Posted: December 17th, 2014, 3:38 pm
by Nigel Chapman
Here's a PHP library (also composer package and Symfony Bundle, though can be used by itself).

It's good at matching, manipulating and DB querying for complex biblical references, and at manipulating Unicode Greek text.

This is MIT licensed, so feel free to fork and mod. There is a large Unit Test suite, so you'll know immediately if you've broken anything.


Libraries are defined in CSV files (Resources/libraries/nt/books.csv, and easy to add more):

Code: Select all

107,NT,1 Corinthians,1 Cor,1cor,2,1co,16
To query that book:

Code: Select all

use Koinos\Bundle\KoinosBundle\Service\ReferenceManager;
$rm = new ReferenceManager($libraries=['nt', 'lxx']); 

$ref1 = $rm->createReferenceFromQuery('1 Cor 16:1-5,8,10-12,13-14'); 
echo $rm->getTitle($ref1);  //  1 Corinthians 16:1-5,8,10-14 -- note merged ranges
It can match references in texts and turn them into links, or can identify if they exist in parallels (pipe-separated).

Internally, references are arrays of ranges [start, finish], each value being a quadruple of [bookId, sectionNum, chapterNum, verseNum]. These map to INT(12)s for efficient SQL querying:

Code: Select all

echo $ref1->getSqlClause($columnName='reference'); 

//  (reference BETWEEN 107001016001 AND 107001016005) OR 
//  (reference BETWEEN 107001016008 AND 107001016008) OR 
//  (reference BETWEEN 107001016010 AND 107001016014)  
The Greek utility provides a bundle of useful tools, incl. some for scanning texts, and can romanize any word in the Perseus dataset:

Code: Select all

use Koinos\Bundle\KoinosBundle\Utility\Greek;
$g = new Greek; 

echo $g->romanize('Ῥύγχος');   //  Rhunchos
echo $g->romanize('Ἡσυχάζω');  //  Hēsuchazō
echo $g->romanize('Αὑτοῖσι');  //  Hautoisi

Plenty more info in the, code doc and Test suites...

Re: Koinos: PHP Library for working with References and Gree

Posted: January 10th, 2015, 12:52 pm
by Nigel Chapman
This is now a framework-independent composer library.

See v1.1.1 at

Re: Koinos: PHP Library for working with References and Gree

Posted: January 20th, 2015, 5:57 am
by Nigel Chapman
Koinos is now running a site of mine called It auto-tweets a daily Greek link on (which echoes to facebook).

The site may be useful for easily linking to parallel passages, e.g. today's tweet:'luke+3.23-38.

I'm expecting to open source more of this as it stabilizes.