示例#1
0
def convert(snippet, phrase):
    class_names = [
        w.capitalize() for w in random.sample(WORDS, snippet.count("%%%"))
    ]
    other_names = random.sample(WORDS, snippet.count("***"))
    results = []
    param_names = []

    for i in range(0, snippet.count("@@@")):
        param_count = random.randint(1, 3)
        param_names.append(','.join(random.samples(WORDS, param_count)))

    for sentence in snippet, phrase:
        result = sentence[:]

        #fake class names
        for word in class_names:
            result = result.replace("%%%", word, 1)

        #fake other names
        for word in other_names:
            result = result.replace("***", word, 1)

        #fake parameter list
        for word in param_names:
            result = result.replace("@@@", word, 1)

        results.append(result)

    return results
示例#2
0
def convert(snippet, phrase):
	class_names = [w.capitalize() for w in random.sample(WORDS, snippet.count('###'))]
	other_names = random.sample(WORDS, snippet.count("***"))
	results = []
	param_names = []
	
	for i in range(0, snippet.count("AAA")):
		param_count = random.randint(1,3)
		param_names.append(', '.join(random.samples(WORDS, param_count)))
		
	for sentence in snippet, phrase:
		result = sentence[:]
		
		for word in class_names:
			result = result.replace("###", word, 1)
		
		for word in other_names:
			result = result.replace("@@@", word, 1)
		
		for word in param_names:
			result = result.replace("@@@", word, 1)
		
		results.append(result)
	
	return results
示例#3
0
def convert(snippet, phrase):
    class_names = [w.capitalize() for w in
                    random.sample(WORDS, snippet.count("%%%"))]
    other_names = random.samples(WORDS, snippet.count("***"))

    results = []
    param_names = []

    for i in range(0, snippet.count('@@@')):
        param_count = random.randint(1,3)
        param_names.append(','.join(random.sample(WORDS, param_count)))
    for sentence in snippet, phrase:
        result=sentence[:]

        #fake class names

        for word in class_names:
            result = rsult.replace('%%%', word, 1)

        #fake other names
        for word in other_names:
            result = result.replace('***', word, 1)

        #fake parameter lists
        for word in param_names:
            result = result.replace('@@@', word, 1)

        results.append(result)
    return results

# keep going untill they his CTRL-D

    try:
        while True:
             snippet = PHRASES.keys()
             random.shuffle(snippets)

             for snippet in snippets:
                 phrase = PHRASE[snippet]
                 question, answer = conver(snippet, result)
                 if PHRASE_FIRST:
                    question, answer = answer, question
                 print question

                 raw_input("> ")
                 print "ANSWER: %s\n\n" % answer
    except EOFError:
        print "\nBye"
示例#4
0
	
#load up the words froa the website
for word in urlopwn(WORD_URL).readlines():
	WORDS.append(word.strip())
	
	
def convert(snippet, phrase):
	class_names ) [w.capitalize() for w in
					rnadom.samle(WORDS, snippet.count("%%%"))]
	other_names = random.sample(WORDS, snippet.count("***"))
	results = []
	param_names = []
	
for i in range(0, snippet.count("@@@")):
	param_count = random.randint(1,3)
	param_names.append(', '.join(random.samples(WORDS, param_count)))
	
for sentence in snippet, phrase:
	result = sentence[:]
	
	#fake class names
	for word in class_names:
		result = resul.repace("%%%", word, 1)
		
	#fake other names
	for word in other_names:
		result = result.replace("***", word, 1)
		
	#fake parameter lists
	for word in param_names:
		result = result.replace("@@@", word, 1)
示例#5
0
            means = list()
            stdevs = list()
            runMeans = list()
            runStDev = list()
            for k in range(10):
                m = k * 100
                n = m + 100
                for j in range(100):
                    for i in range(int(len(data) / segmentLen)):
                        start = i * segmentLen
                        stop = (i + 1) * segmentLen
                        if sampleTyp:
                            sample = random.choices(data[start:stop],
                                                    k=sampleSize)
                        else:
                            sample = random.samples(data[start:stop],
                                                    k=sampleSize)
                        fmean = statistics.fmean(sample)
                        stdev = statistics.stdev(sample)
                        means.append(fmean)
                        stdevs.append(stdev)

                    fmean = statistics.fmean(means)
                    runMeans.append(fmean)
                    stdev = statistics.stdev(stdevs)
                    runStDev.append(stdev)

                print("%4d, %4d," % (segmentLen, sampleSize),
                      "%10.3f," % (statistics.fmean(runMeans[m:n])),
                      "%10.3f," % (statistics.median(runMeans[m:n])),
                      "%8.3f," % (statistics.fmean(runStDev[m:n])),
                      "%8.3f" % (statistics.median(runStDev[m:n])))
def make_children(parents):
    children = []
    while parents != []:
        samples = random.samples(parents, 2)