#!/usr/bin/python -tt
Read in the file specified on the command line.
Do a simple split() on whitespace to obtain all the words in the file.
Rather than read the file line by line, it's easier to read
it into one giant string and split it once.
Build a "mimic" dict that maps each word that appears in the file
to a list of all the words that immediately follow that word in the file.
The list of words can be be in any order and should include
duplicates. So for example the key "and" might have the list
["then", "best", "then", "after", ...] listing
all the words which came after "and" in the text.
We'll say that the empty string is what comes before
the first word in the file.
With the mimic dict, it's fairly easy to emit random
text that mimics the original. Print a word, then look
up what words might come next and pick one at random as
the next work.
Use the empty string as the first word to prime things.
If we ever get stuck with a word that is not in the dict,
go back to the empty string to keep things moving.
Note: the standard python module 'random' includes a
random.choice(list) method which picks a random element
from a non-empty list.
For fun, feed your program to itself as input.
Could work on getting it to put in linebreaks around 70
columns, so the output looks better.
"""
import random
import sys
def mimic_dict(filename):
"""Returns mimic dict mapping each word to list of words which follow it."""
f=open(filename,'r')
words=f.read()
f.close()
dicts={}
words=words.split()
#solution1:
if len(words)>0:
dicts['']=[words[0]]
for word in words:
if words.index(word)<len(words)-1:
if word in dicts.keys() and words[words.index(word)+1] not in dicts.values():
dicts.get(word).append(words[words.index(word)+1])
else:
dicts[word]=[words[words.index(word)+1]]
return dicts
#solution 2:
temp=''
for word in words:
if temp not in dicts:
dicts[temp]=[word]
else:
dicts[temp].append(word)
temp=word
return dicts
def print_mimic(mimic_dict, word):
"""Given mimic dict and start word, prints 200 random words."""
for i in range(0,200):
print word,
if len(mimic_dict[word])<1:
word=''
word=random.choice(mimic_dict.get(word))
# Provided main(), calls mimic_dict() and mimic()
def main():
if len(sys.argv) != 2:
print 'usage: ./mimic.py file-to-read'
sys.exit(1)
dict = mimic_dict(sys.argv[1])
print_mimic(dict, '')
if __name__ == '__main__':
main()
分享到:
相关推荐
基于Python和JoinQuant平台的选股模型构建与设计源码(附PPT+论文报告+数据集+项目说明).zip 代码结构: 1_CAPM.py:使用资本资产定价模型(CAPM)筛选股票 2_skews_kurts.py:使用正态性检验历史交易数据并筛选股票 ...
安装Python库通常通过`pip`(Python的包管理器)进行,但像`mmir-0.2.0.tar.gz`这样的源码压缩包则需要先解压,然后通过`setup.py`文件进行安装。 解压`mmir-0.2.0.tar.gz`后,我们通常会看到以下结构: 1. `...
要使用mimic,首先需要从PyPI官网下载“mimic-2.0.0.tar.gz”文件,然后使用Python的`setup.py`工具进行安装。安装完成后,可以在Python代码中导入mimic模块,根据文档指导调用相应的函数和类,开始构建和配置模拟...
资源分类:Python库 所属语言:Python 资源全名:mimic_text-0.0.2-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
**Python库torchxrayvision-0.0.13-py3-none-any.whl详解** 在Python编程领域,库是开发者的重要工具,它们提供了一系列预定义的函数和类,简化了特定任务的实现。`torchxrayvision`是这样一个库,专为医学成像分析...
脓毒症项目 ...commonDB.py具有访问mimic3 sql db的多个功能(常规查询等)。 event_count.py负责生成统计信息,以比较预处理和后处理的输入数据 categorization.py保存了安格斯准则的代码(SQL脚本取
您可以通过执行以下setup.py命令来设置和安装python模块,该命令会将软件包安装到conda环境site-packages文件夹中,但带有指向src文件夹的符号链接,因此修改将立即反映出来。 python setup.py develop 另外,您...
使用MIMIC III中的结构化和非结构化数据预测30天ICU再次入院 数据处理 结构化数据 结构化网络的ETL过程可以在结构目录中找到在structured_etl_part1.scala和structured_etl_part2.py 非结构化数据 非结构化数据的...
python3 scripts/extract_subjects.py [PATH TO MIMIC-III CSVs] data/root/ 2. python3 scripts/validate_events.py data/root/ 3. python3 scripts/create_readmission.py data/root/ 4. python3 scripts/extract...
项目:模仿我! 概述 使用的Emotion-as-a-Service API构建的简单有趣的游戏。... serve.py :通过HTTPS投放网页所需的轻量级Python网络服务器,可以访问网络摄像头供稿。 generate-pemfile.sh :您需要运行
MIMIC数据资源 该存储库将资源重组以用于语料库处理 ...python ~ /mimic-w2v-tools/main.py EXTRACT \ --url postgresql://mimic@localhost:5432/mimic \ --output-dir ~ /mimicdump/01_extraction
mimic”文件夹中。 跑步 1.数据准备 要使用旋转代码,请运行以下命令: cd DataPrep/mimic psql -U mimic -a -f allevents.sql python generate_icd_levels.py python generate_seq_combined1.py python generate_...
蒸馏以提高功能级别+蒙版中的rcnn 代码: main.py里面介绍在哪里加入蒸馏adaplayer.py是针对老师和学生的功能地图mimic_loss.py是如何计算分类和回归的蒸馏损失,其实就是计算他们的相似度蒸馏在teacher和student的...
运行:python main.py 选择型号 图形仅生成每个优化程序的度量图形 调整需要输入值,并遍历json配置中的列表 Protune与调优功能相同,但针对问题参数/大小 -r --runtype(选择以下选项之一:plots,tuning,protune...
Python 3.6 火炬+1.4 脾气暴躁的 西皮 OpenCV 小路 tqdm h5py 档文件 解放者 形态池化层 为了在您自己的机器上构建形态学池化层,请运行以下行 python src/setup.py install 火车 现在,您可以使用Euler-Lagrange...
在实际操作中,项目可能会利用如MNIST、CIFAR-10或其他公开的医学影像数据集进行初步验证,然后逐步转向更复杂的医学影像数据集,如MIMIC-CXR、CheXpert等,以提高模型的泛化能力。同时,模型的性能评估通常会用到...
Matlab中AI临床医生的Python重新实现 该项目的目的是为Komorowski等人提供的《 Nature Medicine》论文的python实现。 [1]。 Komorowski等人,“人工智能临床医生在重症监护中学习败血症的最佳治疗策略”,《自然医学...