| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
package org.crosswire.jsword.examples; |
| 21 | |
|
| 22 | |
import java.util.ArrayList; |
| 23 | |
import java.util.List; |
| 24 | |
import java.util.regex.Matcher; |
| 25 | |
import java.util.regex.Pattern; |
| 26 | |
|
| 27 | |
import org.crosswire.jsword.book.Book; |
| 28 | |
import org.crosswire.jsword.book.BookData; |
| 29 | |
import org.crosswire.jsword.book.BookException; |
| 30 | |
import org.crosswire.jsword.book.BookFilters; |
| 31 | |
import org.crosswire.jsword.book.Books; |
| 32 | |
import org.crosswire.jsword.book.FeatureType; |
| 33 | |
import org.crosswire.jsword.book.OSISUtil; |
| 34 | |
import org.crosswire.jsword.book.study.StrongsMapSet; |
| 35 | |
import org.crosswire.jsword.book.study.StrongsNumber; |
| 36 | |
import org.crosswire.jsword.passage.Key; |
| 37 | |
import org.jdom2.Content; |
| 38 | |
import org.jdom2.Element; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
public class StrongsAnalysis { |
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | 0 | public StrongsAnalysis() { |
| 51 | 0 | Book bible = Books.installed().getBook("KJV"); |
| 52 | 0 | if (!bible.hasFeature(FeatureType.STRONGS_NUMBERS)) { |
| 53 | 0 | bible = null; |
| 54 | 0 | List<Book> bibles = Books.installed().getBooks(new BookFilters.BookFeatureFilter(FeatureType.STRONGS_NUMBERS)); |
| 55 | |
|
| 56 | 0 | if (!bibles.isEmpty()) { |
| 57 | 0 | bible = bibles.get(0); |
| 58 | |
} |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | if (bible == null) { |
| 62 | 0 | return; |
| 63 | |
} |
| 64 | |
|
| 65 | 0 | List<Key> errors = new ArrayList<Key>(); |
| 66 | 0 | StrongsMapSet sms = new StrongsMapSet(); |
| 67 | 0 | analyze(sms, bible, errors, bible.getGlobalKeyList()); |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
public void analyze(StrongsMapSet sms, Book book, List<Key> errors, Key wholeBible) { |
| 77 | 0 | BookData data = null; |
| 78 | 0 | Element osis = null; |
| 79 | 0 | StringBuilder buffer = new StringBuilder(); |
| 80 | 0 | for (Key subkey : wholeBible) { |
| 81 | 0 | if (subkey.canHaveChildren()) { |
| 82 | 0 | analyze(sms, book, errors, subkey); |
| 83 | |
} else { |
| 84 | 0 | data = new BookData(book, subkey); |
| 85 | 0 | osis = null; |
| 86 | |
|
| 87 | |
try { |
| 88 | 0 | osis = data.getOsisFragment(); |
| 89 | 0 | } catch (BookException e) { |
| 90 | 0 | errors.add(subkey); |
| 91 | 0 | continue; |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
|
| 95 | 0 | for (Content content : OSISUtil.getDeepContent(osis, OSISUtil.OSIS_ELEMENT_W)) { |
| 96 | |
|
| 97 | 0 | int len = buffer.length(); |
| 98 | 0 | if (len > 0) { |
| 99 | 0 | buffer.delete(0, len); |
| 100 | |
} |
| 101 | |
|
| 102 | 0 | Element wElement = (Element) content; |
| 103 | 0 | String snAttr = wElement.getAttributeValue(OSISUtil.ATTRIBUTE_W_LEMMA); |
| 104 | |
|
| 105 | 0 | String text = OSISUtil.getPlainText(wElement); |
| 106 | |
|
| 107 | 0 | Matcher matcher = strongsNumberPattern.matcher(snAttr); |
| 108 | 0 | while (matcher.find()) { |
| 109 | 0 | StrongsNumber strongsNumber = new StrongsNumber(matcher.group(1)); |
| 110 | 0 | if (strongsNumber.isValid()) { |
| 111 | 0 | if (buffer.length() > 0) { |
| 112 | 0 | buffer.append(' '); |
| 113 | |
} |
| 114 | 0 | buffer.append(strongsNumber.getStrongsNumber()); |
| 115 | |
} |
| 116 | 0 | } |
| 117 | |
|
| 118 | |
|
| 119 | 0 | sms.add(buffer.toString(), text); |
| 120 | 0 | } |
| 121 | |
} |
| 122 | |
} |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
public static void main(String[] args) { |
| 129 | 0 | new StrongsAnalysis(); |
| 130 | 0 | } |
| 131 | |
|
| 132 | 0 | private static Pattern strongsNumberPattern = Pattern.compile("strong:([GH][0-9]+)"); |
| 133 | |
} |