public class PassageTally extends AbstractPassage
Currently there is no well defined spec for what the rank of a verse means - it is just an int. Since this number is exposed in 2 places (getNameAndTally() and getTallyFor()) we should specify what the numbers mean. Trouble is most tallies come from searches where the numbers only have relative meaning.
This class exactly implements the Passage interface when the ordering is set to Order.BIBLICAL, however an additional setting of Order.TALLY sorts the verses by the rank in this tally.
Calling tally.add(Gen 1:1); tally.add(Gen 1:1);
is redundant for
a Passage however a PassageTally will increase the rank of Gen 1:1, there are
additional methods unAdd()
and unAddAll()
that do
the reverse, of decreasing the rank of the specified verse(s).
The point is to allow a search for "God loves us, and gave Jesus to die to save us" to correctly identify John 3:16. So we are using fuzzy matching big style, but I think this will be very useful.
How should we rank VerseRanges? We could use a sum of the ranks of the verses in a range or the maximum value of a range. The former would seem to be more mathematically correct, but I think that the latter is better because: the concept of max value is preserved, because a wide blurred match is generally not as good as a sharply defined one.
Should we be going for a PassageTallyFactory type approach? Of the 3 implementations of Passage, The RangedPassage does not make sense here, and a PassageTally will not have the range of uses that a Passage has, so I think there is more likely to be a correct answer. So right now the answer is no.
Memory considerations: The BitSet approach will always use a
int[31000]
= 128k of memory.
The Distinct approach will be n * int[4] where n is the number of verses
stored. I expect most searches to have at least n=1000. Also 128k
Given this, (A Distinct style PassageTally will usually use more memory than
a BitSet style PassageTally) And the intuitive result that the BitSet will be
faster, I'm going to start by implementing the latter only.
To think about - I've upped the MAX_TALLY to 20000 to help the new mapper program. I'm not sure why it was originally 100?
LATER(joe): Specify how passage ranks work.
The GNU Lesser General Public License for details.
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
PassageTally.Order
Indicates how this PassageTally is to order it's Verses.
|
private static class |
PassageTally.OrderedVerseIterator
Iterate over the Verses in order of their rank in the tally
|
private static class |
PassageTally.OrderedVerseRangeIterator
Iterate over the Ranges in order of their rank in the tally
|
private static class |
PassageTally.TalliedVerse
Hack to make this work with J2SE 1.1 as well as J2SE 1.2 This compared 2
Integers
|
private static class |
PassageTally.TalliedVerseRange
Hack to make this work with JDK1.1 as well as JDK1.2 This compared 2
Integers
|
private class |
PassageTally.VerseIterator
Iterate over the Verses in normal verse order
|
AbstractPassage.VerseRangeIterator
Modifier and Type | Field and Description |
---|---|
protected int[] |
board
The tally board itself
|
private static org.slf4j.Logger |
log
The log stream
|
private int |
max
The maximum tally possible
|
static int |
MAX_TALLY
The highest tally possible
|
private PassageTally.Order |
order
The maximum tally possible
|
private static long |
serialVersionUID
Serialization ID
|
private int |
size |
private int |
total |
BITWISE, DISTINCT, listeners, METHOD_COUNT, originalName, RANGED, REF_ALLOWED_DELIMS, REF_OSIS_DELIM, REF_PREF_DELIM, skipNormalization, suppressEvents
Modifier | Constructor and Description |
---|---|
|
PassageTally(Versification v11n)
Create an empty PassageTally
|
protected |
PassageTally(Versification v11n,
String refs) |
protected |
PassageTally(Versification v11n,
String refs,
Key basis)
Create a Verse from a human readable string.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Key that)
Add/Increment this verses in the rankings
|
void |
add(Key that,
int count)
DONT USE THIS.
|
void |
addAll(Key that)
Adds the specified element to this set if it is not already present.
|
private void |
alterVerseBase(Key that,
int tally)
Increment/Decrement this verses in the rankings
|
void |
blur(int verses,
RestrictionType restrict)
Widen the range of the verses/keys in this list.
|
void |
clear()
Removes all of the elements from this set (optional operation).
|
PassageTally |
clone()
This needs to be declared here so that it is visible as a method on a
derived Key.
|
boolean |
contains(Key that)
Does this tally contain all the specified verses?
|
int |
countVerses()
Returns the number of verses in this collection.
|
void |
flatten()
Take the verses in the tally and give them all and equal rank of 1.
|
int |
getIndexOf(Verse verse)
What is the index of the give verse in the current ordering scheme
|
String |
getName()
A Human readable version of the Key.
|
String |
getName(int cnt)
A Human readable version of the verse list.
|
String |
getNameAndTally()
A Human readable version of the PassageTally.
|
String |
getNameAndTally(int cnt)
A Human readable version of the PassageTally.
|
PassageTally.Order |
getOrdering()
Get how we sort the verses we output.
|
int |
getTallyOf(Verse verse)
The ranking given to a specific verse
|
int |
getTotal() |
private void |
increment(int ord,
int tally)
Increment a verse by an amount
|
private void |
incrementMax(int tally)
Increment a verse by an amount
|
boolean |
isEmpty()
Does this Key have 0 members
|
Iterator<Key> |
iterator()
Iterate through the verse elements in the current sort order
|
private void |
kill(int ord)
Wipe the rank of the given verse to zero
|
Iterator<VerseRange> |
rangeIterator(RestrictionType restrict)
Like iterator() that iterates over VerseRanges instead of Verses.
|
private void |
readObject(ObjectInputStream in)
Call the support mechanism in AbstractPassage
|
void |
remove(Key that)
Remove these verses from the rankings, ie, set their rank to zero.
|
void |
removeAll(Key key)
Removes the specified elements from this set if it is present.
|
private void |
resetMax()
Sometimes we end up not knowing what the max is - this makes sure we know
accurately.
|
void |
setOrdering(PassageTally.Order order)
Set how we sort the verses we output.
|
void |
setTotal(int total) |
String |
toString() |
Passage |
trimVerses(int count)
Ensures that there are a maximum of
count Verses in this
Passage. |
void |
unAdd(Key that)
Remove/Decrement this verses in the rankings
|
void |
unAddAll(Passage that)
Remove/Decrement these verses in the rankings
|
private void |
writeObject(ObjectOutputStream out)
Call the support mechanism in AbstractPassage
|
addPassageListener, addVerses, booksInPassage, canHaveChildren, compareTo, containsAll, countRanges, equals, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, get, getCardinality, getChildCount, getName, getOsisID, getOsisRef, getOverview, getParent, getRangeAt, getRootName, getVerseAt, getVersification, getWhole, hashCode, hasRanges, indexOf, isWhole, lowerEventSuppressionAndTest, lowerNormalizeProtection, normalize, optimizeReads, optimizeWrites, raiseEventSuppresion, raiseNormalizeProtection, readDescription, readObjectSupport, removePassageListener, retainAll, reversify, setParent, toVerseRange, trimRanges, writeDescription, writeObjectSupport
public static final int MAX_TALLY
private int size
private int total
protected int[] board
private int max
private PassageTally.Order order
private static final org.slf4j.Logger log
private static final long serialVersionUID
public PassageTally(Versification v11n)
v11n
- The Versification to which this Passage belongs.protected PassageTally(Versification v11n, String refs, Key basis) throws NoSuchVerseException
v11n
- The Versification to which this Passage belongs.refs
- The text to interpretbasis
- The basis by which to interpret refsNoSuchVerseException
- If refs is invalidprotected PassageTally(Versification v11n, String refs) throws NoSuchVerseException
NoSuchVerseException
public boolean isEmpty()
Key
isEmpty
in interface Key
isEmpty
in class AbstractPassage
public int countVerses()
Passage
countVerses
in interface Passage
countVerses
in class AbstractPassage
Verse
public void setOrdering(PassageTally.Order order)
order
- the sort orderpublic PassageTally.Order getOrdering()
public int getTotal()
public void setTotal(int total)
total
- the total to setpublic PassageTally clone()
Key
clone
in interface Key
clone
in class AbstractPassage
public String toString()
toString
in class AbstractPassage
public String getName()
Key
getName
in interface Key
getName
in class AbstractPassage
public String getName(int cnt)
cnt
- The number of matches to return, 0 gives all matchespublic String getNameAndTally()
public String getNameAndTally(int cnt)
cnt
- The number of matches to return, 0 gives all matchespublic Iterator<Key> iterator()
public Iterator<VerseRange> rangeIterator(RestrictionType restrict)
Passage
rangeIterator
in interface Passage
rangeIterator
in class AbstractPassage
restrict
- Do we break ranges over chapterspublic boolean contains(Key that)
public int getTallyOf(Verse verse)
verse
- The verse to get the ranking ofpublic int getIndexOf(Verse verse)
verse
- The verse to get the index ofpublic void add(Key that)
that
- The verses to add/incrementpublic void add(Key that, int count)
that
- The verses to add/incrementcount
- The amount to increment bypublic void unAdd(Key that)
that
- The verses to remove/decrementpublic void remove(Key that)
that
- The verses to remove/decrementpublic void addAll(Key that)
Key
addAll
in interface Key
addAll
in class AbstractPassage
that
- element to be added to this set.public void unAddAll(Passage that)
that
- The verses to remove/decrementpublic void removeAll(Key key)
Key
removeAll
in interface Key
removeAll
in class AbstractPassage
key
- object to be removed from this set, if present.public void clear()
Key
clear
in interface Key
clear
in class AbstractPassage
public Passage trimVerses(int count)
count
Verses in this
Passage. If there were more than count
Verses then a new
Passage is created containing the Verses from count
+ 1
onwards. If there was not greater than count
in the Passage,
then the passage remains unchanged, and null is returned.trimVerses
in interface Passage
trimVerses
in class AbstractPassage
count
- The maximum number of Verses to allow in this collectionVerse
public void flatten()
public void blur(int verses, RestrictionType restrict)
Key
blur
in interface Key
blur
in class AbstractPassage
verses
- The number of verses/keys to widen byrestrict
- How should we restrict the blurring?Passage
private void resetMax()
private void alterVerseBase(Key that, int tally)
that
- The verses to add/incrementtally
- The amount to increment/decrement byprivate void increment(int ord, int tally)
ord
- The verse to incrementtally
- The amount to increase byprivate void incrementMax(int tally)
tally
- The amount to increase byprivate void kill(int ord)
ord
- The verse to incrementprivate void writeObject(ObjectOutputStream out) throws IOException
out
- The stream to write our state toIOException
- if the read failsAbstractPassage.writeObjectSupport(ObjectOutputStream)
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
in
- The stream to read our state fromIOException
- if the read failsClassNotFoundException
- If the read data is incorrectAbstractPassage.readObjectSupport(ObjectInputStream)