Example #1
0
def add_kb(kb_name="Untitled", kb_type=None):
    """
    Adds a new kb in database, and returns its id
    The name of the kb will be 'Untitled#'
    such that it is unique.

    @param kb_name: the name of the kb
    @param kb_type: the type of the kb, incl 'taxonomy' and 'dynamic'.
                   None for typical (leftside-rightside).
    @return the id of the newly created kb
    """
    name = kb_name
    i = 1
    while bibknowledge_dblayer.kb_exists(name):
        name = kb_name + " " + str(i)
        i += 1
    kb_id = bibknowledge_dblayer.add_kb(name, "", kb_type)
    return kb_id
Example #2
0
def add_kb(kb_name="Untitled", kb_type=None):
    """
    Adds a new kb in database, and returns its id
    The name of the kb will be 'Untitled#'
    such that it is unique.

    @param kb_name: the name of the kb
    @param kb_type: the type of the kb, incl 'taxonomy' and 'dynamic'.
                   None for typical (leftside-rightside).
    @return the id of the newly created kb
    """
    name = kb_name
    i = 1
    while bibknowledge_dblayer.kb_exists(name):
        name = kb_name + " " + str(i)
        i += 1
    kb_id = bibknowledge_dblayer.add_kb(name, "", kb_type)
    return kb_id
Example #3
0
    description = ""
    for opt, opt_value in opts:
        if opt in ("-h", "--help"):
            print usage
            sys.exit()
        if opt in ("-d", "--description"):
            description = opt_value

    if len(args) < 2:
        sys.stderr.write("Missing kb-file or kb-name\n")
        print usage
        sys.exit(1)

    kbfile = args[0].strip()
    if not os.path.exists(kbfile):
        sys.stderr.write("Path to non-existing file\n")
        print usage
        sys.exit(1)

    kbname = args[1].strip()
    if kb_exists(kbname):
        update_kb(kbname, kbname, description)
    else:
        add_kb(kbname, description)
    num_added = add_kb_values(kbname, kbfile)
    print "Added %i entries to %s" % (num_added, kbname)

if __name__ == "__main__":
    main()
Example #4
0
    description = ""
    for opt, opt_value in opts:
        if opt in ("-h", "--help"):
            print usage
            sys.exit()
        if opt in ("-d", "--description"):
            description = opt_value

    if len(args) < 2:
        sys.stderr.write("Missing kb-file or kb-name\n")
        print usage
        sys.exit(1)

    kbfile = args[0].strip()
    if not os.path.exists(kbfile):
        sys.stderr.write("Path to non-existing file\n")
        print usage
        sys.exit(1)

    kbname = args[1].strip()
    if kb_exists(kbname):
        update_kb(kbname, kbname, description)
    else:
        add_kb(kbname, description)
    num_added = add_kb_values(kbname, kbfile)
    print "Added %i entries to %s" % (num_added, kbname)


if __name__ == "__main__":
    main()