def highlightSearch(self, content): highlight = config.noteSearchString if highlight and not highlight == "z": content = re.sub("("+highlight+")", r"<z>\1</z>", content, flags=re.IGNORECASE) content = TextUtil.fixTextHighlighting(content) # add an id so as to scroll to the first result content = re.sub("<z>", "<z id='v{0}.{1}.{2}'>".format(config.studyB, config.studyC, config.studyV), content, count=1) return content
def runTextCommand(self, textCommand, addRecord=False, source="cli", forceExecute=False): view, content, dict = TextCommandParser(self).parser( textCommand, source) print(TextUtil.htmlToPlainText(content))
def googleTranslate(self, language): selectedText = self.selectedText().strip() if not selectedText: self.messageNoSelection() else: selectedText = TextUtil.plainTextToUrl(selectedText) url = "https://translate.google.com/?sl=origin_language_or_auto&tl={0}&text={1}&op=translate".format( language, selectedText) webbrowser.open(url)
def constrcutTrie(self, filename): keywords = TextUtil.generateKeyWords(filename) for keyword in keywords: self.keywords.add(tuple(keyword)) self.prefixTrie.insert(keyword) keyword.reverse() self.suffixTrie.insert(keyword) self.countKeywords += 1 for character in keyword: keyword = set(keyword) if character not in self.characters: self.characters[character] = 0 self.characters[character] += 1
def getContentData(self, query, entry): self.cursor.execute(query, (entry, )) row = self.cursor.fetchone() if not row: return "[not applicable]" else: config.book = self.module config.bookChapter = row[0] content = row[1] config.bookChapNum = row[2] if config.overwriteBookFont: fontFamily = config.font if config.overwriteBookFontFamily: fontFamily = config.overwriteBookFontFamily content = re.sub("font-family:[^<>]*?;", r"font-family:'{0}';".format(fontFamily), content) if config.overwriteBookFontSize: if type(config.overwriteBookFontSize) == bool: content = re.sub("font-size:[^<>]*?;", "", content) elif type(config.overwriteBookFontSize) == int: content = re.sub( "font-size:[^<>]*?;", r"font-size:'{0}px';".format( config.overwriteBookFontSize), content) elif type(config.overwriteBookFontSize) == str: content = re.sub( "font-size:[^<>]*?;", r"font-size:'{0}';".format( config.overwriteBookFontSize), content) for searchString in config.bookSearchString.split("%"): if searchString and not searchString == "z": content = re.sub("({0})".format(searchString), r"<z>\1</z>", content, flags=re.IGNORECASE) content = TextUtil.fixTextHighlighting(content) # add an id so as to scroll to the first result content = re.sub("<z>", "<z id='v{0}.{1}.{2}'>".format( config.studyB, config.studyC, config.studyV), content, count=1) if config.theme == "dark": content = self.adjustDarkThemeColorsForBook(content) # return content return "<p><ref onclick='document.title={3}BOOK:::{0}{3}'>{0}</ref><br>> <b>{1}</b></p>{2}".format( self.module, config.bookChapter, content, '"')
def generateNegativeKeyWords(self, keywords): negativeWords = [] stopwords = TextUtil.getStopWords("../util/stopword.txt") for keyword in keywords: flag = True for stopword in stopwords: stopword = set(stopword) if stopword.issubset(keyword): flag = False break if not flag: continue for negativeWord in negativeWords: tmpNegativeWord = set(negativeWord) if tmpNegativeWord.issubset(keyword): negativeWords.remove(negativeWord) negativeWords.append(keyword) return negativeWords
def shell(reader, writer): from util.TextCommandParser import TextCommandParser textCommandParser = TextCommandParser(RemoteCliMainWindow()) writer.write("Connected to UniqueBible.app" + CRLF) linereader = RemoteCliHandler.readline(reader, writer) linereader.send(None) command = None while True: if command: writer.write(CRLF) writer.write('> ') command = None while command is None: inp = yield from reader.read(1) if not inp: return command = linereader.send(inp) writer.write(CRLF) command = re.sub("\[[ABCD]", "", command) command = command.strip() if command.lower() in ('.quit', '.exit', '.bye'): break elif command.lower() in ('.help', '?'): RemoteCliHandler.help(writer) elif len(command) > 0: view, content, dict = textCommandParser.parser(command, "cli") if not content: content = "Command was processed!" content = TextUtil.htmlToPlainText(content) content = re.sub(r"\n", CRLF, content) content = content.strip() writer.write(content) writer.close()
import config, webbrowser from util.TextUtil import TextUtil if config.pluginContext: content = TextUtil.plainTextToUrl(config.pluginContext) webbrowser.open("https://www.google.com/search?q={0}".format(content)) else: config.contextSource.messageNoSelection()
def setDaysElapse(self): digits = TextUtil.getDigits(self.daysInput.text()) if digits == '': digits = '0' config.daysElapseForNextAppUpdateCheck = digits
def main(): filename="data/负样本评论.txt" keywords=TextUtil.generateKeyWords(filename) keywords=set(keywords) print(len(keywords))