Esempio n. 1
0
 def test_journal(self):
     field, pattern = search_from_reference(
         '[1] J. Mars, oh hello, Nucl.Phys. B76 (1974) 477-482')
     self.assertEqual(field, 'journal')
     self.assert_('Nucl' in pattern)
     self.assert_('B76' in pattern)
     self.assert_('477' in pattern)
    def answer(self, req, user_info, of, cc, colls_to_search, p, f,
               search_units, ln):
        """Answer question given by context.

        Return (relevance, html_string) where relevance is integer
        from 0 to 100 indicating how relevant to the question the
        answer is (see C{CFG_WEBSEARCH_SERVICE_MAX_SERVICE_ANSWER_RELEVANCE}
        for details), and html_string being a formatted answer.
        """
        from invenio.refextract_api import search_from_reference

        _ = gettext_set_language(ln)

        if f or not self.seems_a_journal_reference(p):
            return (0, "")

        (field, pattern) = search_from_reference(p.decode('utf-8'))

        if field is not "journal":
            return (0, "")

        recids = perform_request_search(req=req,
                                        p=pattern,
                                        f=field,
                                        cc=cc,
                                        c=colls_to_search)

        if not recids:
            return (0, "")

        if len(recids) == 1:
            recid = recids.pop()
            user_info = collect_user_info(req)
            return (100, """\
<p><span class="journalhint">%s</span></p>
<table style="padding: 5px; border: 2px solid #ccc; margin: 20px"><tr><td>
%s
</td></tr></table>""" % (escape(_("Were you looking for this paper?")),
                         print_record(recid, ln=ln, user_info=user_info)))

        query = "find rawref \"" + p + "\""
        query_link = CFG_SITE_URL + '/search?' + urlencode({'p': query})
        return (
            80, '<span class="journalhint">%s</span>' %
            (_("Were you looking for a journal reference? Try: %(x_href)s") % {
                "x_href":
                '<a href="{0}">{1}</a>'.format(escape(query_link, True),
                                               escape(query))
            }, ))
    def answer(self, req, user_info, of, cc,
               colls_to_search, p, f, search_units, ln):
        """Answer question given by context.

        Return (relevance, html_string) where relevance is integer
        from 0 to 100 indicating how relevant to the question the
        answer is (see C{CFG_WEBSEARCH_SERVICE_MAX_SERVICE_ANSWER_RELEVANCE}
        for details), and html_string being a formatted answer.
        """
        from invenio.refextract_api import search_from_reference

        _ = gettext_set_language(ln)

        if f or not self.seems_a_journal_reference(p):
            return (0, "")

        (field, pattern) = search_from_reference(p.decode('utf-8'))

        if field is not "journal":
            return (0, "")

        recids = perform_request_search(
            req=req, p=pattern, f=field, cc=cc, c=colls_to_search)

        if not recids:
            return (0, "")

        if len(recids) == 1:
            recid = recids.pop()
            user_info = collect_user_info(req)
            return (100, """\
<p><span class="journalhint">%s</span></p>
<table style="padding: 5px; border: 2px solid #ccc; margin: 20px"><tr><td>
%s
</td></tr></table>""" % (escape(_("Were you looking for this paper?")),
             print_record(recid, ln=ln, user_info=user_info)))

        query = "find rawref \"" + p + "\""
        query_link = CFG_SITE_URL + '/search?' + urlencode({'p': query})
        return (80, '<span class="journalhint">%s</span>' % (
                _("Were you looking for a journal reference? Try: %(x_href)s") %
                {"x_href": '<a href="{0}">{1}</a>'.format(
                 escape(query_link, True), escape(query))}, ))
Esempio n. 4
0
def check_record(record):
    """
    ensure that 999C5s is in standard form "p,v,c"
    fix if possible, otherwise flag
    """
    for pos, val in record.iterfield('999C5s'):
        if val.count(',') < 2:
            val = val.decode('utf-8')
            field, pubnote = search_from_reference(val)
            if pubnote and field == 'journal':
                if abs(len(pubnote) - len(val)) < 3:
                    record.amend_field(pos, pubnote)
                else:
                    record.warn("fix ref 999C5s: '{0}' ==> '{1}'".format(val, pubnote))
            elif field == 'report':
                record.warn("report number in 999C5s, should move '{0}' ==> '999C5r:{1}'".format(
                    val, pubnote))
            else:
                record.warn("999C5s in non-standard form: '{0}'".format(
                    val))
Esempio n. 5
0
 def test_report(self):
     field, pattern = search_from_reference(
         '[1] J. Mars, oh hello, [hep-ph/0104088]')
     self.assertEqual(field, 'report')
     self.assertEqual(pattern, 'hep-ph/0104088')
Esempio n. 6
0
 def test_not_recognized(self):
     field, pattern = search_from_reference('[1] J. Mars, oh hello')
     self.assertEqual(field, '')
     self.assertEqual(pattern, '')
Esempio n. 7
0
 def test_not_recognized_unicode_2(self):
     field, pattern = search_from_reference(u'Capellà Pere')
     self.assertEqual(field, '')
     self.assertEqual(pattern, '')
Esempio n. 8
0
 def test_not_recognized_unicode_1(self):
     field, pattern = search_from_reference(u'País Valencià')
     self.assertEqual(field, '')
     self.assertEqual(pattern, '')
Esempio n. 9
0
 def test_journal(self):
     field, pattern = search_from_reference('[1] J. Mars, oh hello, Nucl.Phys. B76 (1974) 477-482')
     self.assertEqual(field, 'journal')
     self.assert_('Nucl' in pattern)
     self.assert_('B76' in pattern)
     self.assert_('477' in pattern)
Esempio n. 10
0
 def test_report(self):
     field, pattern = search_from_reference('[1] J. Mars, oh hello, [hep-ph/0104088]')
     self.assertEqual(field, 'report')
     self.assertEqual(pattern, 'hep-ph/0104088')
Esempio n. 11
0
 def test_not_recognized(self):
     field, pattern = search_from_reference('[1] J. Mars, oh hello')
     self.assertEqual(field, '')
     self.assertEqual(pattern, '')