stevenbuehner/bible-verse-bundle

一个经过高度测试的库,用于解析、识别、合并、存储和操作圣经经文。

2.6.0 2023-03-09 23:24 UTC

README

使用此包,您将获得一个强大的后端来解析任何文本并识别其中的圣经经文。它与symphony兼容,也与其他任何composer系统兼容。圣经经文不仅被识别,而且被智能地分离为书、章节和经文范围。

我在一个大型安装中使用它来存储和索引圣经经文到数据库中,并执行非常快速和复杂的搜索。

功能

该库可以识别德语和英语中所有类型的文本作为圣经经文。例如

  • 1Tim 3,16

  • 1 Tim 3,16f (一个后续经文)

  • 1 Tim 3,15-16 (多个经文作为范围连接)

  • 1 Tim 3,16ff (使用 "ff" 表示章节末尾的后续经文)

  • 1 Timotheus 3,16 (长命名约定)

  • 1 Tim 3,15.16 (多个经文连接)

  • 1 Tim 3,15+16 (多个经文连接)

  • 1. Timothy 3,16 (前缀 "1." 约定)

  • I Timothy 3,16 (前缀 "I" 约定 / 带或不带 ".")

  • First Timothy 3,16 (前缀 "First" 约定)

  • 1st Timothy 3,16 (前缀 "1st" 约定)

  • 1.Timotheusbrief 3,16 (德语长命名约定)

  • 1 Ti 3,16 (不同的简写命名约定)

  • 1Tim 3,16-4,2 (跨越多个章节的范围)

  • 1Tim 3 (整章)

示例

文本被识别并解析为有效的整数。对于1Tim 3,16-17,这将是这样

存储和搜索优化

内部,圣经经文以两个数字存储,这两个数字描述一个范围(开始 - 结束)。这使得可以快速索引圣经经文并搜索相交的圣经经文。

START 和 END 被一起设置为三位数代码

这会产生以下索引

使用方法

将文本解析为圣经经文实体

$service = new BibleVerseService();
$found = $service->stringToBibleVerse('1Tim 3,16');

将圣经经文实体格式化为文本

默认支持德语和英语

foreach($found as $bibleverse){
	// long labels
	echo $service->bibleVerseToString($bibleverse);
	
	// or short labels
	echo $service->bibleVerseToString($bibleverse, 'short');
}

从较大文本中提取圣经经文作为圣经经文实体

$found = $service->stringToBibleVerse('Hello. I learned from 2Tim 3,16 that it differs from Gen 1,1');
// --> $found will be an array with two recognized bibleverses

$rest = $service->getLastRestString();
// --> $rest will be the remaining string, without the found bibleverses = "Hello. I learned from that it differs from "

将多个圣经经文实体连接起来

// Join biblevereses
$found = $service->stringToBibleVerse('Hello. I learned from 2Tim 3,16 that it differs from 2Tim 3,17');
// --> $found will be an array with two recognized bibleverses
$merged = $service->mergeBibleverses($found);
// --> $merged will be an array with ONE bibleverse. Both verses where merged into 2Tim 3,16-17

访问圣经经文的开头和结尾编号

	/**
	 * @return int
	 */
	public function getStart() {
		return $this->start;
	}

	/**
	 * @return int
	 */
	public function getEnd() {
		return $this->end;
	}

圣经经文接口

圣经经文是有效的 BibleVerseInterface 实例。这意味着它们可以被扩展,并具有以下默认功能

	/**
	 * Set From and To bookId
	 * @param integer $bookId
	 */
	public function setBookId($bookId);

	/**
	 * Get bookId
	 * @return int
	 */
	public function getFromBookId();

	/**
	 * Get bookId
	 * @return int
	 */
	public function getToBookId();

	/**
	 * Set $fromBookId
	 * @param integer $fromBookId
	 */
	public function setFromBookId($fromBookId);

	/**
	 * Set $toBookId
	 * @param integer $toBookId
	 */
	public function setToBookId($toBookId);


	/**
	 * Set fromChapter
	 * @param integer $fromChapter
	 */
	public function setFromChapter($fromChapter);

	/**
	 * Get fromChapter
	 * @return int
	 */
	public function getFromChapter();

	/**
	 * Set toChapter
	 * @param integer $toChapter
	 */
	public function setToChapter($toChapter);

	/**
	 * Get toChapter
	 * @return int
	 */
	public function getToChapter();

	/**
	 * Set fromVerse
	 * @param integer $fromVerse
	 */
	public function setFromVerse($fromVerse);

	/**
	 * Get fromVerse
	 * @return int
	 */
	public function getFromVerse();

	/**
	 * Set toVerse
	 *
	 * @param integer $toVerse
	 */
	public function setToVerse($toVerse);

	/**
	 * Get toVerse
	 *
	 * @return int
	 */
	public function getToVerse();

	/**
	 * @param int      $bookId
	 * @param int      $fromChapter
	 * @param int      $fromVerse
	 * @param int|NULL $toChapter
	 * @param int|NULL $toVerse
	 */
	public function setVerse($bookId, $fromChapter, $fromVerse, $toChapter = NULL, $toVerse = NULL);

JavaScript

还有一个用于解析圣经经文的JavaScript库,例如用于markdown的目的。

生成JavaScript库更新

JavaScript库使用以下命令生成

php ./js/Generator/cmd.php