Beispiel #1
0
def reset(overwrite=False, ignore_initial=False):
    # Automatically load presets
    global _presets

    _presets = {}

    load_path = utils.get_write_path("presets")
    if ignore_initial or not os.path.exists(
            os.path.join(load_path, ".initial_complete")):
        # Do initial population of presets from system install / cwd
        if not os.path.exists(load_path):
            os.makedirs(load_path)

        # Write file to say we have done this
        open(os.path.join(load_path, ".initial_complete"), "w").close()

        # Copy actual files
        search_paths = utils.get_search_paths()
        if overwrite:
            # Reverse search paths because things will get overwritten
            search_paths = reversed(search_paths)

        for path in search_paths:
            full = os.path.join(path, "presets")
            if full != load_path and os.path.exists(full):
                for f in os.listdir(full):
                    # Do not overwrite existing files
                    if overwrite or not os.path.exists(
                            os.path.join(load_path, f)):
                        shutil.copy2(os.path.join(full, f), load_path)

    load_directory(load_path)
Beispiel #2
0
def reset(overwrite=False, ignore_initial=False):
    # Automatically load presets
    global _presets
    
    _presets = {}
    
    load_path = utils.get_write_path("presets")
    if ignore_initial or not os.path.exists(os.path.join(load_path, ".initial_complete")):
        # Do initial population of presets from system install / cwd
        if not os.path.exists(load_path):
            os.makedirs(load_path)
            
        # Write file to say we have done this
        open(os.path.join(load_path, ".initial_complete"), "w").close()
        
        # Copy actual files
        for path in utils.get_search_paths():
            full = os.path.join(path, "presets")
            if full != load_path and os.path.exists(full):
                for f in os.listdir(full):
                    # Do not overwrite existing files
                    if overwrite or not os.path.exists(os.path.join(load_path, f)):
                        shutil.copy2(os.path.join(full, f), load_path)
    
    load_directory(load_path)
Beispiel #3
0
def reset(overwrite=False, ignore_initial=False):
    # Automatically load presets
    global _presets

    _presets = {}

    load_path = utils.get_write_path("presets")
    if ignore_initial or not os.path.exists(os.path.join(load_path, ".initial_complete")):
        # Do initial population of presets from system install / cwd
        if not os.path.exists(load_path):
            os.makedirs(load_path)

        # Write file to say we have done this
        open(os.path.join(load_path, ".initial_complete"), "w").close()

        # Copy actual files
        search_paths = utils.get_search_paths()
        if overwrite:
            # Reverse search paths because things will get overwritten
            search_paths = reversed(search_paths)

        print [path for path in search_paths]
Beispiel #4
0
    "A tab separated file containing original terms before entity recognition."
)
parser.add_argument(
    "-o",
    "--output",
    help=
    "The optional path to which a file containing grounded terms in each sentence will be written.",
    default="_")
args = parser.parse_args()

if any([i is None for i in [args.tags, args.input, args.dictionary]]):
    parser.print_help()
    sys.exit(1)

output_file = None
if args.output != "_" and utils.get_write_path(args.output):
    output_file = utils.get_write_path(args.output)

tags = utils.read_tags(args.tags)
original = utils.parse_tsv(args.input)
dictionary = utils.parse_tsv(args.dictionary)

if len(original) != len(tags):
    print("Error: mismatching original inputs and tags ({} and {}).".format(
        len(original), len(tags)))
    sys.exit(1)

if len(dictionary) == 0:
    print("Error: read an empty dictionary, check the tsv.")
    sys.exit(1)
Beispiel #5
0
    help=
    "A tab separated file containing original terms before entity recognition."
)
parser.add_argument(
    "-o",
    "--output",
    help=
    "The optional path to which a file containing grounded terms in each sentence will be written.",
    default="_")
args = parser.parse_args()

if any([i is None for i in [args.tags, args.input, args.dictionary]]):
    parser.print_help()
    sys.exit(1)

output_file = utils.get_write_path(args.output)
out = open(output_file, 'w+')

# Build the disease and chemical dictionary choices separately.
dictionary = utils.parse_tsv(args.dictionary)
if len(dictionary) == 0:
    print("Error: read an empty dictionary, check the tsv.")
    sys.exit(1)

chemical_choices = {
    i[2]: i[0]
    for i in dictionary if i[1].lower() == "chemical"
}
disease_choices = {i[2]: i[0] for i in dictionary if i[1].lower() == "disease"}