[jsword-svn] r1187 - in trunk/jsword/src: main/java/org/crosswire/jsword/passage main/java/org/crosswire/jsword/versification test/java/org/crosswire/jsword/book
dmsmith at www.crosswire.org
dmsmith at www.crosswire.org
Wed Nov 15 06:22:01 MST 2006
Author: dmsmith
Date: 2006-11-15 06:22:00 -0700 (Wed, 15 Nov 2006)
New Revision: 1187
Added:
trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java
Modified:
trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageKeyFactory.java
trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleNames.properties
Log:
Fix up passage parsing.
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageKeyFactory.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageKeyFactory.java 2006-11-13 21:57:36 UTC (rev 1186)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/PassageKeyFactory.java 2006-11-15 13:22:00 UTC (rev 1187)
@@ -86,7 +86,15 @@
}
catch (Exception e)
{
- return defaultType.createPassage(normalize(name));
+ try
+ {
+ return defaultType.createPassage(normalize(name));
+ }
+ catch (Exception e1)
+ {
+ // TODO(DM): Parser should allow valid osis refs!
+ return defaultType.createPassage(mungOsisRef(name));
+ }
}
}
@@ -462,6 +470,16 @@
}
/**
+ * Replace spaces with semi-colons, because the parser expects them.
+ * @param name
+ * @return the munged value
+ */
+ private String mungOsisRef(String name)
+ {
+ return name.replace(' ', ';');
+ }
+
+ /**
* The internals of a Passage require that references are separated with a reference delimiter.
* However, people and other systems may not be so stringent.
* So we want to allow for "Ge 1:26 3:22 11:7 20:13 31:7, 53 35:7" (which is from Clarke)
Modified: trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleNames.properties
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleNames.properties 2006-11-13 21:57:36 UTC (rev 1186)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/versification/BibleNames.properties 2006-11-15 13:22:00 UTC (rev 1187)
@@ -18,28 +18,28 @@
Josh.Alt=
Judg.Full=Judges
Judg.Short=Judg
-Judg.Alt=jdg
+Judg.Alt=jdg,jud
Ruth.Full=Ruth
Ruth.Short=Rut
Ruth.Alt=rth
1Sam.Full=1 Samuel
1Sam.Short=1Sa
-1Sam.Alt=
+1Sam.Alt=isam
2Sam.Full=2 Samuel
2Sam.Short=2Sa
-2Sam.Alt=
+2Sam.Alt=iisa
1Kgs.Full=1 Kings
1Kgs.Short=1Ki
-1Kgs.Alt=1kgs
+1Kgs.Alt=1kg,iki,ikg
2Kgs.Full=2 Kings
2Kgs.Short=2Ki
-2Kgs.Alt=2kgs
+2Kgs.Alt=2kgs,iiki,iikg
1Chr.Full=1 Chronicles
1Chr.Short=1Ch
-1Chr.Alt=
+1Chr.Alt=ich
2Chr.Full=2 Chronicles
2Chr.Short=2Ch
-2Chr.Alt=
+2Chr.Alt=iich
Ezra.Full=Ezra
Ezra.Short=Ezr
Ezra.Alt=
@@ -66,7 +66,7 @@
Song.Alt=ss,songofsongs,sos,canticleofcanticles,canticle,can,coc
Isa.Full=Isaiah
Isa.Short=Isa
-Isa.Alt=
+Isa.Alt=is
Jer.Full=Jeremiah
Jer.Short=Jer
Jer.Alt=
@@ -135,10 +135,10 @@
Rom.Alt=
1Cor.Full=1 Corinthians
1Cor.Short=1Cor
-1Cor.Alt=
+1Cor.Alt=ico
2Cor.Full=2 Corinthians
2Cor.Short=2Cor
-2Cor.Alt=
+2Cor.Alt=iico
Gal.Full=Galatians
Gal.Short=Gal
Gal.Alt=
@@ -150,19 +150,19 @@
Phil.Alt=php
Col.Full=Colossians
Col.Short=Col
-Col.Alt=
+Col.Alt=co
1Thess.Full=1 Thessalonians
1Thess.Short=1Th
-1Thess.Alt=
+1Thess.Alt=ith
2Thess.Full=2 Thessalonians
2Thess.Short=2Th
-2Thess.Alt=
+2Thess.Alt=iith
1Tim.Full=1 Timothy
1Tim.Short=1Ti
-1Tim.Alt=1tm
+1Tim.Alt=1tm,iti,itm
2Tim.Full=2 Timothy
2Tim.Short=2Ti
-2Tim.Alt=2tm
+2Tim.Alt=2tm,iiti,iitm
Titus.Full=Titus
Titus.Short=Tit
Titus.Alt=
@@ -177,22 +177,22 @@
Jas.Alt=jas
1Pet.Full=1 Peter
1Pet.Short=1Pe
-1Pet.Alt=1ptr
+1Pet.Alt=1ptr,ip
2Pet.Full=2 Peter
2Pet.Short=2Pe
-2Pet.Alt=2ptr
+2Pet.Alt=2pt,iip
1John.Full=1 John
1John.Short=1Jo
-1John.Alt=1jn,1jhn
+1John.Alt=1jn,1jh,ijo,ijn,ijh
2John.Full=2 John
2John.Short=2Jo
-2John.Alt=2jn,2jhn
+2John.Alt=2jn,2jh,iijo,iijn,iijh
3John.Full=3 John
3John.Short=3Jo
-3John.Alt=3jn,3jhn
+3John.Alt=3jn,3jh,iiijo,iiijn,iiijh
Jude.Full=Jude
Jude.Short=Jude
-Jude.Alt=jud
+Jude.Alt=
Rev.Full=Revelation of John
Rev.Short=Rev
Rev.Alt=rv,apocalypse
Added: trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java
===================================================================
--- trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java (rev 0)
+++ trunk/jsword/src/test/java/org/crosswire/jsword/book/GatherAllReferences.java 2006-11-15 13:22:00 UTC (rev 1187)
@@ -0,0 +1,203 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ * The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: ReadEverything.java 1185 2006-11-13 08:32:18 -0500 (Mon, 13 Nov 2006) dmsmith $
+ */
+package org.crosswire.jsword.book;
+
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.crosswire.common.config.ChoiceFactory;
+import org.crosswire.common.config.Config;
+import org.crosswire.common.util.CWClassLoader;
+import org.crosswire.common.util.Logger;
+import org.crosswire.common.util.ResourceUtil;
+import org.crosswire.common.xml.XMLUtil;
+import org.crosswire.jsword.passage.Key;
+import org.crosswire.jsword.passage.KeyFactory;
+import org.crosswire.jsword.passage.NoSuchKeyException;
+import org.crosswire.jsword.passage.PassageKeyFactory;
+import org.crosswire.jsword.util.Project;
+import org.jdom.Document;
+import org.jdom.JDOMException;
+
+/**
+ * Gather all references.
+ *
+ * @see gnu.lgpl.License for license details.
+ * The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class GatherAllReferences
+{
+ /**
+ * Prevent instansiation
+ */
+ private GatherAllReferences()
+ {
+ }
+
+ /**
+ * Read all the books that we can get our hands on.
+ */
+ public static void main(String[] args) throws IOException, JDOMException
+ {
+ out = new PrintWriter(new BufferedWriter(new FileWriter("passages.log"))); //$NON-NLS-1$
+ // Calling Project.instance() will set up the project's home directory
+ // ~/.jsword
+ // This will set it as a place to look for overrides for
+ // ResourceBundles, properties and other resources
+ Project.instance();
+
+ // And the array of allowed osis>html converters
+ ChoiceFactory.getDataMap().put("converters", new String[] {}); //$NON-NLS-1$
+
+ // The choice of configurable XSL stylesheets
+ ChoiceFactory.getDataMap().put("cswing-styles", new String[] {}); //$NON-NLS-1$
+
+ // Load the desktop configuration so we can find the sword drivers
+ Config config = new Config("Desktop Options"); //$NON-NLS-1$
+ Document xmlconfig = XMLUtil.getDocument("config"); //$NON-NLS-1$
+
+ Locale defaultLocale = Locale.getDefault();
+ ResourceBundle configResources = ResourceBundle.getBundle("config", defaultLocale, CWClassLoader.instance(GatherAllReferences.class)); //$NON-NLS-1$
+
+ config.add(xmlconfig, configResources);
+
+ config.setProperties(ResourceUtil.getProperties("desktop")); //$NON-NLS-1$
+ config.localToApplication();
+
+ // Loop through all the Bookks
+ log.warn("*** Reading all known Books"); //$NON-NLS-1$
+ List comments = Books.installed().getBooks();
+ for (Iterator cit = comments.iterator(); cit.hasNext();)
+ {
+ Book book = (Book) cit.next();
+
+ BookMetaData bmd = book.getBookMetaData();
+ // Skip PlainText as they do not have references marked up
+ if (bmd.getProperty("SourceType") != null) //$NON-NLS-1$
+ {
+ Key set = book.getGlobalKeyList();
+
+ readBook(book, set);
+ }
+ }
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * Perform a test read on an iterator over a set of keys
+ */
+ private static void readBook(Book book, Key set)
+ {
+ DataPolice.setBook(book.getBookMetaData());
+
+ int[] stats = new int[] { 0, 0 };
+
+ Iterator it = set.iterator();
+ while (it.hasNext())
+ {
+ readKey(book, (Key) it.next(), stats);
+ }
+ log.warn(book.getInitials() + ':' + stats[0] + ':' + stats[1]);
+
+ }
+
+ /**
+ * Perform a test read on a single key
+ */
+ private static void readKey(Book book, Key key, int[] stats)
+ {
+ try
+ {
+ String orig;
+ try
+ {
+ orig = book.getRawData(key);
+ }
+ catch (BookException ex)
+ {
+ log.warn("Failed to read: " + book.getInitials() + '(' + key.getName() + "):" + ex.getMessage(), ex); //$NON-NLS-1$ //$NON-NLS-2$
+ return;
+ }
+
+ Matcher matcher = null;
+ if (orig.indexOf("passage=\"") != -1) //$NON-NLS-1$
+ {
+ matcher = thmlPassagePattern.matcher(orig);
+ }
+ else if (orig.indexOf("osisRef=\"") != -1) //$NON-NLS-1$
+ {
+ matcher = osisPassagePattern.matcher(orig);
+ }
+ else if (orig.indexOf("<RX>") != -1) //$NON-NLS-1$
+ {
+ matcher = gbfPassagePattern.matcher(orig);
+ }
+
+ if (matcher != null)
+ {
+ while (matcher.find())
+ {
+ String rawRef = matcher.group(1);
+ stats[0]++;
+ String message = book.getInitials() + ':' + key.getOsisRef() + '/' + rawRef;
+ try
+ {
+ Key ref = keyf.getKey(rawRef);
+ message += '/' + ref.getOsisRef();
+ }
+ catch (NoSuchKeyException e)
+ {
+ message += '!' + e.getMessage();
+ stats[1]++;
+ }
+
+ out.println(message);
+ }
+ }
+
+ }
+ catch (Throwable ex)
+ {
+ log.error("Unexpected error reading: "+book.getInitials()+'(' + key.getName() + ')', ex); //$NON-NLS-1$
+ }
+ }
+
+ private static Pattern thmlPassagePattern = Pattern.compile("passage=\"([^\"]*)"); //$NON-NLS-1$
+ private static Pattern gbfPassagePattern = Pattern.compile("<RX>([^<]*)"); //$NON-NLS-1$
+ private static Pattern osisPassagePattern = Pattern.compile("osisRef=\"([^\"]*)"); //$NON-NLS-1$
+ private static KeyFactory keyf = PassageKeyFactory.instance();
+ private static PrintWriter out;
+ /**
+ * The log stream
+ */
+ private static final Logger log = Logger.getLogger(GatherAllReferences.class);
+}
More information about the jsword-svn
mailing list