Пример #1
0
def find_knowl_crossrefs(id, all=True, verbose=False):
    """Finds knowl(s) which cite the given knowl.

    if verbose, list the citing knowls (or just the first if
    all=False), otherwise just return True/False according to whether
    any other knowls cite the given one.

    EXAMPLE:

    sage: find_knowl_crossrefs("ec.q.torsion_order", verbose=True)
    knowl ec.q.torsion_order is cited by ec.q.bsd_invariants
    knowl ec.q.torsion_order is cited by ec.q.mordell-weil
    True

    """
    found = False
    for k in knowldb.search():
        content = knowldb.get_knowl(k['id'])['content']
        if id in content:
            found = True
            if verbose:
                print("knowl {} is cited by {}".format(id, k['id']))
            if not all or not verbose:
                return True
    return found
Пример #2
0
def check_knowls(cat='ec', verbose=False):
    cat_knowls = knowldb.search(category=cat)
    if verbose:
        print("%s knowls in category %s" % (len(cat_knowls), cat))
    for k in cat_knowls:
        if verbose:
            print("Checking knowl %s" % k['id'])
        k = knowldb.get_knowl(k['id'])
        cont = k['content']
        i = 0
        while (i >= 0):
            i = cont.find("KNOWL_INC")
            if i >= 0:
                offset = 10
            else:
                i = cont.find("KNOWL")
                if i >= 0:
                    offset = 6
            if (i >= 0):
                cont = cont[i + offset:]
                qu = cont[0]
                j = cont.find(qu, 1)
                ref = cont[1:j]
                if verbose:
                    print("..cites %s" % ref)
                cont = cont[j + 1:]
                the_ref = knowldb.get_knowl(ref)
                if the_ref is None:
                    print("Non-existing reference to %s in knowl %s" %
                          (ref, k['id']))
                elif verbose:
                    print("--- found")
Пример #3
0
def interesting_knowls(category, table, url_for_label, label_col="label", regex=None, **kwds):
    # category might be something like ec.q
    main_cat = category.split(".")[0]
    if category[-1] != ".":
        category += "."
    knowls = knowldb.search(category=main_cat, types=["top", "bottom"], filters=["beta", "reviewed"], projection=["id", "title", "type"])
    # Filter to only those with category correct
    knowls = [k for k in knowls if k["id"].startswith(category)]
    # Get the labels and links
    n = len(category)
    unsorted = {}
    labels = []
    for k in knowls:
        label = k["id"][n:]
        label = label[:label.rfind(".")]
        if regex and not regex.match(label):
            continue
        labels.append(label)
        k["label"] = label
        k["link"] = url_for_label(label)
        unsorted[label] = k
    # Use the table for sorting
    sorted_labels = {lab: i for (i, lab) in enumerate(table.search({label_col: {"$in": labels}}, label_col))}
    # Some labels might not appear (e.g. if an isogeny class knowl was included)
    # and others might appear multiple times (higher genus families, where the "label" is for a family and isn't unique)
    if sorted_labels:
        M = max(sorted_labels.values()) + 1
    else:
        M = 1
    knowls = [unsorted[lab] for lab in sorted(unsorted.keys(), key=lambda x: sorted_labels.get(x, M))]
    return render_template("interesting.html", knowls=knowls, **kwds)
Пример #4
0
def find_knowl_crossrefs(id, all=True, verbose=False):
    """Finds knowl(s) which cite the given knowl.

    if verbose, list the citing knowls (or just the first if
    all=False), otherwise just return True/False according to whether
    any other knowls cite the given one.

    EXAMPLE:

    sage: find_knowl_crossrefs("ec.q.torsion_order", verbose=True)
    knowl ec.q.torsion_order is cited by ec.q.bsd_invariants
    knowl ec.q.torsion_order is cited by ec.q.mordell-weil
    True

    """
    found = False
    for k in knowldb.search():
        content = knowldb.get_knowl(k['id'])['content']
        if id in content:
            found = True
            if verbose:
                print("knowl {} is cited by {}".format(id,k['id']))
            if not all or not verbose:
                return True
    return found    
Пример #5
0
def profile(userid):
    # See issue #1169
    user = LmfdbUser(userid)
    bread = base_bread() + [(user.name, url_for('.profile', userid=user.get_id()))]
    from lmfdb.knowledge.knowl import knowldb
    userknowls = knowldb.search(author=userid, sort=['title'])
    return render_template("user-detail.html", user=user,
                           title="%s" % user.name, bread=bread, userknowls=userknowls)
Пример #6
0
def profile(userid):
    # See issue #1169
    user = LmfdbUser(userid)
    bread = base_bread() + [(user.name, url_for('.profile', userid=user.get_id()))]
    from lmfdb.knowledge.knowl import knowldb
    userknowls = knowldb.search(author=userid, sort=['title'])
    return render_template("user-detail.html", user=user,
                           title="%s" % user.name, bread=bread, userknowls=userknowls)
Пример #7
0
def profile(userid):
    user = LmfdbUser(userid)
    if not user.exists:
        flash_error("User %s does not exist", userid)
        return flask.redirect(url_for(".list"))
    bread = base_bread() + [
        (user.name, url_for('.profile', userid=user.get_id()))
    ]
    from lmfdb.knowledge.knowl import knowldb
    userknowls = knowldb.search(author=userid, sort=['title'])
    return render_template("user-detail.html",
                           user=user,
                           title="%s" % user.name,
                           bread=bread,
                           userknowls=userknowls)
Пример #8
0
def uncited_knowls(ignore_top_and_bottom=True):
    """Lists all knowls not cited by other knowls.

    Knowls whose id ends in "top" or "bottom" are ignored by default.

    NB This lists a lot of knowls which are linked from code or
    templates so is not so useful by itself.

    """
    for k in knowldb.search():
        kid = k['id']
        if kid.endswith(".top") or kid.endswith(".bottom"):
            continue
        crossrefs = find_knowl_crossrefs(kid)
        links = find_knowl_links(kid)
        if crossrefs:
            print("{} is cited by other knowl(s)".format(kid))
        else:
            print("No other knowl cites {}".format(kid))
        if links:
            print("{} IS mentioned in the source code".format(kid))
        else:
            print("{} is NOT mentioned in the source code".format(kid))
Пример #9
0
def uncited_knowls(ignore_top_and_bottom=True):
    """Lists all knowls not cited by other knowls.

    Knowls whose id ends in "top" or "bottom" are ignored by default.

    NB This lists a lot of knowls which are linked from code or
    templates so is not so useful by itself.

    """
    for k in knowldb.search():
        kid = k['id']
        if kid.endswith(".top") or kid.endswith(".bottom"):
            continue
        crossrefs = find_knowl_crossrefs(kid)
        links = find_knowl_links(kid)
        if crossrefs:
            print("{} is cited by other knowl(s)".format(kid))
        else:
            print("No other knowl cites {}".format(kid))
        if links:
            print("{} IS mentioned in the source code".format(kid))
        else:
            print("{} is NOT mentioned in the source code".format(kid))
Пример #10
0
def check_knowls(cat='ec', verbose=False):
    cat_knowls = knowldb.search(category=cat)
    if verbose:
        print("%s knowls in category %s" % (len(cat_knowls),cat))
    for k in cat_knowls:
        if verbose:
            print("Checking knowl %s" % k['id'])
        k = knowldb.get_knowl(k['id'])
        cont = k['content']
        all_content = cont
        cont = cont.replace("KNOWL ","KNOWL")
        i = 0
        while (i>=0):
            i = cont.find("KNOWL_INC")
            if i>=0:
                offset = 10
            else:
                i = cont.find("KNOWL")
                if i>=0:
                    offset=6
            if (i>=0):
                cont = cont[i+offset:]
                qu = cont[0]
                j = cont.find(qu,1)
                ref = cont[1:j]
                if verbose:
                    print("..cites %s" % ref)
                cont = cont[j+1:]
                the_ref = knowldb.get_knowl(ref)
                if the_ref is None:
                    print("Non-existing reference to %s in knowl %s" % (ref,k['id']))
                    print("content of {} = ".format(k['id']))
                    print(all_content)
                    return False
                elif verbose:
                    print("--- found")
    return True