def run_prompt(self): self.run(False) self.debug.print_debug(self, u'Entering interactive mode') prompt = Interactive(self.gv) manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath('//back/ref-list/ref') # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False for p in tree.xpath('//xref[@ref-type="bibr"]'): text = manipulate.get_stripped_text(p) if 'rid' in p.attrib and p.attrib['rid'] == 'TO_LINK': prompt.print_( u"Found an unhandled reference marker: {0}".format(text)) elif 'rid' in p.attrib: remote = next((x for x in ref_items if 'id' in x.attrib and ( x.attrib['id'] == p.attrib['rid'])), None) remote_text = manipulate.get_stripped_text(remote) prompt.print_( u"Found a handled reference marker: \"{0}\" which links to \"{1}\"" .format(text, remote_text)) opts = ('Skip', 'Delete', 'deleTe all', 'Enter search', 'Ibid', 'enter Link id', 'skip Rest', 'show Context') sel = '' if delete_all: sel = 'd' else: sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, ref_items, sel, tree=tree) if result == 'abort': manipulate.save_tree(tree) return elif result == 'delall': delete_all = True manipulate.save_tree(tree)
def run_prompt(self): self.run(False) self.debug.print_debug(self, u"Entering interactive mode") prompt = Interactive(self.gv) manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath("//back/ref-list/ref") # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False for p in tree.xpath('//xref[@ref-type="bibr"]'): text = manipulate.get_stripped_text(p) if "rid" in p.attrib and p.attrib["rid"] == "TO_LINK": prompt.print_(u"Found an unhandled reference marker: {0}".format(text)) elif "rid" in p.attrib: remote = next((x for x in ref_items if "id" in x.attrib and (x.attrib["id"] == p.attrib["rid"])), None) remote_text = manipulate.get_stripped_text(remote) prompt.print_(u'Found a handled reference marker: "{0}" which links to "{1}"'.format(text, remote_text)) opts = ( "Skip", "Delete", "deleTe all", "Enter search", "Ibid", "enter Link id", "skip Rest", "show Context", ) sel = "" if delete_all: sel = "d" else: sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, ref_items, sel, tree=tree) if result == "abort": manipulate.save_tree(tree) return elif result == "delall": delete_all = True manipulate.save_tree(tree)
def run_prompt(self, interactive): if not interactive: self.debug.fatal_error( self, 'Cannot enter confirmation mode without interactive flag') prompt = Interactive(self.gv) opts = ('Confirm', 'Unconfirm', 'cOnfirm all', 'uNconfirm all', 'Abort') manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath('//back/ref-list/ref') # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False confirm_all = False for p in tree.xpath('//ref'): text = manipulate.get_stripped_text(p) sel = '' if delete_all: sel = 'u' elif confirm_all: sel = 'c' else: prompt.print_( u"Please confirm whether the following is a bibliographic reference: {0}" .format(text)) sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, sel, tree, text) if result == 'abort': return elif result == 'delall': delete_all = True elif result == 'confirmall': confirm_all = True manipulate.save_tree(tree)
def run_prompt(self): self.run(False) self.debug.print_debug(self, u'Entering interactive mode') prompt = Interactive(self.gv) manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath('//back/ref-list/ref') # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False for p in tree.xpath('//xref[@ref-type="bibr"]'): text = manipulate.get_stripped_text(p) if 'rid' in p.attrib and p.attrib['rid'] == 'TO_LINK': prompt.print_(u"Found an unhandled reference marker: {0}".format(text)) elif 'rid' in p.attrib: remote = next((x for x in ref_items if 'id' in x.attrib and (x.attrib['id'] == p.attrib['rid'])), None) remote_text = manipulate.get_stripped_text(remote) prompt.print_(u"Found a handled reference marker: \"{0}\" which links to \"{1}\"".format(text, remote_text)) opts = ('Skip', 'Delete', 'deleTe all', 'Enter search', 'Ibid', 'enter Link id', 'skip Rest', 'show Context') sel = '' if delete_all: sel = 'd' else: sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, ref_items, sel, tree=tree) if result == 'abort': manipulate.save_tree(tree) return elif result == 'delall': delete_all = True manipulate.save_tree(tree)
def run_prompt(self, interactive): if not interactive: self.debug.fatal_error(self, "Cannot enter confirmation mode without interactive flag") prompt = Interactive(self.gv) opts = ("Confirm", "Unconfirm", "cOnfirm all", "uNconfirm all", "Abort") manipulate = NlmManipulate(self.gv) tree = manipulate.load_dom_tree() ref_items = tree.xpath("//back/ref-list/ref") # note that we don't want to exit even if there are no references to link because the user may want to delete # some delete_all = False confirm_all = False for p in tree.xpath("//ref"): text = manipulate.get_stripped_text(p) sel = "" if delete_all: sel = "u" elif confirm_all: sel = "c" else: prompt.print_(u"Please confirm whether the following is a bibliographic reference: {0}".format(text)) sel = prompt.input_options(opts) result = self.handle_input(manipulate, opts, p, prompt, sel, tree, text) if result == "abort": return elif result == "delall": delete_all = True elif result == "confirmall": confirm_all = True manipulate.save_tree(tree)
def main(): args = docopt(__doc__, version='meTypeset 0.1') bare_gv = GV(args) if args['--debug']: bare_gv.debug.enable_debug(True) bare_gv.debug.enable_prompt(Interactive(bare_gv)) if args['zotero']: from zotero import libzotero zotero = libzotero.LibZotero( unicode(bare_gv.settings.get_setting(u'zotero', bare_gv)), bare_gv) term = args['<query>'] term = re.sub(r'[\-,\.\<\>\(\)\;\:\@\'\#\~\}\{\[\]\"\!\\/]', ' ', term) term = term.replace(u'“', u'') term = re.sub(u'[^\s]+?\s[Ee]dition', u' ', term) term = term.replace(u'\'s', u'') term = term.replace(u'’s', u'') term = term.replace(u'’', u'') term = term.replace(u'”', u'') term = re.sub(r'[Aa]ccessed', '', term) term = re.sub(r'meTypesetbr', '', term) term = re.sub(r'\s+', ' ', term) results = zotero.search(term.strip()) bare_gv.debug.print_debug(bare_gv, "%d results for %s" % (len(results), term)) for item in results: interactive = Interactive(bare_gv) interactive.print_(item.JATS_format()) return bibliography_database_instance = BibliographyDatabase(bare_gv) bibliography_database_instance.run()
def main(): args = docopt(__doc__, version='meTypeset 0.1') bare_gv = GV(args) if args['--debug']: bare_gv.debug.enable_debug(True) bare_gv.debug.enable_prompt(Interactive(bare_gv)) if args['zotero']: from zotero import libzotero zotero = libzotero.LibZotero(unicode(bare_gv.settings.get_setting(u'zotero', bare_gv)), bare_gv) term = args['<query>'] term = re.sub(r'[\-,\.\<\>\(\)\;\:\@\'\#\~\}\{\[\]\"\!\\/]', ' ', term) term = term.replace(u'“', u'') term = re.sub(u'[^\s]+?\s[Ee]dition', u' ', term) term = term.replace(u'\'s', u'') term = term.replace(u'’s', u'') term = term.replace(u'’', u'') term = term.replace(u'”', u'') term = re.sub(r'[Aa]ccessed', '', term) term = re.sub(r'meTypesetbr', '', term) term = re.sub(r'\s+', ' ', term) results = zotero.search(term.strip()) bare_gv.debug.print_debug(bare_gv, "%d results for %s" % (len(results), term)) for item in results: interactive = Interactive(bare_gv) interactive.print_(item.JATS_format()) return bibliography_database_instance = BibliographyDatabase(bare_gv) bibliography_database_instance.run()