|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.crosswire.jsword.passage.AbstractPassage
org.crosswire.jsword.passage.PassageTally
public class PassageTally
Similar to a Passage, but that stores a ranking for each of the Verses that it contains.
Currently there is no well defined spec for what the rank of a verse means - it is just an int. Since this number is expoed 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 implentations 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 sytle PassageTally) And the intuative 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.
for license details.
The copyright to this program is held by it's authors.
,
Serialized FormNested Class Summary | |
---|---|
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 |
Nested classes/interfaces inherited from class org.crosswire.jsword.passage.AbstractPassage |
---|
AbstractPassage.VerseRangeIterator |
Field Summary | |
---|---|
protected int[] |
board
The tallyboard itself |
private static Logger |
log
The log stream |
private int |
max
The maximum tally possible |
static int |
MAX_TALLY
The highest tally possible |
private int |
order
The maximum tally possible |
static int |
ORDER_BIBLICAL
Sort in Biblical order |
static int |
ORDER_TALLY
Sort in tally rank order |
private static long |
serialVersionUID
Serialization ID |
private int |
size
|
Fields inherited from class org.crosswire.jsword.passage.AbstractPassage |
---|
BITWISE, DISTINCT, listeners, METHOD_COUNT, originalName, RANGED, REF_ALLOWED_DELIMS, REF_OSIS_DELIM, REF_PREF_DELIM, skipNormalization, suppressEvents |
Constructor Summary | |
---|---|
PassageTally()
Create an empty PassageTally |
|
PassageTally(String refs)
Create a Verse from a human readable string. |
Method Summary | |
---|---|
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 in this list. |
void |
clear()
Removes all of the Verses from this Passage. |
Object |
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. |
int |
getOrdering()
Get how we sort the verses we output. |
int |
getTallyOf(Verse verse)
The ranking given to a specific verse |
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 |
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 |
rangeIterator(RestrictionType restrict)
Iterate through the range elements in the current sort order |
void |
remove(Key that)
Remove these verses from the rankings, ie, set their rank to zero. |
void |
removeAll(Key key)
Remove/Decrement these verses in the rankings |
private void |
resetMax()
Sometimes we end up not knowing what the max is - this makes sure we know accurately. |
void |
setOrdering(int order)
Set how we sort the verses we output. |
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 |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int ORDER_BIBLICAL
public static final int ORDER_TALLY
public static final int MAX_TALLY
private int size
protected int[] board
private int max
private int order
private static final Logger log
private static final long serialVersionUID
Constructor Detail |
---|
public PassageTally()
public PassageTally(String refs) throws NoSuchVerseException
refs
- The text to interpret
NoSuchVerseException
- If refs is invalidMethod Detail |
---|
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(int order)
order
- the sort orderpublic int getOrdering()
public Object 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 matches
public String getNameAndTally()
public String getNameAndTally(int cnt)
cnt
- The number of matches to return, 0 gives all matches
public Iterator iterator()
public Iterator rangeIterator(RestrictionType restrict)
rangeIterator
in interface Passage
rangeIterator
in class AbstractPassage
restrict
- Do we break ranges over chapters
public boolean contains(Key that)
contains
in interface Key
contains
in interface Passage
contains
in class AbstractPassage
that
- The verses to test for
public int getTallyOf(Verse verse)
verse
- The verse to get the ranking of
public int getIndexOf(Verse verse)
verse
- The verse to get the index of
public 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)
removeAll
in interface Key
removeAll
in class AbstractPassage
key
- The verses to remove/decrementpublic void clear()
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 collection
Verse
public void flatten()
public void blur(int verses, RestrictionType restrict)
blur
in interface Key
blur
in class AbstractPassage
verses
- The number of verses 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 inrease byprivate void incrementMax(int tally)
tally
- The amount to inrease byprivate void kill(int ord)
ord
- The verse to increment
|
Copyright ยจ 2003-2006 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |