Exemple #1
0
    def load(self, path):

        for f in utils.get_files_in_path(path):
            if not f.endswith(".json"):
                continue
            config_name = Path(f).stem
            logging.debug("Loading {}".format(f))
            with open(f, "r") as fp:
                self.configs[config_name] = json.load(fp)

        logging.debug("Loaded config: %s", self.configs)
Exemple #2
0
    def upload_filepaths(self, filepaths):
        # Convert a directory to a list of files
        if len(filepaths) == 1 and os.path.isdir(filepaths[0]):
            filepaths = get_files_in_path(filepaths[0])

        # Zip up files
        s = StringIO.StringIO()
        zip_file = ZipFile(s, 'w')
        for filepath in filepaths:
            zip_file.write(filepath)
        zip_file.close()
        content = s.getvalue()

        self.upload_file('temp.zip', content, zip_files=False)
Exemple #3
0
    def add_files(self, filepaths):
        # Convert a directory to a list of files
        if len(filepaths) == 1 and os.path.isdir(filepaths[0]):
            filepaths = get_files_in_path(filepaths[0])

        # Zip up files
        s = StringIO.StringIO()
        zip_file = ZipFile(s, 'w')
        for filepath in filepaths:
            filename = os.path.basename(filepath)
            if os.path.getsize(filepath) < 5:
                raise DataverseException('The Dataverse does not currently accept files less than 5 bytes. '
                                   '{} cannot be uploaded.'.format(filename))
            elif filename in [f.name for f in self.get_files()]:
                raise DataverseException('The file {} already exists on the Dataverse'.format(filename))
            zip_file.write(filepath)
        zip_file.close()
        content = s.getvalue()

        self.upload_file('temp.zip', content, zip=False)
            sentence_attrs = dict(sentence.attributes.items())
            text=sentence_attrs["text"]
            sentence_id=sentence_attrs["id"]
            path=utils.construct_path(write_path,sentence_id)
            output_file=open(path,'w')
            output_file.write(text)
            output_file.close()


test_medline_path= "./Test/Test for DDI Extraction task/MedLine"
test_drugbank_path= "./Test/Test for DDI Extraction task/DrugBank"
train_medline_path="./Train/MedLine"
train_drugbank_path="./Train/DrugBank"

test_medline_path_files=utils.get_files_in_path(test_medline_path)
test_drugbank_path_files=utils.get_files_in_path(test_drugbank_path)
train_medline_path_files=utils.get_files_in_path(train_medline_path)
train_drugbank_path_files=utils.get_files_in_path(train_drugbank_path)

for file in test_drugbank_path_files:
    file=utils.construct_path(test_drugbank_path,file)
    write_sentences_to_file(file,"./test_sentences")
for file in test_medline_path_files:
    file=utils.construct_path(test_medline_path,file)
    write_sentences_to_file(file,"./test_sentences")
for file in train_drugbank_path_files:
    file=utils.construct_path(train_drugbank_path,file)
    write_sentences_to_file(file,"./train_sentences")
for file in train_drugbank_path_files:
    file=utils.construct_path(train_drugbank_path,file)