public class VersificationToKJVMapper extends Object
A properties-like file will contain the non-KJV versification as they key, and the KJV versification value as the target value... Duplicate keys are allowed.
i.e. Gen.1.1=Gen.1.2 means Gen.1.1 in X versification is Gen.1.2 in the KJV versification
You can specify a range on either side. If a range is present on both sides, they have to have the same number of
verses, i.e. verses are mapped verse by verse to each other
Gen.1.1-Gen.1.2=Gen.1.2-Gen.1.3 means Gen.1.1=Gen.1.2 and Gen.1.2=Gen.1.3
Note: if the cardinality of the left & KJV sides are different by only one, the algorithm makes the
assumption that verse 0 should be disregarded in both ranges.
Mappings can be specified by offset. In this case, be aware this maps verse 0 as well. So for example:
Ps.19-Ps.20=-1 means Ps.19.0=Ps.18.50, Ps.19.1=Ps.19.0, Ps.19.2=Ps.19.1, etc.
It does not make much sense to have an offset for a single verse, so this is not supported.
Offsetting for multiple ranges however does, and operates range by range, i.e. each range is calculated separately.
Offsetting is somewhat equivalent to specifying ranges, and as a result, the verse 0 behaviour is identical.
You can use part-mappings. This is important if you want to preserve transformations from one side to another without losing resolution of the verse.
For example,
if V1 defines Gen.1.1=Gen.1.1, Gen.1.2=Gen1.1
if V2 defines Gen.1.1=Gen.1.1, Gen.1.2=Gen.1.1
then, mapping from V1=>KJV and KJV=>V2 gives you Gen.1.1=>Gen.1.1=>Gen.1.1-Gen.1.2 which is inaccurate if in fact
V1(Gen.1.1) actually equals V2(Gen.1.1). So instead, we use a split on the right hand-side:
For example,
V1 defines Gen.1.1=Gen1.1!a, Gen.1.2=Gen.1.1!b
V2 defines Gen.1.1=Gen1.1!a, Gen.1.2=Gen.1.1!b
then, mapping from V1=>KJV and KJV=>V2 gives you Gen.1.1=>Gen.1.1!a=>Gen.1.1, which is now accurate.
A part is a string fragment placed after the end of a key reference. We cannot use # because that is commonly known
as a comment in real properties-file. Using a marker, means we can have meaningful part names if we so choose.
Parts of ranges are not supported.
Note: splits should never be seen by a user. The mapping from one versification to another is abstracted such that the user can simply request the mapping between 2 verse (ranges).
Unmapped verses can be specified by inventing ids, either for whole sections, or verse by verse (this would come in handy if two versifications have the same content, but the KJV doesn't). A section must be preceded with a '?' character indicating that there will be no need to try and look up a reference. Gen.1.1=?NewPassage
Since not specifying a verse mappings means there is a 1-2-1 unchanged mapping, we need a way of specifying
absent verses altogether:
?=Gen.1.1
?=Gen.1.5
means that the non-KJV book simply does not contain verses Gen.1.1 and Gen.1.5 and therefore can't
be mapped.
We allow some global flags (one at present):
!zerosUnmapped : means that any mapping to or from a zero verse
TODO(CJB): think about whether when returning, we should clone, or make things immutable.
The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private Passage |
absentVerses |
private Map<QualifiedKey,Passage> |
fromKJVMappings |
private boolean |
hasErrors |
private static Versification |
KJV |
private static org.slf4j.Logger |
LOGGER |
private Versification |
nonKjv |
private OsisParser |
osisParser |
private Map<VerseKey,List<QualifiedKey>> |
toKJVMappings |
Constructor and Description |
---|
VersificationToKJVMapper(Versification nonKjv,
FileVersificationMapping mapping) |
Modifier and Type | Method and Description |
---|---|
private void |
add1ToManyMappings(Verse leftHand,
QualifiedKey kjvHand)
A simple two way entry between 2 1-1 entries.
|
private void |
addForwardMappingFromSingleKeyToRange(Verse leftHand,
QualifiedKey kjvHand)
Adds a forward mappings from left to KJV.
|
private void |
addKJVToMapping(QualifiedKey kjvVerses,
Verse leftKey)
If leftKey is non-null (i.e.
|
private void |
addManyToMany(QualifiedKey leftHand,
QualifiedKey kjvVerses)
Adds a many to many mapping, mappings all the verses on the left hand side to all the verses on the right hand side.
|
private void |
addMappings(QualifiedKey leftHand,
QualifiedKey kjvVerses)
Adds a 1-Many mapping, by simply listing out all the properties.
|
private void |
addReverse1ToManyMappings(Verse leftHand,
QualifiedKey kjvHand)
Adds the data into the reverse mappings.
|
private Passage |
createEmptyPassage(Versification versification)
Simplify creation of an empty passage object of the default type, with the required v11n.
|
void |
dump(PrintStream out)
Dump a debug representation of this map to the output stream.
|
private QualifiedKey |
getAbsentQualifiedKey(Versification versification,
String versesKey)
Deals with absent markers, whether absent in the KJV or absent in the current versification.
|
private QualifiedKey |
getExistingQualifiedKey(Versification versification,
String versesKey)
Deals with real keys found in the versification.
|
private VerseKey |
getNonEmptyKey(Map<QualifiedKey,Passage> mappings,
QualifiedKey key)
Gets a non-empty key list, either new or the one existing in the map already.
|
private <T,S> List<S> |
getNonEmptyMappings(Map<T,List<S>> mappings,
T key)
Gets a non-empty list, either new or the one existing in the map already
|
private QualifiedKey |
getOffsetQualifiedKey(Versification versification,
String versesKey,
VerseKey offsetBasis)
Deals with offset markers, indicating a passage is +x or -x verses from this one.
|
private List<QualifiedKey> |
getQualifiedKeys(Key leftKey) |
private QualifiedKey |
getRange(Versification versification,
String versesKey,
VerseKey offsetBasis)
Expands a reference to all its verses
|
(package private) boolean |
hasErrors()
Returns whether we initialised with errors
|
List<QualifiedKey> |
map(QualifiedKey qualifiedKey)
Maps the full qualified key to its proper equivalent in the KJV.
|
private void |
processEntry(KeyValuePair entry) |
private void |
processMappings(FileVersificationMapping mappings)
This is the crux of the decoding facility.
|
private void |
reportCardinalityError(VerseKey leftKeys,
VerseKey kjvKeys)
If for some reason cardinalities of keys are different, we report it.
|
private void |
trace()
Outputs the mappings for debug purposes to the log file.
|
VerseKey |
unmap(QualifiedKey kjvVerse)
Converts a KJV verse to the target versification, from a qualified key, rather than a real key
|
private Versification nonKjv
private Passage absentVerses
private Map<VerseKey,List<QualifiedKey>> toKJVMappings
private Map<QualifiedKey,Passage> fromKJVMappings
private boolean hasErrors
private OsisParser osisParser
private static final Versification KJV
private static final org.slf4j.Logger LOGGER
public VersificationToKJVMapper(Versification nonKjv, FileVersificationMapping mapping)
nonKjv
- a versification that is not the KJVmapping
- the mappings from one versification to anotherprivate void processMappings(FileVersificationMapping mappings)
mappings
- the input mappings, in a contracted, short-hand formprivate void processEntry(KeyValuePair entry) throws NoSuchKeyException
NoSuchKeyException
private void addMappings(QualifiedKey leftHand, QualifiedKey kjvVerses) throws NoSuchVerseException
leftHand
- the left hand side operandkjvVerses
- the verses that are mapped by the left hand sideNoSuchVerseException
private void addManyToMany(QualifiedKey leftHand, QualifiedKey kjvVerses)
leftHand
- is assumed to be manykjvVerses
- could be 1 or manyprivate void reportCardinalityError(VerseKey leftKeys, VerseKey kjvKeys)
leftKeys
- the left hand keykjvKeys
- the kjv qualified keyprivate void addKJVToMapping(QualifiedKey kjvVerses, Verse leftKey)
kjvVerses
- the kjv versesleftKey
- the left-hand key, possibly null.private void add1ToManyMappings(Verse leftHand, QualifiedKey kjvHand) throws NoSuchVerseException
leftHand
- the verse on the left side, left is assumed to be 1 verse onlykjvHand
- the KJV referenceNoSuchVerseException
private void addReverse1ToManyMappings(Verse leftHand, QualifiedKey kjvHand)
leftHand
- the reference of the left hand referencekjvHand
- the kjv reference/key, qualified with the partprivate void addForwardMappingFromSingleKeyToRange(Verse leftHand, QualifiedKey kjvHand)
leftHand
- the left hand reference (corresponding to a non-kjv versification)kjvHand
- the kjv reference (with part if applicable).private VerseKey getNonEmptyKey(Map<QualifiedKey,Passage> mappings, QualifiedKey key)
mappings
- the map from key to list of valueskey
- the keyprivate <T,S> List<S> getNonEmptyMappings(Map<T,List<S>> mappings, T key)
T
- the type of the keyS
- the type of the valuemappings
- the map from key to list of valueskey
- the keyprivate QualifiedKey getRange(Versification versification, String versesKey, VerseKey offsetBasis) throws NoSuchKeyException
versesKey
- the versesNoSuchKeyException
private QualifiedKey getOffsetQualifiedKey(Versification versification, String versesKey, VerseKey offsetBasis) throws NoSuchKeyException
versification
- the versification of the passed in keyversesKey
- the text of the reference we are trying to parseNoSuchKeyException
private QualifiedKey getExistingQualifiedKey(Versification versification, String versesKey)
versification
- the versification of the passed in keyversesKey
- the text of the reference we are trying to parseprivate QualifiedKey getAbsentQualifiedKey(Versification versification, String versesKey)
versification
- the versification of the passed in keyversesKey
- the text of the reference we are trying to parseprivate List<QualifiedKey> getQualifiedKeys(Key leftKey)
public List<QualifiedKey> map(QualifiedKey qualifiedKey)
qualifiedKey
- the qualified keypublic VerseKey unmap(QualifiedKey kjvVerse)
kjvVerse
- the verse from the KJVprivate void trace()
public void dump(PrintStream out)
out
- boolean hasErrors()
private Passage createEmptyPassage(Versification versification)
versification
- required v11n for new Passage