Skip to content

Commit

Permalink
Support morph in verse vocab
Browse files Browse the repository at this point in the history
  • Loading branch information
patricksptang committed Jun 19, 2024
1 parent 00463c4 commit d1d9978
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class StrongCountsAndSubjects {
private boolean ot;
private String verse;
private boolean multipleVerses;
private String allMorphsInVerse;
private String translationTipsFN;

/**
* Sets the counts.
Expand All @@ -33,6 +35,22 @@ public void setStrongData(final Map<String, List<LexiconSuggestion>> strongData)
this.strongData = strongData;
}

public void setTranslationTipsFN(final String translationTipsFN) {
this.translationTipsFN = translationTipsFN;
}

public String getTranslationTipsFN() {
return this.translationTipsFN;
}

public void setAllMorphsInVerse(final String allMorphsInVerse) {
this.allMorphsInVerse = allMorphsInVerse;
}

public String getAllMorphsInVerse() {
return this.allMorphsInVerse;
}

/**
* @return the strongData
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public interface JSwordPassageService {
String REFERENCE_BOOK = "ESV_th";
String SECONDARY_REFERENCE_BOOK = "NIV";
String OT_BOOK = "OSMHB";
String OT_BOOK = "THOT"; // "OSMHB";
String BEST_VERSIFICATION = "KJV";
int MAX_VERSES_RETRIEVED = 200;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class JSwordStrongNumberHelper {
private Map<String, List<LexiconSuggestion>> verseStrongs;
private Map<String, BookAndBibleCount> allStrongs;
private boolean isOT;
private String allMorph;
private String translationTipsFN;

/**
Expand Down Expand Up @@ -135,6 +136,8 @@ else if (customFN.containsKey(curOrdinal))
final List<Element> elements = JSwordUtils.getOsisElements(new BookData(preferredCountBook, key));
Set<String> strongAlreadyIncluded = new HashSet<String>();
for (final Element e : elements) {
if (elements.size() == 1) // If it is from verseVocabuary, it will only has one morphology
allMorph = OSISUtil.getMorphologiesWithStrong(e);
final String verseRef = e.getAttributeValue(OSISUtil.OSIS_ATTR_OSISID);
final String strongsNumbers = OSISUtil.getStrongsNumbers(e);
if (StringUtils.isBlank(strongsNumbers)) {
Expand Down
25 changes: 20 additions & 5 deletions step-web/src/main/webapp/js/backbone/views/view_quick_lexicon.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var QuickLexicon = Backbone.View.extend({
this.position = opts.position;
this.height = opts.height;
this.type = opts.type;
this.morphCount = opts.morphCount;
this.touchEvent = opts.touchEvent || false;
this.passageContainer = step.util.getPassageContainer(opts.target);
if (typeof opts.variant !== "string")
Expand All @@ -72,6 +73,7 @@ var QuickLexicon = Backbone.View.extend({
var self = parameters[0];
var strongsNotToDisplay = parameters[1];
var multipleStrongTextFromSearchModal = parameters[2];
var morphCount = parameters[3];
$("#quickLexicon").remove();
var morphOnly = false;
var data = JSON.parse(JSON.stringify(origData));
Expand Down Expand Up @@ -134,6 +136,8 @@ var QuickLexicon = Backbone.View.extend({
data.vocabInfos[i].mediumDef = data.vocabInfos[i].mediumDef.replace(/<br>/g, " ").replace(/<br \/>/g, " ").trim();
}
}
if (morphCount > 1)
morph_information[0] += " - 1st of " + morphCount + " different grammar for this word in this verse.";
lexicon = $(_.template(self.templateDef)({ data: data.vocabInfos,
brief_morph_info: morph_information,
fontClass: step.util.ui.getFontForStrong(self.strong),
Expand Down Expand Up @@ -215,8 +219,8 @@ var QuickLexicon = Backbone.View.extend({
strongsNotToDisplay = step.util.fixStrongNumForVocabInfo(strongsNotToDisplay, false);
}
var multipleStrongText = (typeof self.options.txtForMultiStrong === "string") ? self.options.txtForMultiStrong : "";
var callBackCreateDefParams = [ self, strongsNotToDisplay, multipleStrongText ];
var callBackLoadDefFromAPIParams = [ this.version, this.reference, strongsToUse, this.morph, step.userLanguageCode, self, strongsNotToDisplay, multipleStrongText, self.processQuickInfo ];
var callBackCreateDefParams = [ self, strongsNotToDisplay, multipleStrongText, this.morphCount ];
var callBackLoadDefFromAPIParams = [ this.version, this.reference, strongsToUse, this.morph, step.userLanguageCode, self, strongsNotToDisplay, multipleStrongText, self.processQuickInfo, this.morphCount ];
step.util.getVocabMorphInfoFromJson(strongsToUse, this.morph, this.version, self.processQuickInfo, callBackCreateDefParams,
self.loadDefinitionFromRestAPI, callBackLoadDefFromAPIParams);
},
Expand All @@ -230,12 +234,13 @@ var QuickLexicon = Backbone.View.extend({
var strongsNotToDisplay = paramArray[6];
var multipleStrongText = paramArray[7];
var callBackProcessQuickInfo = paramArray[8];
var morphCount = paramArray[9];
$.getSafe(MODULE_GET_QUICK_INFO, [version, reference, strongsToUse, morph, userLanguageCode], function (data) {
callBackProcessQuickInfo(data, [ callerSelf, strongsNotToDisplay, multipleStrongText ]);
callBackProcessQuickInfo(data, [ callerSelf, strongsNotToDisplay, multipleStrongText, morphCount ]);
}).error(function() {
if (changeBaseURL())
$.getSafe(MODULE_GET_QUICK_INFO, [version, reference, strongsToUse, morph, userLanguageCode], function (data) {
callBackProcessQuickInfo(data, [ callerSelf, strongsNotToDisplay, multipleStrongText ]);
callBackProcessQuickInfo(data, [ callerSelf, strongsNotToDisplay, multipleStrongText, morphCount ]);
})
});
return false;
Expand Down Expand Up @@ -267,7 +272,17 @@ var QuickLexicon = Backbone.View.extend({
var self = this;
if ((typeof augStrongNum === "string") && (augStrongNum !== "")) self.augStrong = augStrongNum;
var quickDefPositionAtTop = true; // Try to show it on top first. Swap to bottom if it overlaps with current mouse/touch position.
if (step.touchDevice)
var versePopupLocations = $(".versePopup");
var hasVersePopup = false;
for (var i = versePopupLocations.length -1; i >= 0; i --) {
var versePopupLoc = $(versePopupLocations[i]);
if ((typeof versePopupLoc.position === "function") && (typeof versePopupLoc.position().top === "number")) {
self.position = versePopupLoc.position().top;
hasVersePopup = true;
break;
}
}
if ((step.touchDevice) || (hasVersePopup)) // If versePopup is close to the top, the quick lexicon should go to the bottom.
quickDefPositionAtTop = ((self.position / self.height) > 0.35 ); // 0.35 (touch screen) to put most of the quick lexicon on top
if (quickDefPositionAtTop)
lexicon.css({"top": "0", "bottom": "auto"});
Expand Down
36 changes: 26 additions & 10 deletions step-web/src/main/webapp/js/backbone/views/view_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var SidebarView = Backbone.View.extend({
var curMorphs = step.util.convertMorphOSHM2TOS( this.model.get("morph") );
if (curMorphs != undefined)
lastMorphCode = curMorphs;
var morphCount = this.model.get("morphCount");
var ref = this.model.get("ref");
var version = this.model.get("version");
var allVersions = this.model.get("allVersions");
Expand All @@ -85,8 +86,8 @@ var SidebarView = Backbone.View.extend({
return;
}
strong = step.util.fixStrongNumForVocabInfo(strong, false);
var callBackCreateDefParams = [ ref, allVersions, variant ];
var callBackLoadDefFromAPIParams = [ version, ref, strong, curMorphs, allVersions, variant, self.createDefinition];
var callBackCreateDefParams = [ ref, allVersions, variant, morphCount ];
var callBackLoadDefFromAPIParams = [ version, ref, strong, curMorphs, allVersions, variant, self.createDefinition, morphCount ];
step.util.getVocabMorphInfoFromJson(strong, curMorphs, version, self.createDefinition, callBackCreateDefParams, self.loadDefinitionFromRestAPI, callBackLoadDefFromAPIParams);
}
else if (this.model.get("mode") == 'analysis') {
Expand All @@ -104,7 +105,7 @@ var SidebarView = Backbone.View.extend({
var C_numOfAnimationsAlreadyPerformedOnSamePage = 16; // TBRBMR
if ((cv[C_numOfAnimationsAlreadyPerformedOnSamePage] !== undefined) && (cv[C_numOfAnimationsAlreadyPerformedOnSamePage] !== null))
cv[C_numOfAnimationsAlreadyPerformedOnSamePage] = 0;
return false; // Return false so this will not be called 2 times.
return false; // Return false so this will not be called 2 times.s
},
loadDefinitionFromRestAPI: function (parameters) {
var version = parameters[0];
Expand All @@ -114,13 +115,14 @@ var SidebarView = Backbone.View.extend({
var allVersions = parameters[4];
var variant = parameters[5];
var callBackCreateDef = parameters[6];
var morphCount = parameters[7];
$.getSafe(MODULE_GET_INFO, [version, ref, strong, morph, step.userLanguageCode], function (data) {
callBackCreateDef(data, [ ref, allVersions, variant ]);
callBackCreateDef(data, [ ref, allVersions, variant, morphCount ]);
//return false;
}).error(function() {
if (changeBaseURL())
$.getSafe(MODULE_GET_INFO, [version, ref, strong, morph, step.userLanguageCode], function (data) {
callBackCreateDef(data, [ ref, allVersions, variant ]);
callBackCreateDef(data, [ ref, allVersions, variant, morphCount ]);
})
});
//return false;
Expand Down Expand Up @@ -175,6 +177,7 @@ var SidebarView = Backbone.View.extend({
var ref = parameters[0];
var allVersions = parameters[1];
var variant = parameters[2];
var morphCount = parameters[3];
var allMorphsForBackButton;
var allStrongsForBackButton;
if (!Array.isArray(variant)) variant = [""]; // Initialize in case it is not.
Expand Down Expand Up @@ -283,7 +286,7 @@ var SidebarView = Backbone.View.extend({
panelBody.append("<div>Only in " + variant[0] + " manuscript</div>");
// need to handle multiple morphInfo (array)
if (data.morphInfos.length > 0) {
this._createBriefMorphInfo(panelBody, data.morphInfos[0]);
this._createBriefMorphInfo(panelBody, data.morphInfos[0], morphCount, ref, data.vocabInfos[0].strongNumber);
}
this._createWordPanel(panelBody, data.vocabInfos[0], currentUserLang, allVersions, isOTorNT, headerType, data.morphInfos[0]);
if (data.morphInfos.length > 0) {
Expand All @@ -300,7 +303,7 @@ var SidebarView = Backbone.View.extend({
}
else console.log("this.lexicon length is " + this.lexicon.length);

if ((typeof allStrongsForBackButton === "string") && (allStrongsForBackButton !== allStrongsForNextBackButton)) {
if ((typeof allStrongsForBackButton === "string") && (allStrongsForBackButton !== allStrongsForNextBackButton)) {
var lexiconElement = $(this.lexicon[0]);
lexiconElement.prepend("<button id='lexicon-back-button' class='glyphicon glyphicon-arrow-left' title='Back to the definition of the previous word, " + allStrongsForBackButton + "'></button>");
}
Expand Down Expand Up @@ -932,7 +935,7 @@ var SidebarView = Backbone.View.extend({
require(['quick_lexicon'], function () {
step.util.delay(function () {
// do the quick lexicon
step.util.ui.displayNewQuickLexiconForVerseVocab(searchString, '', bibleVersion, step.util.activePassageId(), ev, ev.pageY, null, "");
step.util.ui.displayNewQuickLexiconForVerseVocab(searchString, '', '', bibleVersion, step.util.activePassageId(), ev, ev.pageY, null, "");
}, MOUSE_PAUSE, 'show-quick-lexicon');
});
},
Expand All @@ -948,7 +951,7 @@ var SidebarView = Backbone.View.extend({
this._doSideNotes(panel, bibleVersion);
},
// for one-line morphology
_createBriefMorphInfo: function (panel, info) {
_createBriefMorphInfo: function (panel, info, morphCount, ref, strongNum) {
if (typeof info === "undefined") {
panel.append("<br />");
return;
Expand All @@ -968,7 +971,20 @@ var SidebarView = Backbone.View.extend({
this.renderBriefMorphItem(panel, info, "gender");
this.renderBriefMorphItem(panel, info, "state");
this.renderBriefMorphItem(panel, info, "suffix");
panel.append(")<br />");
panel.append(")");
if (morphCount > 1) {
if ((typeof ref === "string") && (ref !== "") && (typeof strongNum === "string") &&
((strongNum.substring(0,1) === "G") || (strongNum.substring(0,1) === "H"))) {
panel.append(" - 1st of ");
var version = (strongNum.substring(0,1) === "G") ? "THGNT" : "OSHB";
strongNum = step.util.fixStrongNumForVocabInfo(strongNum, true);
panel.append("<a href='https://www.stepbible.org/?q=version=" + version + "|reference=" + ref + "|strong=" + strongNum + "&clickStrong' target='_blank'>" + morphCount + " different grammars</a>");
}
else
panel.append(" - 1st of " + morphCount + " different grammars");
panel.append(" for this word in this verse.");
}
panel.append("<br />");
},
renderBriefMorphItem: function (panel, morphInfo, param) {
if(morphInfo && param && morphInfo[param]) {
Expand Down
4 changes: 3 additions & 1 deletion step-web/src/main/webapp/js/search_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ step.searchSelect = {
else
$("#searchButton").hide();
},

goBackToPreviousPage: function() {
$('#quickLexicon').remove();
$('#searchSelectError').text("");
Expand Down Expand Up @@ -619,6 +620,7 @@ step.searchSelect = {
'<button id="searchButton" style="vertical-align:top;display:none;padding-left:10px;padding-right:10px" class="stepButton primaryLightBg" onclick=step.searchSelect._handleEnteredSearchWord() title="Get suggested search">' +
'<i style="font-size:12px" class="find glyphicon glyphicon-search"></i>' +
'</button>' +

//'<span id="previousSearchDropDown" class="dropdown advanced_search_elements">' +
// '<a class="dropdown-toggle showSettings" data-toggle="dropdown" title="Previous searches">' +
// using https://www.iconfinder.com/icons/326655/history_icon
Expand Down Expand Up @@ -2098,7 +2100,7 @@ step.searchSelect = {
require(['quick_lexicon'], function () {
step.util.delay(function () {
// do the quick lexicon
step.util.ui.displayNewQuickLexiconForVerseVocab(searchString, '', version, step.util.activePassageId(), ev, ev.pageY, null, multipleStrongText);
step.util.ui.displayNewQuickLexiconForVerseVocab(searchString, '', '', version, step.util.activePassageId(), ev, ev.pageY, null, multipleStrongText);
}, MOUSE_PAUSE, 'show-quick-lexicon');
});
},
Expand Down
Loading

0 comments on commit d1d9978

Please sign in to comment.