Ejemplo n.º 1
0
    def do_annotate(self, line):
        """annotate <template_id> <data> [-n number] [-f field]- add or test annotation (aliases: a, t)

        Add a new annotation (if -f is passed) or test what would be annotated
        otherwise
        """
        if line.find(' ') < 0:
            print(
                "You must provide a valid template identifier (check output of ls_templates)"
            )
            print(IblTool.do_annotate.__doc__)
            return
        template_id, criteria = line.split(' ', 1)
        t = self._load_template(template_id)
        if not t:
            return
        criteria = self._parse_criteria(criteria)
        tm = TemplateMaker(t)
        selection = apply_criteria(criteria, tm)
        if criteria.field:
            for index in selection:
                index = selection[0]
                tm.annotate_fragment(index, criteria.field)
                self._save_template(template_id, tm.get_template())
                print("[new] (%s) %r" %
                      (criteria.field,
                       remove_annotation(tm.selected_data(index))))
        else:
            for n, i in enumerate(selection):
                print("[%d] %r" % (n, remove_annotation(tm.selected_data(i))))
Ejemplo n.º 2
0
    def do_annotate(self, line):
        """annotate <template_id> <data> [-n number] [-f field]- add or test annotation (aliases: a, t)

        Add a new annotation (if -f is passed) or test what would be annotated
        otherwise
        """
        if line.find(' ') < 0:
            print("You must provide a valid template identifier (check output of ls_templates)")
            print(IblTool.do_annotate.__doc__)
            return
        template_id, criteria = line.split(' ', 1)
        t = self._load_template(template_id)
        if not t:
            return
        criteria = self._parse_criteria(criteria)
        tm = TemplateMaker(t)
        selection = apply_criteria(criteria, tm)
        if criteria.field:
            for index in selection:
                index = selection[0]
                tm.annotate_fragment(index, criteria.field)
                self._save_template(template_id, tm.get_template())
                print("[new] (%s) %r" % (criteria.field,
                    remove_annotation(tm.selected_data(index))))
        else:
            for n, i in enumerate(selection):
                print("[%d] %r" % (n, remove_annotation(tm.selected_data(i))))
Ejemplo n.º 3
0
 def test_selected_data(self):
     tm = TemplateMaker(self.PAGE)
     indexes = tm.select(best_match('text to annotate'))
     data = [tm.selected_data(i) for i in indexes]
     self.assertEqual(data, \
         [u'<p>Some text to annotate here</p>', \
         u'<p>Another text to annotate there</p>'])
Ejemplo n.º 4
0
 def test_selected_data(self):
     tm = TemplateMaker(self.PAGE)
     indexes = tm.select(best_match('text to annotate'))
     data = [tm.selected_data(i) for i in indexes]
     self.assertEqual(data, \
         [u'<p>Some text to annotate here</p>', \
         u'<p>Another text to annotate there</p>'])
Ejemplo n.º 5
0
 def do_al(self, template_id):
     """al <template> - list annotations"""
     if assert_or_print(template_id, "missing template id"):
         return
     t = self._load_template(template_id)
     tm = TemplateMaker(t)
     for n, (a, i) in enumerate(tm.annotations()):
         print "[%s-%d] (%s) %r" % (template_id, n, a['annotations']['content'], 
             remove_annotation(tm.selected_data(i)))
Ejemplo n.º 6
0
 def do_t(self, line):
     """ts <template> <text> - test selection text"""
     template_id, criteria = line.split(' ', 1)
     t = self._load_template(template_id)
     criteria = parse_criteria(criteria)
     tm = TemplateMaker(t)
     selection = apply_criteria(criteria, tm)
     for n, i in enumerate(selection):
         print "[%d] %r" % (n, remove_annotation(tm.selected_data(i)))
Ejemplo n.º 7
0
 def do_t(self, line):
     """t <template> <text> - test selection text"""
     template_id, criteria = line.split(' ', 1)
     t = self._load_template(template_id)
     criteria = self._parse_criteria(criteria)
     tm = TemplateMaker(t)
     selection = apply_criteria(criteria, tm)
     for n, i in enumerate(selection):
         print "[%d] %r" % (n, remove_annotation(tm.selected_data(i)))
Ejemplo n.º 8
0
 def do_al(self, template_id):
     """al <template> - list annotations"""
     if assert_or_print(template_id, "missing template id"):
         return
     t = self._load_template(template_id)
     tm = TemplateMaker(t)
     for n, (a, i) in enumerate(tm.annotations()):
         print "[%s-%d] (%s) %r" % (template_id, n,
                                    a['annotations']['content'],
                                    remove_annotation(tm.selected_data(i)))
Ejemplo n.º 9
0
 def do_a(self, line):
     """a <template> <data> [-n number] [-f field]- add or test annotation
     
     Add a new annotation (if -f is passed) or test what would be annotated
     otherwise
     """
     template_id, criteria = line.split(' ', 1)
     t = self._load_template(template_id)
     criteria = parse_criteria(criteria)
     tm = TemplateMaker(t)
     selection = apply_criteria(criteria, tm)
     if criteria.field:
         for index in selection:
             index = selection[0]
             tm.annotate_fragment(index, criteria.field)
             self._save_template(template_id, tm.get_template())
             print "[new] (%s) %r" % (criteria.field,
                 remove_annotation(tm.selected_data(index)))
     else:
         for n, i in enumerate(selection):
             print "[%d] %r" % (n, remove_annotation(tm.selected_data(i)))
Ejemplo n.º 10
0
    def do_a(self, line):
        """a <template> <data> [-n number] [-f field]- add or test annotation

        Add a new annotation (if -f is passed) or test what would be annotated
        otherwise
        """
        template_id, criteria = line.split(' ', 1)
        t = self._load_template(template_id)
        criteria = self._parse_criteria(criteria)
        tm = TemplateMaker(t)
        selection = apply_criteria(criteria, tm)
        if criteria.field:
            for index in selection:
                index = selection[0]
                tm.annotate_fragment(index, criteria.field)
                self._save_template(template_id, tm.get_template())
                print "[new] (%s) %r" % (
                    criteria.field, remove_annotation(tm.selected_data(index)))
        else:
            for n, i in enumerate(selection):
                print "[%d] %r" % (n, remove_annotation(tm.selected_data(i)))
Ejemplo n.º 11
0
 def test_selected_data(self):
     tm = TemplateMaker(self.PAGE)
     indexes = tm.select(best_match("text to annotate"))
     data = [tm.selected_data(i) for i in indexes]
     self.assertEqual(data, [u"<p>Some text to annotate here</p>", u"<p>Another text to annotate there</p>"])