/** * @param key * @return */ private String getVersification(Key key) { String v11nName=""; if (key instanceof VerseKey) { // must save a VerseKey's versification along with the key! v11nName = ((VerseKey<?>) key).getVersification().getName(); } return v11nName; }
/** * If leftKey is non-null (i.e. not attached to a simple specifier, then adds to the kjvTo mappings * * @param kjvVerses the kjv verses * @param leftKey the left-hand key, possibly null. */ private void addKJVToMapping(final QualifiedKey kjvVerses, final Verse leftKey) { // NOTE(DMS): Both kjvVerses and left key are each a single verse if (leftKey != null) { getNonEmptyKey(this.fromKJVMappings, kjvVerses).addAll(leftKey); // If we have a part, then we need to add the whole verse as well... if (!kjvVerses.isWhole()) { getNonEmptyKey(this.fromKJVMappings, QualifiedKey.create(kjvVerses.getKey().getWhole())).addAll(leftKey); } } }
/** * If for some reason cardinalities of keys are different, we report it. * * @param leftKeys the left hand key * @param kjvKeys the kjv qualified key */ private void reportCardinalityError(final VerseKey leftKeys, final VerseKey kjvKeys) { // TODO (CJB): change this to a neater exception // then something went wrong, as we have remaining verses throw new LucidRuntimeException(String.format("%s has a cardinality of %s whilst %s has a cardinality of %s.", leftKeys, Integer.toString(leftKeys.getCardinality()), kjvKeys, Integer.toString(kjvKeys.getCardinality()))); }
/** * Adds the data into the reverse mappings. Caters for 1-2-1 and 1-2-Many mappings * * @param leftHand the reference of the left hand reference * @param kjvHand the kjv reference/key, qualified with the part */ private void addReverse1ToManyMappings(final Verse leftHand, final QualifiedKey kjvHand) { //add the reverse mapping, for 1-1 mappings if (kjvHand.getAbsentType() == QualifiedKey.Qualifier.ABSENT_IN_KJV || kjvHand.getKey().getCardinality() == 1) { // TODO(CJB): deal with parts addKJVToMapping(kjvHand, leftHand); } else { //add the 1-many mappings //expand the key and add them all //Parts are not supported on ranges... Iterator<Key> kjvKeys = kjvHand.getKey().iterator(); while (kjvKeys.hasNext()) { addKJVToMapping(new QualifiedKey(KeyUtil.getVerse(kjvKeys.next())), leftHand); } } }
/** * Convert this QualifiedKey from one Versification to another. * This is a potentially dangerous operation that does no mapping * from one versification to another. Use it only when it is known * to be safe. * * @param target The target versification * @return The reversified QualifiedKey */ public QualifiedKey reversify(Versification target) { // Only if it has a qualified key can it be reversified if (this.qualifiedKey == null) { return this; } final VerseKey reversifiedKey = qualifiedKey.reversify(target); if (reversifiedKey != null) { return create(reversifiedKey); } if (target.getName().equals(Versifications.DEFAULT_V11N)) { //then we're absent in KJV return new QualifiedKey(qualifiedKey.getOsisID()); } return new QualifiedKey(); }
/** * @param kjvVerses the list of keys * @return the aggregate key */ private VerseKey getKeyFromQualifiedKeys(Versification versification, final List<QualifiedKey> kjvVerses) { final VerseKey finalKey = new RangedPassage(versification); for (QualifiedKey k : kjvVerses) { // we simply ignore everything else at this stage. The other bits // and pieces are used while we're converting // from one to the other. if (k.getKey() != null) { finalKey.addAll(k.getKey()); } } return finalKey; }
@Override public String toString() { StringBuilder buf = new StringBuilder(); if (wholeKey != null) { buf.append(qualifiedKey.getOsisRef()); } String desc = absentType.getDescription(this); if (desc.length() > 0) { if (buf.length() > 0) { buf.append(": "); } buf.append(absentType.getDescription(this)); } return buf.toString(); }
/** * A QualifiedKey is whole if it does not split part of a reference. * * @return whether this QualifiedKey has a whole reference */ public boolean isWhole() { // If the reference is null, then it cannot be part or whole. // But we say it is whole because the calls to this are really testing // to see if it is a part. return qualifiedKey == null || qualifiedKey.isWhole(); }
/** * Allow override of the key, particular useful if we're constructing in 2 stages like the offset mechanism * * @param key the new key */ private void setKey(final VerseRange key) { if (key.getCardinality() == 1) { this.qualifiedKey = key.getStart(); } else { this.qualifiedKey = key; } this.wholeKey = this.qualifiedKey.getWhole(); }
/** * Iterate all books checking if document contains a verse from the book */ private Set<BibleBook> calculateBibleBookList() { final BookMetaData bookMetaData = this.getBookMetaData(); final VerseKey scope = (VerseKey) getScope(); if (scope == null) { return new HashSet<BibleBook>(); } final Set<BibleBook> bookList = new LinkedHashSet<BibleBook>(); // iterate over all book possible in this document final Versification v11n = Versifications.instance().getVersification(bookMetaData.getProperty(BookMetaData.KEY_VERSIFICATION)); final Iterator<BibleBook> v11nBookIterator = v11n.getBookIterator(); while (v11nBookIterator.hasNext()) { BibleBook bibleBook = v11nBookIterator.next(); // test some random verses - normally ch1 v 1 is sufficient - but we don't want to miss any if (scope.contains(new Verse(v11n, bibleBook, 1, 1)) || scope.contains(new Verse(v11n, bibleBook, 1, 2))) { bookList.add(bibleBook); } } return bookList; }
VerseKey leftKeys = leftHand.getKey(); VerseKey kjvKeys = kjvVerses.getKey(); Iterator<Key> leftIter = leftKeys.iterator(); if (kjvKeys != null && kjvKeys.getCardinality() != 1) { int diff = Math.abs(leftKeys.getCardinality() - kjvKeys.getCardinality()); Iterator<Key> kjvIter = kjvKeys.iterator(); while (leftIter.hasNext()) { Verse leftVerse = (Verse) leftIter.next();
/** * This is a last attempt at trying to get something, on the basis that * something is better than nothing. * * @param targetVersification the target versification * @param kjvVerses the verses in the KJV versification. * @return the possible verses in the target versification, no guarantees * made */ private VerseKey guessKeyFromKjvVerses(final Versification targetVersification, final List<QualifiedKey> kjvVerses) { final VerseKey finalKeys = new RangedPassage(targetVersification); for (QualifiedKey qualifiedKey : kjvVerses) { if (qualifiedKey.getKey() != null) { final VerseKey key = qualifiedKey.reversify(targetVersification).getKey(); if (key != null) { //verse key exists in target versification finalKeys.addAll(key); } } } return finalKeys; }
for (Map.Entry<VerseKey, List<QualifiedKey>> entry : this.toKJVMappings.entrySet()) { List<QualifiedKey> kjvVerses = entry.getValue(); String osisRef = entry.getKey().getOsisRef(); for (QualifiedKey q : kjvVerses) { out.println(String.format("\t(%s) %s => (KJV) %s",
/** * Get the versification for the key or the default versification. * * @param key the key that should provide for the Versification * @return the versification for the key */ public static Versification getVersification(Key key) { if (key instanceof VerseKey) { return ((VerseKey) key).getVersification(); } return Versifications.instance().getVersification(Versifications.DEFAULT_V11N); } }
/** * Adds a 1-Many mapping, by simply listing out all the properties. There is probably * a better way for storing this, perhaps in a tree - but for simplicity, we're going to list them out. * * @param leftHand the left hand side operand * @param kjvVerses the verses that are mapped by the left hand side */ private void addMappings(final QualifiedKey leftHand, final QualifiedKey kjvVerses) throws NoSuchVerseException { if (leftHand.getAbsentType() == QualifiedKey.Qualifier.ABSENT_IN_LEFT) { this.absentVerses.addAll(kjvVerses.getKey()); } else if (leftHand.getKey().getCardinality() == 1) { add1ToManyMappings(leftHand.getVerse(), kjvVerses); } else { addManyToMany(leftHand, kjvVerses); } }
if (verseKey != null) { finalKeys.addAll(verseKey);
/** * Cast a Key to a Passage. Only those keys that are a Passage or can * be held by a Passage (i.e. Verse and VerseRange) may be cast to one. * If you pass a null key into this method, you get a null Passage out. * * @param key The key to cast * @return The key cast to a Passage * @throws ClassCastException */ public static Passage getPassage(Key key) { if (key == null) { return null; } if (key instanceof Passage) { return (Passage) key; } if (key instanceof VerseKey) { VerseKey verseKey = (VerseKey) key; Key ref = PassageKeyFactory.instance().createEmptyKeyList(verseKey.getVersification()); ref.addAll(verseKey); return (Passage) ref; } throw new ClassCastException("Expected key to be a Verse, VerseRange or Passage"); }
if (offsetBasis == null || offsetBasis.getCardinality() == 0) {