%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.Segment" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.SegmentReading" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Apparatus.SegmentReading.ReadingWord" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.WitnessReading" %>
<%@ page import="org.crosswire.community.projects.ntmss.data.Transcription.Convert" %>
<%@ page import="org.crosswire.utils.Utils" %>
<%@ page import="org.crosswire.data.DataObject" %>
<%@ page import="org.crosswire.utils.HTTPUtils" %>
<%@ page import="org.crosswire.sword.keys.VerseKey" %>
<%@ page import="org.crosswire.sword.keys.ListKey" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.TreeMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Vector" %>
<%@ page import="java.util.UUID" %>
<%@ page import="java.util.Collections" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="org.crosswire.xml.XMLBlock" %>
<%@ page import="org.crosswire.webtools.annotation.*" %>
<%@ page import="org.crosswire.webtools.*" %>
<%@ page import="javax.validation.constraints.NotNull" %>
<%!
static final int BUFFEREDWORDSMAX = 1000;
@Description(value = "Retrieve variant apparatus data", name = "variant/apparatus/get")
public static class MyParameters extends Parameters {
@NotNull
@Description(value = "which range of apparatus to obtain", example = "Acts.4.5")
public String indexContent = null;
@Description(value = "limit results to a specific segmentGroupID; -1 = all", defaultValue = "-1", example = "3")
public Integer segmentGroupID = null;
@Description(value = "augment results with segments from another group", example = "7")
public Integer augmentGroupID = null;
@Description(value = "include a baseline edition with apparatus", example = "ECM")
public String includeBaseline = null;
@Description(value = "when computing the word context, include this many baseline words before and after reading or word", defaultValue = "3", example = "5")
public Integer wordContextSize = 3;
@Description(value = "convert 'a' readings to positive apparatus", defaultValue = "false", example = "true")
public Boolean positiveConversion = false;
@Description(value = "save search data as test index", defaultValue = "false", example = "true")
public Boolean testIndex = false;
@Description(value = "add extra detail if desired", defaultValue = "complete", example = "extra")
public String detail = "complete";
@Override
protected void customValidation() {
}
}
public static WitnessReading loadModuleReading(String moduleName, String key, boolean supplied, boolean unclear, boolean punct, boolean accents, Parameters params) {
String moduleServiceURL = "http://crosswire.org/study/fetchdata.jsp";
String postParams
= "mod="+java.net.URLEncoder.encode(moduleName)
+ "&key="+java.net.URLEncoder.encode(key)
+ "&format=raw";
StringBuffer result = HTTPUtils.postURL(moduleServiceURL, postParams);
String t = result.toString();
WitnessReading retVal = null;
try {
retVal = new WitnessReading("", t);
/*
Vector wits = Convert.getTEITranscriptionText(t, supplied, unclear, punct, accents);
retVal = (wits.size() > 0) ? wits.get(0) : new WitnessReading("", t);
*/
}
catch (Exception e) {
params.getLogger().error("Error looking up module: " + moduleName, e);
retVal = new WitnessReading("", t);
}
retVal.setDocumentName(moduleName);
return retVal;
}
static void pushData(StringBuffer bulkBuffer, Integer segmentGroupID, String indexSuffix, javax.servlet.jsp.JspWriter out) {
try {
// out.print(bulkBuffer.toString());
StringBuffer result = HTTPUtils.postURL("http://127.0.0.1:9200/apparatus"+segmentGroupID+indexSuffix+"/_bulk", bulkBuffer.toString(), null, null, null, HTTPUtils.POST, false, null, HTTPUtils.PARAMSTYPE_JSON);
out.print("\n\n\nResult: " + result);
}
catch (Exception e) { System.out.println("error pushing data" + e); e.printStackTrace(); }
}
static void deleteData(Integer segmentGroupID, String indexSuffix, javax.servlet.jsp.JspWriter out) {
try {
// out.print(bulkBuffer.toString());
StringBuffer result = HTTPUtils.postURL("http://127.0.0.1:9200/apparatus"+segmentGroupID+indexSuffix, null, null, null, null, HTTPUtils.DELETE, false, null, HTTPUtils.PARAMSTYPE_JSON);
out.print("\n\n\nResult: " + result);
}
catch (Exception e) { System.out.println("error pushing data" + e); e.printStackTrace(); }
}
static Map indeclinable = new HashMap() {{
put("ADV", "ADVerb or adverb and particle combined");
put("CONJ", "CONJuction or conjuctive particle");
put("COND", "CONDitional particle or conjunction");
put("PRT", "PaRTicle, disjunctive particle");
put("PREP", "PREPosition");
put("INJ", "INterJection");
put("ARAM", "ARAMaic transliterated word");
put("HEB", "HEBrew transliterated word");
put("N-PRI", "Indeclinable PRoper Noun");
put("A-NUI", "Indeclinable NUmeral (Adjective)");
put("N-LI", "Indeclinable Letter (Noun)");
put("N-OI", "Indeclinable Noun of Other type");
}};
static Map primaryTypes = new HashMap() {{
put("N", "Noun");
put("V", "Verb");
put("A", "Adjective");
put("R", "Relative pronoun");
put("C", "reCiprocal pronoun");
put("D", "Demonstrative pronoun");
put("T", "definite arTicle");
put("K", "correlative pronoun (K)");
put("I", "Interrogative pronoun");
put("X", "indefinite pronoun (X)");
put("Q", "correlative or interrogative pronoun (Q)");
put("F", "reFlexive pronoun (person 1,2,3 added)");
put("S", "poSsessive adjective (person 1,2,3 and number S,P added");
put("P", "Personal pronoun");
}};
static void addWordParts(Map record, ReadingWord rw) {
addWordParts(record, rw, "");
}
static void addWordParts(Map record, ReadingWord rw, String prefix) {
try {
record.put(prefix+"text", rw.getText());
record.put(prefix+"textLength", rw.getText().length());
String lemma = rw.getLemma();
if (lemma != null) {
lemma = lemma.trim();
record.put(prefix+"lemma", lemma);
}
String morph = rw.getMorph();
if (morph != null) {
String checkMorph = morph.replaceAll("[A-Z0-9?-]*", "");
if (checkMorph.length() > 0) {
record.put(prefix+"error", checkMorph);
}
record.put(prefix+"morph", morph);
String segs[] = morph.split("-");
// remove "F" = fault segment, if exists
// and set fault = true
List segsToBe = new ArrayList();
for (int i = 0; i < segs.length; ++i) {
if (i > 0 && "F".equals(segs[i])) {
record.put(prefix+"fault", true);
}
else segsToBe.add(segs[i]);
}
segs = segsToBe.toArray(new String[]{});
String primaryForm = "Unknown";
String suffix = null;
String primaryFormDesc = indeclinable.get(segs[0]);
if (primaryFormDesc != null) {
primaryForm = morph;
record.put(prefix+"indeclinable", true);
if (segs.length > 1) suffix = segs[1];
}
else if (segs.length > 1 && indeclinable.get(String.join("-", segs[0], segs[1])) != null) {
primaryFormDesc = indeclinable.get(String.join("-", segs[0], segs[1]));
primaryForm = morph;
record.put(prefix+"indeclinable", true);
if (segs.length > 2) suffix = segs[2];
}
else {
if (segs.length > 0) {
for (int i = 0; i < segs.length; ++i) {
record.put(prefix+"morphSeg"+(i+1), segs[i]);
}
primaryFormDesc = primaryTypes.get(segs[0]);
if (primaryFormDesc != null) {
String cng = null;
primaryForm = segs[0];
if ("V".equals(primaryForm)) {
String tvm = segs[1];
if (tvm.length() == 3 || tvm.length() == 4) {
record.put(prefix+"tvm", tvm);
String tense = null;
if (tvm.startsWith("2")) {
tense = tvm.substring(0,2);
}
else {
tense = tvm.substring(0,1);
}
tvm = tvm.substring(tense.length());
if (tense != null) record.put(prefix+"tense", tense);
String voice = tvm.substring(0,1);
if (voice != null) record.put(prefix+"voice", voice);
String mood = tvm.substring(1,2);
if (mood != null) record.put(prefix+"mood", mood);
}
if (segs.length > 2) {
String pnOrCng = segs[2];
if (pnOrCng.length() > 0 && Character.isDigit(pnOrCng.charAt(0))) {
record.put(prefix+"person", pnOrCng.substring(0,1));
if (pnOrCng.length() > 1) {
record.put(prefix+"number", pnOrCng.substring(1,2));
}
}
else cng = pnOrCng;
}
}
else if ("S".equals(primaryForm) && segs.length > 1) {
String pncng = segs[1];
if (pncng.length() > 0 && Character.isDigit(pncng.charAt(0))) {
record.put(prefix+"personPron", pncng.substring(0,1));
if (pncng.length() > 1) {
record.put(prefix+"numberPron", pncng.substring(1,2));
if (pncng.length() > 2) {
cng = pncng.substring(2);
}
}
}
}
else {
if (segs.length > 1) {
cng = segs[1];
/*
if (segs.length > 2) {
cng = segs[2];
}
*/
}
}
if (cng != null) {
if (cng.length() > 1 && Character.isDigit(cng.charAt(0))) {
record.put(prefix+"person", cng.substring(0,1));
cng = cng.substring(1);
}
if (cng.length() > 0) {
record.put(prefix+"cng", cng);
String morphCase = cng.substring(0,1);
record.put(prefix+"case", morphCase);
if (cng.length() > 1) {
String number = cng.substring(1,2);
record.put(prefix+"number", number);
if (cng.length() > 2) {
String gender = cng.substring(2,3);
record.put(prefix+"gender", gender);
}
}
}
}
}
else {
primaryForm = "Unknown";
}
}
}
record.put(prefix+"primaryForm", primaryForm);
if (primaryFormDesc != null) record.put(prefix+"primaryFormDesc", primaryFormDesc);
if (suffix != null) record.put(prefix+"suffix", suffix);
record.put(prefix+"wnVerse", rw.getWordNumberVerse());
record.put(prefix+"wnBook", rw.getWordNumberBook());
}
}
catch (Exception e) { System.out.println("ERROR ADDING WORD PARTS. " + e); e.printStackTrace(); }
}
void checkTranspositions(List