| BibleScope.java |
1 /**
2 * Distribution License:
3 * JSword is free software; you can redistribute it and/or modify it under
4 * the terms of the GNU Lesser General Public License, version 2.1 as published by
5 * the Free Software Foundation. This program is distributed in the hope
6 * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8 * See the GNU Lesser General Public License for more details.
9 *
10 * The License is available on the internet at:
11 * http://www.gnu.org/copyleft/lgpl.html
12 * or by writing to:
13 * Free Software Foundation, Inc.
14 * 59 Temple Place - Suite 330
15 * Boston, MA 02111-1307, USA
16 *
17 * Copyright: 2008
18 * The copyright to this program is held by it's authors.
19 *
20 * ID: $Id: BookIndexer.java 1466 2007-07-02 02:48:09Z dmsmith $
21 */
22 package org.crosswire.jsword.bridge;
23
24 import org.crosswire.jsword.book.Book;
25 import org.crosswire.jsword.book.BookCategory;
26 import org.crosswire.jsword.book.Books;
27 import org.crosswire.jsword.passage.Key;
28 import org.crosswire.jsword.versification.BookName;
29
30 /**
31 * Determines the scope of the Bible. That is, the verses that are in the Bible
32 * and the verses that are not. This is based upon the KJV versification.
33 *
34 * @see gnu.lgpl.License for license details.<br>
35 * The copyright to this program is held by it's authors.
36 * @author DM Smith [dmsmith555 at yahoo dot com]
37 */
38 public class BibleScope {
39
40 public BibleScope(Book book) {
41 this.book = book;
42 }
43
44 /**
45 * Get a key containing all the verses that are in this Bible.
46 *
47 * @return verses that are in scope
48 */
49 public Key getInScope() {
50 computeScope();
51 return inScope;
52 }
53
54 /**
55 * Get a key containing all the verses that are not in this Bible.
56 *
57 * @return verses that are out of scope
58 */
59 public Key getOutOfScope() {
60 computeScope();
61 return outScope;
62 }
63
64 private void computeScope() {
65 if (inScope == null) {
66 Key all = book.getGlobalKeyList();
67 inScope = book.createEmptyKeyList();
68 outScope = book.createEmptyKeyList();
69 for (Key key : all) {
70 if (book.contains(key)) {
71 inScope.addAll(key);
72 } else {
73 outScope.addAll(key);
74 }
75 }
76 }
77 }
78
79 public static void report(Book b) {
80 if (!b.getBookCategory().equals(BookCategory.BIBLE) && !b.getBookCategory().equals(BookCategory.COMMENTARY)) {
81 System.err.println(b.getInitials() + " is not a Bible or Commentary");
82 // System.exit(1);
83 }
84
85 BibleScope scope = new BibleScope(b);
86 BookName.setFullBookName(false); // use short names
87 System.out.println('[' + b.getInitials() + ']');
88 System.out.println("InScope=" + scope.getInScope().getOsisRef());
89 System.out.println("OutScope=" + scope.getOutOfScope().getOsisRef());
90 }
91
92 private Book book;
93
94 /**
95 * Call with <operation> book. Where operation can be one of:
96 * <ul>
97 * <li>check - returns "TRUE" or "FALSE" indicating whether the index exists
98 * or not</li>
99 * <li>create - (re)create the index</li>
100 * <li>delete - delete the index if it exists</li>
101 * </ul>
102 * And book is the initials of a book, e.g. KJV.
103 *
104 * @param args
105 */
106 public static void main(String[] args) {
107 if (args.length != 1) {
108 usage();
109 return;
110 }
111
112 System.err.println("BibleScope " + args[0]);
113
114 Book b = Books.installed().getBook(args[0]);
115 if (b == null) {
116 System.err.println("Book not found");
117 return;
118 }
119
120 report(b);
121
122 // List books =
123 // Books.installed().getBooks(BookFilters.getCommentaries());
124 // Iterator iter = books.iterator();
125 // while (iter.hasNext())
126 // {
127 // try {
128 // report((Book) iter.next());
129 // } catch (Exception e) {
130 // System.out.println("exception " + e.toString());
131 // }
132 // System.out.println();
133 // }
134 }
135
136 public static void usage() {
137 System.err.println("Usage: BibleScope book");
138 }
139
140 private Key inScope;
141 private Key outScope;
142 }
143