项目作者: joshpetit

项目描述 :
Parse strings for bible references
高级语言: Dart
项目地址: git://github.com/joshpetit/reference_parser.git
创建时间: 2020-09-29T20:07:32Z
项目社区:https://github.com/joshpetit/reference_parser

开源协议:BSD 3-Clause "New" or "Revised" License

下载


reference_parser

A dart package that parses strings for bible references. You can parse single references or
multiple references from a string in a variety of formats and also identify a text to
its potential match in the bible.

Really 99% of what you need to know will be found in the
Parsing References and Identifying References
headers. But if you have more complicated needs this package can handle those!

Usage

to include the default exports of reference parser add this to your imports:

  1. import package:reference_parser/reference_parser.dart`

Parsing References

use the parseReference function to retrieve a single reference:

  1. var ref = parseReference("I like Mat 2:4-10 and John 3:1");

This will return a reference object describing ‘Matthew 2:4-10’.

use the parseAllReference to retrieve all references within a string.

  1. var refs = parseAllReferences('I enjoy reading Gen 5:7 and 1Co 2-3');

Note: The word ‘is’ will be parsed as the book of Isaiah.

Identifying References

import the identification library with:

import 'package:reference_parser/identification.dart';

then identify references like this:

  1. identifyReference("Come to me all ye").then((possibilities) => {
  2. print(possibilities[0]), // The most likely match would be at index 0
  3. });

The identifyReference method uses biblehub.com.
It will return a PassageQuery object that contains a Reference object along with
a preview of the verse and the original query.

Objects and References

Reference

Reference objects are the broadest kind of reference.
You can directly construct one by following this format:

  1. var ref = Reference(book, [startChp, startVer, endChp, endVer]);

(for ease of use the Reference class has multiple named
constructorsr. Look here and at the API reference.)

Their most important fields are these:

  1. ref.reference // The string representation (osisReference, shortReference, and abbr also available)
  2. ref.startVerseNumber
  3. ref.endVerseNumber
  4. ref.startChapterNumber
  5. ref.endChapterNumber
  6. ref.referenceType // VERSE, CHAPTER, VERSE_RANGE, CHAPTER_RANGE

Based on what is passed in, the constructor will figure out
certain fields. For example, if you were to construct Reference('James')
the last chapter and verse numbers in James will be initialized accordingly.

There are many other fields that may prove useful such as
ones that subdivid the reference, look here


Verses

Reference objects have a startVerse and endVerse field
that return objects of the Verse type.

  1. var firstVerse = ref.startVerse;
  2. var randomVerse = Verse(book, chapter, verse);

You can also construct References that ‘act’ like
verses by using the named constructor

  1. var ref = Reference.verse(book, chapter, verse);

Chapters

  1. ref = parseReference("James 5 is a chapter");

The ref object now holds a Reference to “James 5”. Despite this, startVerseNumber and endVerseNumber are initialized to the first and last verses in James 5.

  1. ref.startVerseNumber // 1
  2. ref.endVerseNumber // 20
  3. ref.referenceType // ReferenceType.CHAPTER

The Reference object also has start/end chapter fields

  1. var ref = parseReference('James 5-10 is cool');
  2. ref.startChapterNumber // 5
  3. ref.endChapterNumber // 10

Just like verses you can create chapter objects:

  1. var chp = Chapter(book, chapter);

Books

  1. var ref = parseReference("Ecclesiastes is hard to spell");
  2. ref.startChapterNumber // 1
  3. ref.endChapterNumber // 12
  4. ref.ReferenceType // ReferenceType.BOOK

Books don’t have their own class, they’re the equivalent of
a Reference object.

Constructing References

Verses

  1. var ref = Reference("Mat", 2, 4);
  2. var ref = Reference.verse("Mat", 2, 4);
  3. var verse = Verse("Matt", 2, 4);

Note that the verse object has different fields than a
Reference object. Check the API.

Verse Ranges

  1. ref = Reference("Mat", 2, 4, null, 10);
  2. ref = Reference.verseRange("Mat", 2, 4, 10);

These are equivalents that create a reference to ‘Matthew 2:4-10’.

The same constructors and classes apply for chapters.

Invalid References

All references have an isValid field that says whether this reference
is within the bible.

  1. var ref = Reference("McDonald", 2, 4, 10);
  2. print(ref.isValid) // false, as far as I know at least.

Notice that the other fields are still initialized!! So if needed, make
sure to check that a reference is valid before using it.

  1. ref.reference // "McDonald 2:4-10"
  2. ref.book // "McDonald"
  3. ref.startVerseNumber // 4
  4. ref.osisBook // null, and so will be other formats.

The same logic applies to chapters and verse numbers.

  1. ref = Reference("Jude", 2, 10);
  2. ref.isValid // false (Jude only has one chapter)

Other fun stuff

I made this library bloat so it can do a lot haha.

  1. ref.verses // returns a list of verse objects within this reference. There's Also one for chapters.
  2. ref.chapters // each chapter
  3. ref.osisReference // the osis representation (there's also short, and abbr)