Skip to content

Commit

Permalink
Merge pull request #1407 from otseng/main
Browse files Browse the repository at this point in the history
Ver 35.25; Add display word frequency menu plugin (#279)
  • Loading branch information
eliranwong authored Dec 29, 2023
2 parents 76fa729 + a7fe34f commit c1a339b
Show file tree
Hide file tree
Showing 27 changed files with 398 additions and 28 deletions.
2 changes: 1 addition & 1 deletion UniqueBibleAppVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
35.24
35.25
262 changes: 262 additions & 0 deletions db/StatisticsWordsSqlite.py

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions db/ToolsSqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,16 @@ def getAllTopics(self):
self.cursor.execute(query)
return self.cursor.fetchall()

def getHebrewTopics(self):
query = "SELECT Topic FROM Lexicon WHERE Topic like 'H%'"
self.cursor.execute(query)
return self.cursor.fetchall()

def getGreekTopics(self):
query = "SELECT Topic FROM Lexicon WHERE Topic like 'G%'"
self.cursor.execute(query)
return self.cursor.fetchall()

def searchTopic(self, search):
try:
searchString = "%{0}%".format(search)
Expand Down
3 changes: 3 additions & 0 deletions gui/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,9 @@ def installGithubHymnLyrics(self):
def installGithubBooks(self):
self.installFromGitHub(GitHubRepoInfo.books)

def installGithubStatistics(self):
self.installFromGitHub(GitHubRepoInfo.statistics)

def installGithubMaps(self):
self.installFromGitHub(GitHubRepoInfo.maps)

Expand Down
1 change: 1 addition & 0 deletions gui/MenuItems.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def addGithubDownloadMenuItems(self, subMenu):
("gitHubPluginsMenu", self.installGithubPluginsMenu),
("githubBiblesIndex", self.installGithubBiblesIndex),
("gitHubBibleAbbreviations", self.installGithubBibleAbbreviations),
("githubStatistics", self.installGithubStatistics),
)
for feature, action in items:
addMenuItem(subMenu, feature, self, action)
Expand Down
1 change: 1 addition & 0 deletions lang/language_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Anpassen",
"donate": "Spenden",
"about": "Informationen zu",
"githubStatistics": "GitHub-Statistik",
}
1 change: 1 addition & 0 deletions lang/language_el.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Προσαρμογή:",
"donate": "Δότη!",
"about": "-Ναι.",
"githubStatistics": "Στατιστικά στοιχεία GitHub",
}
1 change: 1 addition & 0 deletions lang/language_en_GB.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Customise",
"donate": "Donate",
"about": "About",
"githubStatistics": "GitHub Statistics",
}
1 change: 1 addition & 0 deletions lang/language_en_US.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Customise",
"donate": "Donate",
"about": "About",
"githubStatistics": "GitHub Statistics",
}
1 change: 1 addition & 0 deletions lang/language_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Customise",
"donate": "Donar",
"about": "Acerca de",
"githubStatistics": "Estadísticas de GitHub",
}
1 change: 1 addition & 0 deletions lang/language_fr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Personnaliser",
"donate": "Donate",
"about": "A propos",
"githubStatistics": "Statistiques GitHub",
}
1 change: 1 addition & 0 deletions lang/language_hi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "अनुकूलन",
"donate": "दान",
"about": "लगभग",
"githubStatistics": "Githb सांख्यिकी",
}
1 change: 1 addition & 0 deletions lang/language_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Personalizzazione",
"donate": "Donato",
"about": "Informazioni su",
"githubStatistics": "Statistiche GitHub",
}
1 change: 1 addition & 0 deletions lang/language_ja.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "カスタマイズ",
"donate": "ドナーテ",
"about": "アバウト",
"githubStatistics": "GitHub 統計",
}
1 change: 1 addition & 0 deletions lang/language_ko.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "사용자 정의",
"donate": "기부하다",
"about": "정보",
"githubStatistics": "깃허브 통계",
}
1 change: 1 addition & 0 deletions lang/language_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "കസ്റ്റംസ്",
"donate": "ഡോണെറ്റ്",
"about": "ഏകദേശം",
"githubStatistics": "ഗിറ്റ്ഹബ് സ്ഥിതിവിവരംName",
}
1 change: 1 addition & 0 deletions lang/language_ro.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Personalizează",
"donate": "Donează",
"about": "Despre",
"githubStatistics": "Statistici GitHub",
}
1 change: 1 addition & 0 deletions lang/language_ru.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Customise",
"donate": "Пожертвовать",
"about": "О",
"githubStatistics": "Статистика GitHub",
}
1 change: 1 addition & 0 deletions lang/language_zh_HANS.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "定制",
"donate": "捐赠",
"about": "关于",
"githubStatistics": "GitHub 统计信息",
}
1 change: 1 addition & 0 deletions lang/language_zh_HANT.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,4 +1087,5 @@
"customise": "Customise",
"donate": "多納特",
"about": "關於",
"githubStatistics": "GitHub 統計資料",
}
4 changes: 4 additions & 0 deletions latest_changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Changes in 35.25:
* Add display word frequency menu plugin
- https://github.com/eliranwong/UniqueBible/wiki/Display-Word-Frequency-Menu-Plugin

Changes in 35.24:
* Add shortcut to toggle audio toolbar

Expand Down
9 changes: 9 additions & 0 deletions marvelData/statistics/frequency_color_mapping.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Used for "Display Word Frequency" menu plugin
# To override this file, create a file named frequency_color_mapping_custom.txt with your mapping data
# Mapping data:
# start word frequency, end word frequency, light theme color, dark/night theme color

1, 1, red, red
2, 5, blue, orange
6, 10, green, green
11, 10000, black, white
52 changes: 28 additions & 24 deletions patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,6 @@
(31.07, "file", "gui/MorphologyLauncher.py")
(31.07, "file", "plugins/layout/Starter.py")
(31.07, "file", "plugins/menu/Presentation.py")
(31.07, "file", "util/GitHubRepoInfo.py")
(31.09, "folder", "plugins/language")
(31.09, "file", "plugins/language/Readme.md")
(31.09, "file", "plugins/language/sc.biblebooks")
Expand Down Expand Up @@ -1231,7 +1230,6 @@
(33.50, "file", "plugins/terminal/generate bar chart from latest content.py")
(33.50, "file", "plugins/terminal/generate pie chart from copied text.py")
(33.50, "file", "plugins/terminal/generate pie chart from latest content.py")
(33.50, "file", "util/LanguageUtil.py")
(33.50, "file", "util/terminal_text_editor.py")
(33.50, "file", "util/TextFileReader.py")
(33.50, "file", "util/Translator.py")
Expand Down Expand Up @@ -1296,7 +1294,6 @@
(33.96, "file", "gui/SimpleBrowser.py")
(33.96, "file", "gui/WorkSpace.py")
(33.96, "file", "gui/YouTubePopover.py")
(33.98, "file", "gui/MenuItems.py")
(34.04, "file", "htmlResources/material/action/terminal/materialiconsoutlined/48dp/2x/outline_terminal_black_48dp.png")
(34.05, "file", "plugins/menu/Terminal.py")
(34.07, "file", "gui/MiniBrowser.py")
Expand Down Expand Up @@ -1349,22 +1346,6 @@
(34.88, "file", "util/RemoteHttpHandler.py")
(34.89, "file", "util/AGBparagraphs_expanded.py")
(34.89, "file", "marvelData/AGBTS_data.sqlite")
(34.91, "file", "db/ToolsSqlite.py")
(34.95, "file", "lang/language_de.py")
(34.95, "file", "lang/language_el.py")
(34.95, "file", "lang/language_en_GB.py")
(34.95, "file", "lang/language_en_US.py")
(34.95, "file", "lang/language_es.py")
(34.95, "file", "lang/language_fr.py")
(34.95, "file", "lang/language_hi.py")
(34.95, "file", "lang/language_it.py")
(34.95, "file", "lang/language_ja.py")
(34.95, "file", "lang/language_ko.py")
(34.95, "file", "lang/language_ml.py")
(34.95, "file", "lang/language_ro.py")
(34.95, "file", "lang/language_ru.py")
(34.95, "file", "lang/language_zh_HANS.py")
(34.95, "file", "lang/language_zh_HANT.py")
(34.98, "file", "plugins/chatGPT/integrate google searches.py")
(35.01, "file", "plugins/chatGPT/000_UBA.py")
(35.05, "file", "plugins/chatGPT/execute python code.py")
Expand All @@ -1385,11 +1366,34 @@
(35.21, "file", "util/RemoteApiHandler.py")
(35.22, "file", "util/RemoteCliHandler.py")
(35.22, "file", "util/LocalCliHandler.py")
(35.22, "file", "util/TextCommandParser.py")
(35.23, "file", "util/checkup.py")
(35.24, "file", "gui/MainWindow.py")
(35.24, "file", "gui/MaterialMainWindow.py")
(35.24, "file", "util/ShortcutUtil.py")
(35.24, "file", "patches.txt")
(35.24, "file", "UniqueBibleAppVersion.txt")
(35.24, "file", "latest_changes.txt")
(35.25, "file", "db/StatisticsWordsSqlite.py")
(35.25, "file", "db/ToolsSqlite.py")
(35.25, "file", "gui/MainWindow.py")
(35.25, "file", "gui/MenuItems.py")
(35.25, "file", "lang/language_de.py")
(35.25, "file", "lang/language_el.py")
(35.25, "file", "lang/language_en_GB.py")
(35.25, "file", "lang/language_en_US.py")
(35.25, "file", "lang/language_es.py")
(35.25, "file", "lang/language_fr.py")
(35.25, "file", "lang/language_hi.py")
(35.25, "file", "lang/language_it.py")
(35.25, "file", "lang/language_ja.py")
(35.25, "file", "lang/language_ko.py")
(35.25, "file", "lang/language_ml.py")
(35.25, "file", "lang/language_ro.py")
(35.25, "file", "lang/language_ru.py")
(35.25, "file", "lang/language_zh_HANS.py")
(35.25, "file", "lang/language_zh_HANT.py")
(35.25, "folder", "marvelData/statistics")
(35.25, "file", "marvelData/statistics/frequency_color_mapping.txt")
(35.25, "file", "plugins/menu/Display Word Frequency.py")
(35.25, "file", "util/GitHubRepoInfo.py")
(35.25, "file", "util/LanguageUtil.py")
(35.25, "file", "util/TextCommandParser.py")
(35.25, "file", "patches.txt")
(35.25, "file", "latest_changes.txt")
(35.25, "file", "UniqueBibleAppVersion.txt")
19 changes: 19 additions & 0 deletions plugins/menu/Display Word Frequency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import config
from util.BibleBooks import BibleBooks

filename = os.path.join(config.marvelData, 'statistics', 'words.stats')
if not os.path.exists(filename):
config.mainWindow.installGithubStatistics()

text = str(config.mainText)
if text[-1] not in ('+', '*', 'x'):
filename = os.path.join(config.marvelData, 'bibles', 'KJVx.bible')
if not os.path.exists(filename):
config.mainWindow.displayMessage("Please download the KJVx.bible")
config.mainWindow.installGithubBibles()
text = "KJVx"

book = BibleBooks.abbrev["eng"][str(config.mainB)][0]

config.mainWindow.runTextCommand("DISPLAYWORDFREQUENCY:::{0}:::{1} {2}".format(text, book, config.mainC))
5 changes: 4 additions & 1 deletion util/GitHubRepoInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class GitHubRepoInfo:
biblesIndex = ("otseng/UniqueBible_Bibles_Index", "indexes/bible", "githubBiblesIndex", "index")
commentaries = ("otseng/UniqueBible_Commentaries", "commentaries", "githubCommentaries", "commentary")
books = ("darrelwright/UniqueBible_Books", "books", "githubBooks", "book")
statistics = ("otseng/UniqueBible_Statistics", "statistics", "githubStatistics", "stats")
hymnLyrics = ("otseng/UniqueBible_Hymn_Lyrics", "books", "githubHymnLyrics", "book")
maps = ("darrelwright/UniqueBible_Maps-Charts", "books", "githubMaps", "book")
pdf = ("otseng/UniqueBible_PDF", "pdf", "githubPdf", "pdf")
Expand All @@ -18,7 +19,7 @@ class GitHubRepoInfo:
devotionals = ("otseng/UniqueBible_Devotionals", "devotionals", "gitHubDevotionals", "devotion")
bibleAbbreviations = ("otseng/UniqueBible_Bible_Abbreviations", "../plugins/language", "gitHubBibleAbbreviations", "biblebooks")

types = ["bibles", "books", "commentaries", "devotionals", "pdf", "docx", "mp3", "mp4"]
types = ["bibles", "books", "commentaries", "statistics", "devotionals", "pdf", "docx", "mp3", "mp4"]
# "epub", "plugins-context", "plugins-layout", "plugins-menu", "plugins-startup", "plugins-shutdown"]

@staticmethod
Expand All @@ -27,6 +28,7 @@ def buildInfo(repo, type, directory=""):
"books": ("books", "githubBooks", "book"),
"commentaries": ("commentaries", "githubCommentaries", "commentary"),
"devotionals": ("devotionals", "gitHubDevotionals", "devotion"),
"statistics": ("statistics", "githubStatistics", "stats"),
"epub": ("epub", "githubEpub", "epub"),
"pdf": ("pdf", "githubPdf", "pdf"),
"docx": ("docx", "wordDocument", "docx"),
Expand All @@ -48,6 +50,7 @@ def getLibraryType(type):
"books": "BOOK",
"commentaries": "COMM",
"devotionals": "DEVOTIONAL",
"stats": "STATS",
"pdf": "PDF",
"docx": "DOCX",
"epub": "EPUB",
Expand Down
2 changes: 1 addition & 1 deletion util/LanguageUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ def translateWord(text, code):
print("Error executing: " + str(e))
else:
# printCodesSupportedLanguages()
addLanguageStringToAllFiles("enableHttpRemoteErrorRedirection", "Go to redirection page if error in http server")
addLanguageStringToAllFiles("githubStatistics", "GitHub Statistics")
42 changes: 41 additions & 1 deletion util/TextCommandParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from prompt_toolkit.input import create_input
from prompt_toolkit.keys import Keys
from datetime import date

from db.StatisticsWordsSqlite import StatisticsWordsSqlite
from util.VlcUtil import VlcUtil
from util.exlbl import allLocations, tc_location_names, sc_location_names
from util.PluginEventHandler import PluginEventHandler
Expand Down Expand Up @@ -730,6 +732,13 @@ def __init__(self, parent):
# Feature - Open today's devotional entry
# e.g. DEVOTIONAL:::Meyer
"""),
"displaywordfrequency": (self.displayWordFrequency, """
# [KEYWORD] DISPLAYWORDFREQUENCY
# Feature - Displays the word frequency for Bibles with Strongs numbers
# and highlights with different colors based on frequency
# Usage - DISPLAYWORDFREQUENCY:::[BIBLE_VERSION]:::[BIBLE_REFERENCE(S)]
# This will only highlight Bibles that contain Strongs numbers
"""),
#
# Keywords starting with "_" are mainly internal commands for GUI operations
# They are not recorded in history records.
Expand Down Expand Up @@ -1005,7 +1014,7 @@ def parser(self, textCommand, source="main"):
command = command.strip()
if not command:
currentBibleReference = self.bcvToVerseReference(config.mainB, config.mainC, config.mainV)
if keyword in ("bible", "study", "compare", "crossreference", "diff", "difference", "tske", "translation", "discourse", "words", "combo", "commentary", "index", "openversenote"):
if keyword in ("bible", "study", "compare", "crossreference", "diff", "difference", "tske", "translation", "discourse", "words", "combo", "commentary", "index", "openversenote", "displaywordfrequency"):
command = currentBibleReference
print(f"Running '{keyword}:::{command}' ...")
elif keyword in ("openbooknote",):
Expand Down Expand Up @@ -2132,6 +2141,37 @@ def cancelBibleParallels(self):
config.terminalBibleParallels = False
config.terminalBibleComparison = False

# DISPLAYWORDFREQUENCY:::KJVx:::Matt 1
# DISPLAYWORDFREQUENCY:::KJVx:::Matt 1:::custom
def displayWordFrequency(self, command, source):
customFile = "custom"
if command.count(":::") == 2:
texts, references, customFile = command.split(":::")
else:
texts, references = command.split(":::")
config.readFormattedBibles = False
statisticsSqlite = StatisticsWordsSqlite()

data = self.textBible(f"{texts}:::{references}", source)

text = data[1]
matches = re.findall(r" ([GH][0-9]*?) ", text)

highlightMapping = statisticsSqlite.loadHighlightMappingFile(customFile)

for strongs in set(matches):
frequency = statisticsSqlite.getFrequency(strongs)
color = ""
for map in highlightMapping:
if frequency >= int(map[0]) and frequency <= int(map[1]):
if config.theme in ("dark", "night"):
color = map[3]
else:
color = map[2]
if color:
text = statisticsSqlite.addHighlightTagToPreviousWord(text, strongs, color, frequency)
return (data[0], text, data[2])

# BIBLE:::
def textBible(self, command, source):
if command.count(":::") == 0:
Expand Down

0 comments on commit c1a339b

Please sign in to comment.